INFO: Common Dialog Boxes and the WM_INITDIALOG Message

ID: Q74610


The information in this article applies to:


SUMMARY

An application using the common dialog box library (COMMDLG.DLL) can override any information initialized in the DLL by handling the WM_INITDIALOG message in its dialog hook function. If the application is using a private dialog template, it should also initialize all private dialog items while handling this message.

After processing the WM_INITDIALOG message, the hook function should return FALSE if it has set the focus to a dialog control, and return TRUE if Windows should set the focus.


MORE INFORMATION

For example, consider an application that is using the Open File common dialog box (via GetOpenFileName()) but does not want the Drives combo box to appear in the dialog box. Since all dialog items in the standard dialog template must be included in the application's private dialog template, the application will need to include code to disable and hide the Drives combo box and the corresponding "Drives:" static text control. This code would be implemented in the WM_INITDIALOG case of the dialog hook function, as follows:


   case WM_INITDIALOG:
      hWnd = GetDlgItem( hDlg, cmb2 );  // Get Drives combo box handle
      EnableWindow( hWnd, FALSE );      // No longer receives input,
                                        // no longer a tabstop
      SetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_HIDEWINDOW );

      hWnd = GetDlgItem( hDlg, stc4 );  // Get "Drives:" static control
      EnableWindow( hWnd, FALSE );      // no longer an accelerator
      SetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_HIDEWINDOW);

   // Initialize private dialog items here...

      return( TRUE );                   // Let Windows set the focus. 


Keywords          : kbCmnDlg kbNTOS350 kbNTOS351 kbGrpUser 
Version           : 
Platform          : 
Issue type        : kbinfo 

Last Reviewed: March 7, 1999