Using the Document Properties Dialog Box

Last reviewed: September 29, 1995
Article ID: Q118622
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1, 3.5, and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

A number of applications display a printer-configuration dialog box titled "Document Properties" when the user chooses File from the application menu, chooses Print, and then chooses the Setup button.

The DocumentProperties() API is used to display this dialog box. You need to call DocumentProperties() with the DM_IN_PROMPT bit set in the last parameter (fMode). You also need to call OpenPrinter() before calling DocumentProperties().

MORE INFORMATION

The following code demonstrates how to call DocumentProperties():

Sample Code

   HDC         hPrnDC;
   LPDEVMODE   lpDevMode = NULL;
   LPDEVNAMES  lpDevNames;
   LPSTR       lpszDriverName;
   LPSTR       lpszDeviceName;
   LPSTR       lpszPortName;
   PRINTDLG    pd;
   HANDLE      hPrinter;
   int         nDMSize;
   HANDLE      hDevMode;
   NPDEVMODE   npDevMode;
   DEVMODE     DevModeIn;

   // Get the defaults without displaying any dialog boxes.

   pd.Flags = PD_RETURNDEFAULT;
   pd.hDevNames = NULL;
   pd.hDevMode = NULL;
   pd.lStructSize = sizeof(PRINTDLG);
   PrintDlg((LPPRINTDLG)&pd);

   lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
   lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
   lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
   lpszPortName   = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;

   OpenPrinter(lpszDeviceName,&hPrinter,NULL);

   // A zero for last param returns the size of buffer needed.

   nDMSize = DocumentProperties(hWnd,hPrinter,lpszDeviceName,NULL,NULL,0);
   if ((nDMSize < 0) || !(hDevMode = LocalAlloc (LHND, nDMSize)))
      return NULL;

   npDevMode = (NPDEVMODE) LocalLock (hDevMode);

   // Fill in the rest of the structure.

   lstrcpy (DevModeIn.dmDeviceName, lpszDeviceName);
   DevModeIn.dmSpecVersion    = 0x300;
   DevModeIn.dmDriverVersion  = 0;
   DevModeIn.dmSize           = sizeof (DevModeIn);
   DevModeIn.dmDriverExtra    = 0;

   // Display the "Document Properties" dialog box.

   DocumentProperties(hWnd,hPrinter,lpszDeviceName,npDevMode,&DevModeIn,
      DM_IN_PROMPT|DM_OUT_BUFFER);

   // Get the printer DC.

   hPrnDC = CreateDC
(lpszDriverName,lpszDeviceName,lpszPortName,(LPSTR)npDevMode);
   LocalUnlock (hDevMode);

   //  Use the printer DC.

   ...


Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbprint
KBSubcategory: GdiPrn


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.