From: ball-lightning on
Hi,

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
From: Christian ASTOR on
On 4 oct, 09:46, ball-lightning <ball-lightn...(a)arcor.de> wrote:
> Hi,
>
> 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?

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 ....
From: ball-lightning on
On 4 Okt., 10:24, Christian ASTOR <casto...(a)club-internet.fr> wrote:
> 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
From: ball-lightning on
Sorry, the code is NOT correct...i think the structure lpValue is not
filled with the needed DEVMODE-data. Setting printer to landscape only
works for one time, but it seems that i submit an invalid DEVMODE-
structure and the second time i use ResetDC the program crashes.

Greetings,
ball-lightning
From: ball-lightning on
OK, this code seems to work better for me, at least it does not crash
and forces the printer to print in the desired orientation...it's
quick and dirty, without checking failures or deallocating space...

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