The About Dialog Box

A dialog box is a temporary window that displays information or prompts the user for input. The GENERIC application includes an About dialog box. Every application should include an About dialog box. The dialog box displays such information as the application's name and copyright information.

You create and display a dialog box by using the DialogBox function. This function takes a dialog box template and creates a dialog box.

The GENERIC application includes the following dialog box template in the resource-definition file:

AboutDlg DIALOG FIXED 6, 21, 198, 99
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "About Generic"
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "&OK", IDOK, 72, 74, 40, 14
    LTEXT           "Generic Application", 104, 45, 14,
                    128, 8
    LTEXT           "Written as a sample", 105, 45, 35, 59, 8
    LTEXT           "Microsoft Corporation", 106, 45, 45, 98, 8
    LTEXT           "Copyright (c) 1996", 107, 45,
                    54, 138, 8
END

The name of the source is specified as AboutDlg. For more information, see Dialog Resource.

When the user clicks About from the Help menu, the following code in the window procedure displays the About dialog box:

case WM_COMMAND:
   switch( wParam ) {
      case IDM_ABOUT:
         DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
                    AboutDlgProc );
      break;
   }
break;

The last parameter is a pointer to a dialog box procedure. It has the following prototype.

LRESULT WINAPI AboutDlgProc( HWND, UINT, WPARAM, LPARAM );

A dialog box procedure is similar to a window procedure, but usually processes only dialog initialization and user-input messages. The GENERIC application contains the following message processing code:

switch( uMsg ) {
   case WM_INITDIALOG:
      return TRUE;
   case WM_COMMAND:
      switch( wParam ) {
         case IDOK:
            EndDialog( hDlg, TRUE );
            return TRUE;
      }
   break;
}

return FALSE;