PRB: Print Common Dialog Box Doesn't Display Help Button

ID: Q140271


The information in this article applies to:


SYMPTOMS

When an application invokes the print common dialog box and specifies the PD_SHOWHELP flag, the help button is not displayed on the dialog box when the application is run in Windows 95.


CAUSE

The Windows 95 common dialog code does not create the help button even though the PD_SHOWHELP is supplied.


RESOLUTION

To overcome this behavior, an application needs to install a common dialog hook function and create the help button itself. The Help button event handling code in Windows 95 will function properly. The following code fragment demonstrates how to create and position the Help button on the Print common dialog.

This behavior also occurs with the Page Setup common dialog box. The following code will work on this dialog box also, but the positioning of the button will have to be adjusted to place it properly.


   /***********************************************************************
      DoPrintDialog()
   ***********************************************************************/ 

   BOOL DoPrintDialog(HWND hwndParent, BOOL bSetup)
   {
   PRINTDLG pd;
   BOOL     bReturn;

   /*
   initialize PRINTDLG structure
   */ 
   ZeroMemory(&pd, sizeof(pd));

   pd.lStructSize = sizeof(PRINTDLG);
   pd.hwndOwner = hwndParent;
   pd.hDevMode = NULL;
   pd.hDevNames = NULL;
   pd.nFromPage = 0;
   pd.nToPage = 0;
   pd.nMinPage = 0;
   pd.nMaxPage = 0;
   pd.nCopies = 0;
   pd.hInstance = g_hInst;

   if(bSetup)
      {
      /*
      display the print setup dialog box
      */ 
      pd.Flags =  PD_RETURNDC |
                  PD_SHOWHELP |
                  PD_PRINTSETUP |
                  PD_ENABLESETUPHOOK;

      pd.lpfnSetupHook = PrintDlgHookProc;
      pd.lpSetupTemplateName = NULL;
      }
   else
      {
      /*
      display the regular print dialog box
      */ 
      pd.Flags =  PD_RETURNDC |
                  PD_SHOWHELP |
                  PD_ENABLEPRINTHOOK;

      pd.lpfnPrintHook = PrintDlgHookProc;
      pd.lpPrintTemplateName = NULL;
      }

   bReturn = PrintDlg(&pd);

   if(bReturn)
      {
      }

   return bReturn;
   }

   /***********************************************************************
      PrintDlgHookProc()
   ***********************************************************************/ 

   BOOL CALLBACK PrintDlgHookProc(  HWND hWnd,
                                    UINT uMessage,
                                    WPARAM wParam,
                                    LPARAM lParam)
   {
   switch (uMessage)
      {
      case WM_INITDIALOG:
         {
         /*
         lParam is a pointer to the PRINTDLG structure
         */ 
         LPPRINTDLG  lppd = (LPPRINTDLG)lParam;

         /*
         Only create the help button if it has been specified and it
         doesn't already exist - pshHelp is defined in Dlgs.h.
         */ 
         if(   (lppd->Flags & PD_SHOWHELP) &&
               (NULL == GetDlgItem(hWnd, pshHelp)))
            {
            RECT  rc,
                  rcGroup;
            HWND  hwndHelp;
            HFONT hFont;

            /*
            Get the rectangle of the OK button as a template
            */ 
            GetWindowRect(GetDlgItem(hWnd, IDOK), &rc);
            MapWindowPoints(HWND_DESKTOP, hWnd, (LPPOINT)&rc, 2);

            /*
            Get the rectangle of the group box
            */ 
            GetWindowRect(GetDlgItem(hWnd, grp4), &rcGroup);
            MapWindowPoints(HWND_DESKTOP, hWnd, (LPPOINT)&rcGroup, 2);

            /*
            Put the width in right and the height in left
            */ 
            rc.right = rc.right - rc.left;
            rc.bottom = rc.bottom - rc.top;

            /*
            Align the button - this is reliable for the print and setup
            dialogs
            */ 
            rc.left = rcGroup.left;

            /*
            Create the help button
            */ 
            hwndHelp = CreateWindow(
               "button",
               "&Help Button",
               WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
               rc.left,
               rc.top,
               rc.right,
               rc.bottom,
               hWnd,
               (HMENU)pshHelp,
               (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
               NULL);

            /*
            Get the font from the OK button and set the font of the help
            button
            */ 
            hFont = (HFONT)SendDlgItemMessage(hWnd, IDOK, WM_GETFONT,
                                              0, 0);
            SendMessage(hwndHelp, WM_SETFONT, (WPARAM)hFont, 0);
            }
         }
         return TRUE;

      }
   return FALSE;
   } 


STATUS

This problem has been corrected in Windows 98.


Keywords          : kbcode kbCmnDlg kbCmnDlgPrint kbGrpUser kbWinOS95bug kbWinOS98fix 
Version           : 
Platform          : 
Issue type        : kbprb 

Last Reviewed: March 7, 1999