Click to See Complete Forum and Search --> : Starting Program with a Dialog Box


cilphex
November 23rd, 2005, 10:18 PM
Hey,

I'm new to win32 and I've been wondering about this. So far, I only know how to create graphical programs that start with WinMain, and use WndProc to keep track of the main window. I have other dialog boxes appear from menu selections on the main window.

I'd like to be able to _not_ have to create the main window in WinMain, but be able to create it later. To be more clear, for example, I'd like to start my program with a dialog box, like AOL instant messenger, which gathers a small amount of information, processes it, and then opens a main window. Right now, I only know how to make a dialog box appear as the result of a command (menu selection, button press, etc.) from the main window.

Like I said, I'm new to win32 and what I'm asking is probably really basic, but all of the basic win32 tutorials I've found so far create the main window right away and use the (standard?) WinMain/WndProc setup. If anyone could help me out or point me in the right direction it would be much appreciated.

Thanks.

olivthill
November 24th, 2005, 07:40 AM
In C, you can have, e.g.:
BOOL CALLBACK events_dlg(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam)
{
switch (wm)
{
default:
return FALSE;

case WM_INITDIALOG:
{
RECT rect;
int dx = GetSystemMetrics(SM_CXSCREEN);
int dy = GetSystemMetrics(SM_CYSCREEN);

/* Center the dialog on the screen */
GetWindowRect(hwnd, &rect);
SetWindowPos(hwnd, NULL,
(dx - (rect.right - rect.left)) / 2,
(dy - (rect.bottom - rect.top)) / 2,
0, 0, SWP_NOSIZE | SWP_NOZORDER);

/* Set focus on the button */
SetFocus(GetDlgItem(hwnd, IDOK));
}
return FALSE;

case WM_COMMAND:
switch (LOWORD(wParam))
{
default:
return FALSE;
case IDCANCEL:
EndDialog(hwnd, FALSE);
break;
case IDOK:
{
...
}
} // end switch LOWORD(wParam))
} // end switch (wm)

return TRUE;
}

/* ============== */
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
DLGPROC lpfnDialog;

if ((lpfnDialog = (DLGPROC)MakeProcInstance
((FARPROC)events_dlg, hInstance))
== (DLGPROC) NULL)
return FALSE;

DialogBox(hInstance, "IDD_DLG", NULL, lpfnDialog);

return TRUE;
}