Compartilhar via


How to Prevent Display of Smart Minimize and OK Buttons in Dialog Boxes

4/19/2010

In general, a dialog box should include the OK button on the title bar. However, if you are creating a wizard-style dialog box or another type of dialog box that includes a Cancel button, you can choose to show no title bar icon for that dialog box. This requires several changes to general-purpose code, such as that generated by the App Wizard.

To prevent Smart Minimize and OK buttons from appearing on title bar of dialog boxes

  1. Manually edit the resource (.rc) file for the dialog box. Add WS_NONAVDONEBUTTON to the STYLE line to prevent the display of the Smart Minimize button, as shown:

    //
    // Dialog.
    //
    IDD_WIZARD DIALOG DISCARDABLE 0, 0, 140, 57
    STYLE WS_POPUP | WS_CAPTION | WS_NONAVDONEBUTTON
    EXSTYLE 0x80000000L
    CAPTION "Your Wizard"
    
  2. Remove SHDIF_DONEBUTTON from the dwFlags member of the SHINITDLGINFO user interface structure (generally found in the WM_INITDIALOG message handler for the dialog box) to remove the OK button from the title bar, as follows:

    SHINITDLGINFO shidi;
    switch (message)
    {
        case WM_INITDIALOG:
            shidi.dwMask = SHIDIM_FLAGS;
    
            shidi.hDlg = hDlg;
            if (!SHInitDialog(&shidi)) {
                MessageBox(NULL, _T("Can't create dialog box."),
                           _T("Error"), MB_OK);
                exit(0);  // Replace with specific error handling.
            }
            .
            .
            .
    
  3. Add a call to the SHDoneButton function with the SHDB_HIDE state after calling the SHInitDialog function to hide the OK button, as follows:

        if (!SHDoneButton(hDlg, SHDB_HIDE)) {
            MessageBox(NULL, _T("Can't hide the OK button."),
                       _T("Error"), MB_OK);
            exit(0);  // Replace with specific error handling.
        }
    
  4. If you run the code as is, no Smart Minimize button or OK button appears on the title bar, but tapping the Enter key in the emulator or on the input panel keyboard closes the dialog box. If this is not the desired behavior, make the appropriate changes to the WM_COMMAND message handler. Generally, you want to set focus to the default control in the current panel of your wizard.

See Also

Tasks

How to Enable System-defined File Dialog Boxes

Concepts

How to Call a System-defined Dialog Box

Other Resources

Designing Full-Screen Dialog Boxes