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 Sample Application", 104, 45, 14, 128, 8
    LTEXT  "Copyright (c) Microsoft Corporation", 105, 45, 35, 140, 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, TEXT("AboutDlg"), hWnd, 
                          (DLGPROC) AboutDlgProc );
            break;
         }
        break;

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

INT_PTR CALLBACK 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;

See Also

Source Code

 

 

Build date: 3/25/2010