Article ID: 118622
Article Last Modified on 11/21/2006
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 query words: 3.10 4.00
Keywords: kbinfo KB118622