简体   繁体   中英

How to create a button in a child window after calling from main window event handler?

I have a main window program that calls a child window after pressing OK as shown in the below code snippet. MY question is how do i insert a button and edit field within this child window retrieve it back ? I understand for main windows this is done via WinProc. Is there a better way of doing via child windows ?

case IDOK:
            HINSTANCE hinst;
            HWND hWindow;
            hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
            hWindow = CreateWindow
                (

                g_szClassName,
                TEXT("Configure Maze Properties"),
                WS_OVERLAPPEDWINDOW,
                200, 100, 300, 228,
                hwnd,
                0,
                hinst,
                0
                );

You have two main possibilities:

  • start populating the new windows from where you are. Simply pass hWindow as the parent window in CreateWindowEx() instead of the current hwnd .

  • start populating the new window from within its own winproc message handler, by reacting on WM_CREATE as explained in this tutorial . This requires however that you've registered g_szClassName as a separate class for the child window, with its own callback function.

By the way, the tutorial shows you how to create the button and a textbox.

The second alternative requires slightly more work, but makes the child window more self-contained, which lead to cleaner code and better reusability.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM