DialogBox "the right way"?

So here is my dilemma...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
	MainHinst = hInstance;
	HWND hDialog = 0;

	hDialog = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),0,DialogProc);

	if(!hDialog)
	{
		mbLastError();
		return 1;
	}

	MSG msg;
	int status;

	if(status == -1)
			return -1;

	ShowWindow(hDialog,nShowCmd);
	UpdateWindow(hDialog);

	while ( (status = GetMessage(&msg,0,0,0)) != 0 )
	{
		
		if(!IsDialogMessage(hDialog,&msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;

	return 1;
}

this works and everything but I also have this one...:

1
2
3
4
5
6
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
	MainHinst = hInstance;
	DialogBox(MainHinst,MAKEINTRESOURCE(IDD_DIALOG1),0,DialogProc);
	return 1;
}


it does the same thing... so? which one is the "right way" I really don't see any difference, I can interact with the Dialog the same way in either version, is it just preference? or am I missing something?
No, you cannot interact the same way. The first one allows you to click on other windows within your app, the second one forces you to clidk on that one before you do anything else in your applicaton.
Thanks for the fast reply.

Thing is I just want the user to interact with the dialog box, what I mean is I want to use the DialogBox as the "main window", so is the first one still better? I do know there are more advantages on the first one but I don't really need them, not for this application.
Last edited on
You should NEVER make a modal dialog (the second one) as your main window. If you are going to make the dialog your main window, you use the first one, i.e., CreateDialog(), and in your Window Class you MUST declare the extra value of --

wc.cbWndExtra=DLGWINDOWEXTRA;

And if you can get it to work by not doing that, don't think you've gotten away with something because I can guarantee you it will come back to bite you, either by crashing outright or causing other unexpected and unwanted behaviors.
Ok thanks for clearing that up bro.
Topic archived. No new replies allowed.