Google групе више не подржавају нове Usenet постове ни праћења. Претходни садржај остаје видљив.

Printing in landscape with WinAPI

477 прегледа
Пређи на прву непрочитану поруку

ball-lightning

непрочитано,
4. 10. 2009. 03:46:414.10.09.
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

Christian ASTOR

непрочитано,
4. 10. 2009. 04:24:144.10.09.

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 ....

ball-lightning

непрочитано,
4. 10. 2009. 07:30:594.10.09.
On 4 Okt., 10:24, Christian ASTOR <casto...@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

ball-lightning

непрочитано,
4. 10. 2009. 10:01:104.10.09.
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

ball-lightning

непрочитано,
4. 10. 2009. 12:49:384.10.09.
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

0 нових порука