WNDPROC conversion

This is a discussion on WNDPROC conversion within the Windows Programming forums, part of the Platform Specific Boards category; How do you set a class member function to be a WNDPROC? I am creating my own custom class to ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    43

    WNDPROC conversion

    How do you set a class member function to be a WNDPROC? I am creating my own custom class to represent a window, and I have the following in my constructor:

    Code:
    WNDCLASSEX CanvasClass;
    ...
    CanvasClass.lpfnWndProc = &TCanvasWindow::WndProc;
    However I get an error:

    converting from `LRESULT (TCanvasWindow::*)(HWND__ *, unsigned int, unsigned int, long int)' to `LRESULT (*)(HWND__ *, unsigned int, unsigned int, long int)'

    I have tried casting the function pointer to WNDPROC (the type of lpfnWndProc) but this doesn't seem to work either.

    I am using Dev-C++ and MinGW on Windows XP Professional.

    Please help!

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    TCanvasWindow::WndProc must be declared as static.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    In addition to Tonto's fine suggestion you should search this board as there have been many discussions of this in the past which you may find of some interest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    43
    Quote Originally Posted by Ken Fitlike
    In addition to Tonto's fine suggestion you should search this board as there have been many discussions of this in the past which you may find of some interest.
    Yeah thanks. I did actually search the board before I posted, but after reading your message I searched it again and found a couple of topics. Now I have a good window procedure running with "this" passed as the last argument of CreateWindowEx, a global static window procedure, GetWindowLongPtr and SetWindowLongPtr working... Thank you for your help.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> I am using Dev-C++ and MinGW on Windows XP Professional.

    Vote on the poll and you may not have to say that more than once.
    But for now, putting it in your sig would be good.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    MFC accomplished this by having a function called GetWindowHandlePermananet() which takes and HWND and returns a CWnd. They then call WndProc with the CWnd pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 05:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 08:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21