Implant a callback inside a class

This is a discussion on Implant a callback inside a class within the C++ Programming forums, part of the General Programming Boards category; I'm not sure how to put a callback inside a class. What I have right now doesn't work. Code: class ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Implant a callback inside a class

    I'm not sure how to put a callback inside a class. What I have right now doesn't work.

    Code:
    class Listbox
    {
    	private:
    		void Create();
    
    		LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    };
    
    
    
    
    /////////////////////////////////////////////////////////////////////
    ///// Create /////
    /////////////////////////////////////////////////////////////////////
    void Listbox::Create()
    {
        winc.hInstance = NULL;
    	winc.hInstance = NULL;
        winc.lpszClassName = "Listbox";
    	winc.lpfnWndProc = WindowProcedure;
        winc.style = CS_DBLCLKS;
        winc.cbSize = sizeof(WNDCLASSEX);
    
        
        winc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        winc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        winc.hCursor = LoadCursor(NULL, IDC_ARROW);
        winc.lpszMenuName = NULL;
        winc.cbClsExtra = 0;
        winc.cbWndExtra = 0;
        winc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
    }
    
    /////////////////////////////////////////////////////////////////////
    ///// Windows Proc Callback /////
    /////////////////////////////////////////////////////////////////////
    LRESULT CALLBACK Listbox::WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
    		case WM_COMMAND:
    			break;
    
            case WM_DESTROY:
                break;
    
            default:
                return DefWindowProc(hwnd, message, wParam, lParam);
        }
        
        return 0;
    }
    The errors I get are:

    error C3867: 'Listbox::WindowProcedure': function call missing argument list; use '&Listbox::WindowProcedure' to create a pointer to member
    error C2440: '=' : cannot convert from 'LRESULT (__stdcall Listbox::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'


    I am not too worried about the first error cause if I do what it says I get the second error and the first one disapears.

    Without classes (like a ragular windows app) it works fine, but if it is in a class like this it gives those errors.

  2. #2
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    I sucseded in doing that. the LRESULT CALLBACK definitions should be the same, and maybe public?
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    This question has been asked, answered and discussed a lot in the past in the windows board, like here and here.

    I'm sure a board search will turn up more information if the discussions in those threads I've linked to do not suffice.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok I sucesfully implanted the windows thunk. But now I have a new question.

    from msdn:

    An application sends the LBN_DBLCLK notification message when the user double-clicks a string in a list box. The parent window of the list box receives this notification message through the WM_COMMAND message.
    The question is, is the LBN_DBLCLK (and alike notifications) always sent to the parent. My thunk doesn't seem to catch any WM_COMMAND.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. assignment operator for static array inside a class
    By acosgaya in forum C++ Programming
    Replies: 3
    Last Post: 07-27-2008, 11:11 AM
  3. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 10:33 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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