Using a Dialog Box as the Main Window of an ApplicationLast reviewed: April 5, 1996Article ID: Q108936 |
The information in this article applies to:
SUMMARYDialog boxes might be used as the main window of an application for several reasons. When an application uses a dialog box as the main window, the following should be taken into consideration while designing such an application:
MORE INFORMATIONYou can create a modal or modeless dialog box as the main window of an application. In doing so, there is no need to have an overlapped window that acts as the owner of the dialog box. Memory for edit controls created with the DS_LOCALEDIT flag set, and static controls, will come from the heap represented by the hInstance passed to the CreateDialog() or DialogBox() call. When modal dialog boxes are chosen for this purpose, and accelerator keys are defined in an application, Windows enters a modal message loop that does not process accelerators, unless a WH_MSGFILTER hook is installed and TranslateAccelerator() is called from the hook callback function. One easy way to avoid this limitation is to create a modeless dialog box and call TranslateAccelerator() from the main message loop. The icon for a window is stored in its class information. Because a dialog box is a window of global class that all applications in the system are using, changing the icon for this application will change the icon for all dialog boxes in the system. Below is one workaround for drawing the icon manually when the dialog box is minimized:
Sample CodeBOOL WINAPI GenericDlgProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { RECT rect ; switch (msg) { case WM_INITDIALOG: hIcon = LoadIcon(); // Load the icon that is to be displayed // when minimized. return TRUE ; case WM_ERASEBKGND: if (IsIconic(hwnd) && hIcon) { SendMessage( hwnd, WM_ICONERASEBKGND, wParam, 0L ); return TRUE; } break; case WM_QUERYDRAGICON: return (hIcon); case WM_PAINT: { PAINTSTRUCT ps; BeginPaint( hwnd, &ps ); if (IsIconic(hwnd)) //*** If iconic, paint the icon. { if (hIcon) { //center the icon correctly... GetClientRect(hwnd, &rect) ; rect.left = (rect.right - GetSystemMetrics(SM_CXICON)) >> 1; rect.top = (rect.bottom - GetSystemMetrics(SM_CYICON)) >> 1; DrawIcon( ps.hdc, rect.left, rect.top, hIcon ); } } EndPaint( hwnd, &ps ); } break; } return FALSE;} //*** GenericDlgProc The workaround described above assumes that the dialog box belongs to the predefined dialog class. For private dialog box classes, there is no need to manually draw the icon for the dialog box when it is minimized. You can specify the icon while registering the dialog box class. Remember to set the cbWndExtra field to DLGWINDOWEXTRA. When the dialog box is minimized, the icon will be painted automatically.
|
Additional reference words: 3.00 3.10 3.50 3.51 4.00 95 DLGMAIN
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |