Thread: classes and window procedures

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    classes and window procedures

    i have some class based code that is closely based on Ken Fitlike's code from his website. The thing is, Ken's class for a standard application window calls a global window procedure which then calls the member function window procedure that is part of that class. The way i want to do things, it would be better to be able to specify that the class calls the member function window proc directly. eg:

    Code:
    CppAppWnd::CppWndProc(...)
    {
      ...
    }
    
    CppAppWnd::Create()
    {
    WNDCLASSEX wcx;
    wcx.lpfnWndProc= (WNDPROC)CppWndProc;
    }
    but the compiler wont let me. it says:

    [quote]
    'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
    [/code]

    i really want to get this to work, how do i do it?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    21
    it has to be static:

    class CppAppWnd
    {
    //your stuff
    static LRESULT CALLBACK CppWndProc(...);
    //more of your stuff
    };


    static LRESULT CALLBACK CppAppWnd::CppWndProc(...)
    {
    ...
    }

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    actually, you only put static in the class declaration, not when you declare the function. eg:

    Code:
    class CppAppWnd
    {
          static LRESULT CALLBACK CppAppWndProc(...);
    }
    
    LRESULT CALLBACK CppAppWndProc(...)
    {
    
    }
    thanks for the help, i was scared it would be possible.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    21
    oh yeah. same result anyway

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Ken's class for a standard application window calls a global window procedure<<

    For simplicity, but most of that stuff is old and badly needs updating.

    >>i was scared it would be possible.<<



    There's been some discussion about and around this in the past that may be of some interest to you:

    http://www.cprogramming.com/cboard/s...ght=wmnccreate

    http://www.cprogramming.com/cboard/s...ght=wmnccreate

    http://www.cprogramming.com/cboard/s...ght=wmnccreate

    http://www.cprogramming.com/cboard/s...ght=wmnccreate

    http://www.cprogramming.com/cboard/s...ght=wmnccreate

    Not all are entirely relevant and there's some repetition of detail but many of those threads provide example code and links to other sites that may be of interest.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ confusion
    By Eirik in forum Windows Programming
    Replies: 14
    Last Post: 04-29-2009, 01:54 PM
  2. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  3. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  4. Obtaining a list of all registered window classes?
    By Sebastiani in forum Windows Programming
    Replies: 4
    Last Post: 01-05-2003, 04:15 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM