Skip to main content
gamedev.net
🔒 Locked

Basic Win32 Question...

Started by CoiN 4 replies 1.2k views
Original Post
CoiN
CoiN
Lo All, I''ve been working my way through a Win32 book by Herbert Schildt, and I seem to be picking it up okay, but there is a couple of things that I''m unsure about. So far with the examples I''ve not really been using the parent window for anything other than creating menus, that do things like call dialog boxes, which contain controls, etc. But I don''t really understand how I would place these controls onto the parent window, as most applications don''t just have a blank window with a menu when they start up. Or is it done another way, i.e. Hiding the Parent window and just using dialog boxes? (Probably not). Also is it possible to put menus on dialog boxes? Hope this made sense. Thanks in Advance... COiN
Eight
Eight
You don''t *have* to open a parent window. Its just that your particular book has chosen to teach you that way. Parent windows like that are a convenient starting point.

Keep working through it, I''m sure it''ll all become clear soon.

And no, I don''t think you can put menus on dialog boxes although I''m by no means a Win32 expert so don''t quote me.

E
doctorsixstring
doctorsixstring
Yes, you can put menus on dialog boxes. Here''s how:


  
BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{

switch(msg)
{
case WM_INITDIALOG:
SetMenu( hdwnd, (HMENU)LoadMenu(hinstance, MAKEINTRESOURCE(IDR_MENU1) );
return TRUE;
default:
return FALSE; // Don''t call DefWindowProc() in dialog windows!

}

}


If you have a window that is going to have lots of controls, it is generally easier to make it a dialog box. You can use the resource editor to easily place buttons, edit boxes, etc. and then use the DialogProc() to process their logic.

Creating controls on a non-dialog window is a bit harder. You have to make a call to CreateWindow(). Remember, a control is actually just a small window. The code would look something like this:

HWND ButtonHwnd = CreateWindow( "BUTTON", "Button Text", WS_CHILD | WS_VISIBLE | BS_PUSHLIKE, 100, 100, 128, 64,
ParentHwnd, (HMENU)10000, hinstance, NULL);

The (HMENU)10000 part may be confusing. When you create a window that is actually just a control, you have to specify a unique ID number for each control, and pass it to CreateWindow() as an HMENU.

I hope that helped some. Win32 is a huge topic, and if you have any more questions feel free to post them.

-Mike
doctorsixstring
doctorsixstring
Another thing: Like Eight said, you don''t have to create a "parent" window, per se. You could just as easily have your app''s main window be a dialog box. Here''s some code:


  
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpCmdLine, int nShowCmd )
{
MSG msg;
//Initialize main application dialog window

hwnd_main = CreateDialog( hinstance, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC) DialogProc);

if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

BOOL CALLBACK DialogProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{

case WM_CLOSE:
DestroyWindow(hwnd_main);
return 0;

default:
return 0;
}
}



IDD_MAIN is the name of a dialog resource.

-Mike
Ronin Magus
Ronin Magus
A link..

winprog.org/tutorial/

This is where I learned how to program win32. You can do anything you want! You can say "screw windows alltogether" and just use API calls for non-gui stuff. You can create modal/non-modal dialogs (if you're new, this means that the modal dialog is the only window that can gain focus in your program. A non-modal dialog shares focus with the other non-modal windows in the program)

http://roninmagus.hopto.org
acronymfinder.com - Find any acronym you need!

[edited by - Ronin Magus on August 8, 2002 11:24:39 AM]

Topic Locked

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

Sign in to reply to this topic.