Help with PRINTDLG and PrintDlg

C

charles hamm

I'm trying to use PrintDlg (and PRINTDLG) to create a printer dialog
with landscape as the default. Here is my code (from within a
CDialog-based class):

PRINTDLG printDlg;
ZeroMemory(&printDlg, sizeof(printDlg));
printDlg.lStructSize = sizeof(printDlg);
printDlg.Flags = PD_RETURNDEFAULT;
PrintDlg(&printDlg);
DEVMODE* pDevMode = (DEVMODE*)printDlg.hDevMode;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
printDlg.hwndOwner = m_hWnd;
printDlg.Flags = PD_RETURNDC | PD_NOSELECTION;
if (PrintDlg(&printDlg)) {

The problem is that the HANDLE returned in hDevMode from the first
call to PrintDlg does not point to anything that looks like a DEVMODE
structure. Furthermore, if I set the dmOrientation field to landscape,
the print box comes up with orientation set to portrait. What am I
doing wrong here? Is a HANDLE not just a disguised pointer? The
PRINTDLG documentation implies that this should work.
 
D

David Lowndes

DEVMODE* pDevMode = (DEVMODE*)printDlg.hDevMode;

Try using GlobalLock on the hDevMode.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top