Child Window

Started by
6 comments, last by Squeejee 22 years, 5 months ago
I know how to make two windows for and app, but how do you make one of the windows a child to another? Do you use the same windows class?
-----
Advertisement
In the call to CreateWindow/CreateWindowEx one of the parameters specify the HWND of the new window''s parent-window. Also, take a look at the WS_CHILD, WS_CLIPCHILDREN and WS_CLIPSIBLINGS window styles (probably a few more, but those are all I can think of right now).
Oh, and the parent and the child do not have to be of the same window class.
This is what I got:

    WNDCLASSEX winclass;HWND hwnd;HWND hwndc;MSG msg;winclass.cbSize = sizeof(WNDCLASSEX);winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;winclass.lpfnWndProc = WindowProc;winclass.cbClsExtra = 0;winclass.cbWndExtra = 0;winclass.hInstance = hinstance;winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);winclass.hCursor = LoadCursor(NULL, IDC_ARROW);winclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);winclass.lpszMenuName = NULL;winclass.lpszClassName = "WINCLASS1";winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);RegisterClassEx(&winclass);//CREATE WINDOWif(!(hwnd = CreateWindowEx(NULL,	     WINDOW_CLASS_NAME,	     "Enchiten",         WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,	     CW_USEDEFAULT,	     CW_USEDEFAULT,		 640, 480,		 NULL,		 hwndc,      <---------------- ERROR		 hinstance,	     NULL))) return 0;if(!(hwndc = CreateWindowEx(NULL,	     WINDOW_CLASS_NAME,	     "EnchitenChild",         WS_OVERLAPPED | WS_VISIBLE | WS_CHILD | WS_CHILDWINDOW | WS_CLIPSIBLINGS,	     CW_USEDEFAULT,	     CW_USEDEFAULT,		 300, 150,		 hwnd,		 NULL,		 hinstance,	     NULL))) return 0;    


It gives me this error:
error C2664: 'CreateWindowExA' : cannot convert parameter 10 from 'struct HWND__ *' to 'struct HMENU__ *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Edited by - Squeejee on November 4, 2001 3:09:21 PM
-----
Did ya remember to call ShowWindow and UpdateWindow for BOTH windows?
Use (HMENU) hwndc instead of just hwndc.
Umm... You seem to be a little confused as to how it''s supposed to work. In your call to create ''hwnd'' you specify that ''hwndc'' is to be it''s menu. This is clearly not right (it wouldn''t be correct do specify it as a child either because ''hwndc'' isn''t created yet).

What you want to do is:

1. Create window1
2. Create window2 passing window1 as the ''parent-parameter''

That''s the basics of it. You don''t need to do anything special when creating window1 (though you might want to set the WS_CLIP_CHILDREN and/or set WS_CLIPSIBLINGS for the child window).
Thanks guys, I got it working. Now, how do I keep the user from selecting the parent window when the child window is active.
-----

This topic is closed to new replies.

Advertisement