Skip to main content
gamedev.net
🔒 Locked

Child Windows

Started by mtalma May 10, 2003 at 10:44 PM 5 replies 400+ views
Original Post
mtalma
mtalma
I want to split the main window screen of my game editor. I read that the way to this is by using a child window but it just doesn''t seem to work! Does anyone have a working sample i can get so i can see how it works?? Thanks!
pag
pag
Im not sure if I know what you want to do, but if you want this:>

-------------------- -----------------------
| | | | |
| | | | |
| Main Window | look like this:> | Win1 | Win2 |
| | | | |
| | | split-> | |
| | | | |
-------------------- -----------------------

Then you should just create one main window and two child windows. And the child windows you just place next to eachother. And in the main window procedure, you wait for the WM_SIZE message, and when it comes you resize the child windows...


    
HWND mainWnd;
HWND childWnd1;
HWND childWnd2;

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{

switch(uiMsg)
{
case WM_SIZE:
int width = LOWORD(lParam);
int height = HIWORD(lParam);

SetWindowPos(childWnd1, NULL, 0, 0, width/2, height, 0);
SetWindowPos(childWnd2, NULL, width/2, 0, width, height, 0);
break;
}

return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// You should replace these and just register the classes

RegisterMainWindowClass();
RegisterChildWindowClass();

// create the main window

mainWnd = CreateWindow( lpszMainWndClass,
"My Game Editor",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
GetModuleHandle(NULL),
NULL );

if(!mainWnd) return 0;

// create the child windows

childWnd1 = CreateWindow( lpszChildWndClass,
NULL,
WS_CHILD | WS_VISIBLE,
0,
0,
640/2,
480,
mainWnd,
NULL,
GetModuleHandle(NULL),
NULL );

// and do the above again for the next window...

// ....blalbllal


ShowWindow(mainWnd, SW_SHOWNORMAL);
UpdateWindow(mainWnd);

// handle messages>

MSG msg;
while(GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}




[edited by - pag on May 11, 2003 11:11:47 AM]

[edited by - pag on May 11, 2003 11:20:06 AM]
I am a signature virus. Please add me to your signature so that I may multiply.
mtalma
mtalma
I have to register the child class also? doesn''t this mean that the child class has to have its own WinProc? Does the child window also have to have its own hInstance? I thought that the child window would just inherit all the functionality of the main window. If so, wouldn''t a call to CreateWindow just simply create the child window?

And what is the function ''GetModuleHandle'' for?

Thanks again.
brassfish89
brassfish89
quote:

doesn''t this mean that the child class has to have its own WinProc?


yes

quote:

Does the child window also have to have its own hInstance?


no, you only get 1 hInstance when you create the program.




doh, nuts. Mmmm... donuts
My website
pag
pag
quote:

And what is the function 'GetModuleHandle' for?



This function returns a HINSTANCE, the same HINSTANCE that is passed by the WinMain function. A HINSTANCE is what you could say is a handle or an id of the application. If you open five instances of your application, each one of them would have a unique HINSTANCE.

I simply used this function instead of taking the HINSTANCE from the WinMain paramters. It's an old habbit as I usually dont create my windows in the WinMain function and don't like passing a HINSTANCE parameter to the functions that does...

You should get the "Win32 Reference" and look up these things yourself, as it's a great way learning things...

[edited by - pag on May 11, 2003 9:40:17 PM]
I am a signature virus. Please add me to your signature so that I may multiply.
Nervo
Nervo
!!!Warning--Off Topic Post!!! *sirens*

Uh, Trinidad is cool. Especially Marabella.
Well, R2D22U2..
remi
remi
You can manage the thing using only ONE window just taking care of where u draw.

"...and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces."----------Scott Meyers, "Effective C++"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.