i use either CreateDC() or PrintDlg() to retrieve a handle to a
printer. It works fine and i can print out my stuff, but i don't
know...
1.) how to print in lanscape when i used CreateDC() to open the
default printer
2.) how to check if i have selected landscape orientation when i use
the PrintDlg()-Function to choose a printer manually
How is it possible to get/set the printer orientation with pure
WinAPI?
Thanks in advance,
ball-lightning
It's in DEVMODE structure (dmOrientation) =>
PRINTDLG pd;
ZeroMemory(&pd, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
PrintDlg(&pd);
DEVMODE *dm=(DEVMODE *)GlobalLock(pd.hDevMode);
dm->dmOrientation=DMORIENT_LANDSCAPE;
ResetDC(pd.hDC,dm);
GlobalUnlock(pd.hDevMode);
// Print ....
Thanks a lot! It works fine with PrinterDlg(). I modified your code to
use it with my default printer function CreateDC():
LPBYTE lpValue;
lpValue = (LPBYTE)malloc(256);
GetPrinter(hPrinterDC, 2, lpValue, 256, &zeichen);
if (zeichen>256)
{
free(lpValue);
lpValue = (LPBYTE)malloc(zeichen);
GetPrinter(hPrinterDC, 2, lpValue, zeichen, &zeichen);
}
DEVMODE *dm=(DEVMODE *)GlobalLock(lpValue);
dm->dmOrientation=DMORIENT_LANDSCAPE;
ResetDC(hPrinterDC,dm);
GlobalUnlock(lpValue);
free(lpValue);
I used GetPrinter with parameter 2 to get the DevMode of the default
printer. It works fine, but perhaps there is a better solution?
kind regards,
ball-lightning
Greetings,
ball-lightning
hPrinterDC = CreateDC("WINSPOOL\0", Standarddrucker, NULL, NULL);
HANDLE hPrinter;
OpenPrinter(Standarddrucker,&hPrinter, NULL);
DWORD DevSize=0;
DevSize = DocumentProperties(hWnd, hPrinter, Standarddrucker, NULL,
NULL, 0);
LPDEVMODE pDevMode;
pDevMode = (LPDEVMODE)malloc(DevSize);
DWORD dwRet=0;
dwRet = DocumentProperties(hWnd, hPrinter, Standarddrucker, pDevMode,
NULL, DM_OUT_BUFFER);
// And then your code...
DEVMODE *dm=(DEVMODE *)GlobalLock(pDevMode);
dm->dmOrientation=DMORIENT_LANDSCAPE;
ResetDC(hPrinterDC,dm);
GlobalUnlock(dm);
Greetings,
ball-lightning