[win32] - super class: how get the window procedure?

This is a discussion on [win32] - super class: how get the window procedure? within the Windows Programming forums, part of the Platform Specific Boards category; i'm having problems for do the form super class the window is showed and window procedure works, but i don't ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    158

    [win32] - super class: how get the window procedure?

    i'm having problems for do the form super class
    the window is showed and window procedure works, but i don't get some messages, like WM_CREATE(and maybe more), so how can i fix these problem?
    i used my button class code(changed for the form class), but without results
    can nayone advice me, please?

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    speaking on EnumChildWindows(), CreateWindowEx() functiond that we can send the 'this'(when used inside of a class)...
    these functions are connected to another CALLBACK functions.
    how can i get the class pointer inside of CALLBACK functions?

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    You would use SetWindowLongPtr/GetWindowLongPtr functions
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    Quote Originally Posted by Codeplug View Post
    sorry but some links aren't working

    Quote Originally Posted by vart View Post
    You would use SetWindowLongPtr/GetWindowLongPtr functions
    sorry... but how use them for get the pointers?
    i have seen these incomplete sample:
    Code:
    MyClass *pWnd=(MyClass*)GetWindowLong(...);
    but i don't understand what to put on parameters
    Last edited by joaquim; 07-07-2014 at 02:13 PM.

  6. #6
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    now i understand better how can resolve the problem

    1 st - when we create the control, we must send the 'this' in last parameter:
    Code:
     hwnd = CreateWindowEx(0 , classname, strCaption.c_str(), WS_OVERLAPPEDWINDOW | WS_TABSTOP,
                                      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, hinstance, this);
    2 nd - in window procedure we create the pointer variable:

    Code:
    form *inst = (form *)GetWindowLongPtr(HandleWindow, GWLP_USERDATA);
    3 rd - we must use the WM_NCCREATE message:
    Code:
    case WM_NCCREATE:
                    {
                        CREATESTRUCT *p = (CREATESTRUCT *)lParam;
                        inst = (form *)p->lpCreateParams;
                        SetWindowLongPtr(HandleWindow, GWLP_USERDATA, (LONG_PTR)inst);
                        inst->hwnd = HandleWindow;
                    }
                    break;
    now we can use the class members using the inst pointer
    i hope these helps very people

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,702
    WM_NCCREATE is not always the first message sent, which is one reason I like thunking better.

    I posted exampled 32 bit example code here: Member functions as child window procedures

    gg

  8. #8
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    Quote Originally Posted by Codeplug View Post
    WM_NCCREATE is not always the first message sent, which is one reason I like thunking better.

    I posted exampled 32 bit example code here: Member functions as child window procedures

    gg
    i'm confused.. what you mean?
    i need ask anotherthing: what i must do, in window procedure(speaking on form), for the child controls window procedure do the notify messages?
    i tryied these:
    Code:
    case WM_COMMAND:
                    {
                        return DefWindowProc(HandleWindow, WM_COMMAND, wParam, lParam);
                    }
                    break;
    no error, but don't works
    i tryied with:
    Code:
    SendMessage(HandleWindow, WM_COMMAND, wParam, lParam);
    but when i click on child controls, the windows(OS) give me an error and then the aplication is closed... what you can advice me?

  9. #9
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    resolved.. my problem was using the form hwnd instead the control hwnd...
    Code:
    case WM_COMMAND:
                    {
                        return DefWindowProc((HWND)lParam , WM_COMMAND, wParam, lParam);
                    }
                    break;
    the (HWND)lParam give us the control hwnd.
    thanks for all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [win32] - button super class and BS_NOTIFY
    By joaquim in forum Windows Programming
    Replies: 0
    Last Post: 06-21-2014, 04:35 PM
  2. Simple win32 window class
    By Darkinyuasha1 in forum Windows Programming
    Replies: 1
    Last Post: 02-02-2012, 08:40 AM
  3. Coordinating the window procedure with the program
    By megafiddle in forum Windows Programming
    Replies: 13
    Last Post: 10-13-2011, 03:32 AM
  4. Default Procedure for MDI Child Window?
    By SeanMSimonsen in forum Windows Programming
    Replies: 3
    Last Post: 04-05-2003, 05:43 PM
  5. Window Procedure Question
    By shinobisot in forum Windows Programming
    Replies: 3
    Last Post: 01-15-2003, 11:38 AM

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