Re: Attaching Printer to CDC
Here's a function that should do what you want:
HDC CreatePrinterDC(LPCTSTR szPrinterName)
{
PDEVMODE pDevMode = NULL;
LONG lDevModeSize = ::DocumentProperties(NULL, NULL, (LPTSTR)szPrinterName, NULL, NULL, 0);
if (lDevModeSize > 0)
{
HANDLE hDevMode = ::GlobalAlloc(GHND, lDevModeSize);
pDevMode = (PDEVMODE) ::GlobalLock(hDevMode);
::DocumentProperties(GetDesktopWindow(), NULL, (LPTSTR)szPrinterName, pDevMode, NULL, DM_OUT_BUFFER);
}
else
return NULL;
// Here you can change the margins, orientation, etc. by manipulating pDevMode.
// Now get a DC for the printer
HDC hDC = ::CreateDC(NULL, szPrinterName, NULL, pDevMode);
::GlobalFree((HANDLE)pDevMode);
return hDC;
}
I don't know how to change the margins after the DC is created but you can certainly set them beforehand (via the DEVMODE pointer).
Good luck!
Alvaro