Member functions as child window procedures

This is a discussion on Member functions as child window procedures within the Windows Programming forums, part of the Platform Specific Boards category; I'm so embarrased. I must have read those links a hundred times and not understood it.. It has now fallen ...

  1. #16
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87
    I'm so embarrased. I must have read those links a hundred times and not understood it.. It has now fallen into place.

    Thanks so much. I can go on living now!

    Thanks for the patience and time. You have no idea how much I appreciate it!

    FB
    Visual C++ .net
    Windows XP profesional

  2. #17
    Registered User
    Join Date
    Aug 2003
    Posts
    23
    Hi, I've been trying to figure this out as well, in the book I've got you have to use windowclass.cbWndExtra in the windowclass to store a pointer, also (as you guys said), you have to use a this pointer as well. Is the bit about storing a pointer in windowclass.cbWndExtra right?

    Actually I'll keep this short by just asking about the bit I most don't understand , I'll read up about the other links as well.

    [code]

    //declare your window
    CMYWINDOW myWindow;

    myWindow.create("Title");//create
    myWindow.show();//show


    LRESULT CALLBACK//included in the class as a freind
    WindowProc(HWND myWindow,UINT message,
    WPARAM wparam,LPARAM lparam)
    {
    if (message== WM_CREATE)
    {
    CREATESTRUCT* createstruct;//this is a pointer to a
    //CREATESTRUCT type.

    //what does this mean?
    createstruct = (CREATESTRUCT*)lparam;

    SetWindowLong (myWindow, 0, (LONG) (createstruct->
    lpcreateparams)) ;
    return 0;

    CMYWINDOW* object = (CMYWINDOW)GetWindowLong
    (myWindow,0);

    if (object)//I think the rest is just the normal message processing.
    {
    if (message == WM_DESTROY)
    return object-> Destroy(myWindow,message,wparam,lparam);
    //Destroy is the destroy method from the class
    //...

    return DefWindowProc(... )
    }
    [code]

    Thanks anyone.

  3. #18
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Originally posted by Stevo
    Is the bit about storing a pointer in windowclass.cbWndExtra right?
    No. That's just for specifying extra bytes you want to store with windows of that registered class. Use SetWindowLongPtr/GetWindowLongPtr to set and get those extra bytes; GWL_USERDATA is 'free' in this regard ie you don't have to do anything extra to use it.

    Take a look at the relevant descriptions on msdn for clarification:
    WNDCLASSEX
    GetWindowLongPtr
    SetWindowLongPtr
    Originally posted by Stevo
    //what does this mean?
    createstruct = (CREATESTRUCT*)lparam;
    That's type-casting - casting, in this case, the value of lParam to a CREATESTRUCT pointer so you can use it and access the members of the CREATESTRUCT struct.
    Last edited by Ken Fitlike; 03-09-2004 at 04:46 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #19
    Registered User
    Join Date
    Aug 2003
    Posts
    23
    Thanks Ken, I'll look up the answers you already gave to filter as well.
    Thanks

  5. #20
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    You ain't cool, less'n you is thunk'n!

    gg

  6. #21
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Well, thankee kindly.

    That's a very interesting read but the technique seems to carry its own subset of problems.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #22
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    True.
    It's compiler and architecture dependant. I use this technique on ARM, SH3, MIPS, and x86 processors (and so does ATL).

    All the architecture #define's come from the project/makefile. Shouldn't be too hard to port the code in that article using g++ compiler directives.

    If you own VisualStudio and have ATL installed, take a look at your ...\ATL\Include\atlwin.h header file to see how Microsoft does it

    gg

  8. #23
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    Originally posted by Codeplug
    Shouldn't be too hard to port the code in that article using g++ compiler directives.
    If anyone sends me such I'll add it to the article as an appendix, giving due credit of course.

  9. #24
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Shouldn't be too hard to port the code in that article using g++ compiler directives. <<

    Haha! Famous last words.

    >>If you own VisualStudio and have ATL installed, take a look at your ...\ATL\Include\atlwin.h header file to see how Microsoft does it<<

    Ok.

    Thanks again.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  10. #25
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    You ain't cool, less'n you is thunk'n!
    That article just simply blew my mind.

  11. #26
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    Originally posted by Dante Shamest
    That article just simply blew my mind.
    Gosh, thanks (assuming you meant it in a good way).

  12. #27
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    I was bored.....

    Code:
    /*---------------------------------------------------------------------------*/
    
    #if defined (_MSC_VER) // VC++ compiler
      #if !defined (_M_IX86) // x86 architecture
        #error Only X86 supported
      #endif
    #elif defined (__GNUC__) // GNU compiler
      #if !defined (_X86_)  // x86 architecture
        #error Only X86 supported
      #endif
    #endif
    
    /*---------------------------------------------------------------------------*/
    
    #if defined (_MSC_VER) // VC++ compiler
        #pragma warning(push)
        #pragma warning(disable:4355) //'this' used in base member initializer list
        #pragma pack(push,1)
    #endif
    
    /*---------------------------------------------------------------------------*/
    
    class WndProcThunk
    {
        const DWORD m_mov;     // mov ecx, pThis
        const DWORD m_this;    // pThis
        const BYTE  m_jmp;     // jmp WndProc
        const DWORD m_relproc; // relative jmp
        
        WndProcThunk(); // private default constructor (no implementation)
    
    public:
        explicit WndProcThunk(WNDPROC proc, void *pThis) :
            m_mov(0x042444C7),
            m_this((DWORD)pThis),
            m_jmp(0xE9),
            m_relproc((int)proc - ((int)this + sizeof(WndProcThunk)))
        {
            ::FlushInstructionCache(GetCurrentProcess(), this, 
                                    sizeof(WndProcThunk));
        }//constructor
    }//<-- no semicolon yet...
    
    /*---------------------------------------------------------------------------*/
    
    #if defined (__GNUC__) // GNU compiler
      __attribute__ ((packed))
    #endif
    
    ; //<-- semicolon to close WndProcThunk
    
    #if defined (_MSC_VER) // VC++ compiler
        #pragma warning(pop)
        #pragma pack(pop)
    #endif
    
    /*---------------------------------------------------------------------------*/
    I've attached full source that compiles and runs under both MinGW and VC++ 6.0

    gg
    Attached Files Attached Files

  13. #28
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    Originally posted by Codeplug
    I was bored.....
    Cool. You mind if I append it to the article on HackCraft?
    If so how you you like to be referred to as, "Codeplug?" or another name, or what?

  14. #29
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    Codeplug on Cprogramming.com (or something like that) is fine

    Feel free to use your original "winThunk" implementation as well.

    gg

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

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