Home > Software engineering >  VC how to customize the paper size
VC how to customize the paper size

Time:12-26


Int CMyDlg: : PrintTest ()
{
CPrintDialog PrintDialog (TRUE, PD_ALLPAGES | PD_NOPAGENUMS, NULL);
If (PrintDialog. DoModal ()!=IDOK) return 0;//show the print setup dialog (don't show this line to remove)

//to redefine the paper size
DEVMODE * lpDevMode=(DEVMODE *) PrintDialog. GetDevMode ();
LpDevMode - & gt; DmPaperSize=DMPAPER_USER;//set for custom paper size
LpDevMode - & gt; DmFields |=DM_PAPERSIZE;//allow to set the paper size
LpDevMode - & gt; DmPaperWidth=900;//printing paper width 9 cm
LpDevMode - & gt; DmPaperLength=1200;//set paper is 12 cm long

HDC PrintDC=PrintDialog. CreatePrinterDC ();//returns a handle to a printed DC
ResetDC (PrintDC lpDevMode);//make setting parameters work

The CDC dc;
Dc. Attach (PrintDC);
Dc. ResetDC (lpDevMode);


Int printWidth=dc. GetDeviceCaps (HORZRES);
Int printHeight=dc. GetDeviceCaps (VERTRES);

Cstrings kk.
Kk. The Format (" printWidth=% d, printHeight=% d ", printWidth, printHeight);
AfxMessageBox (kk);
return 1;
}

I design a certificate print program, no matter change lpDevMode - & gt; DmPaperWidth numerical size
The above program shows the result is always the same
I don't know what went wrong?


CodePudding user response:

Finally found the answer, the following results right
Int CMyDlg: : PrintTest ()
{
CPrintDialog DLG (FALSE, PD_RETURNDEFAULT);//structure print dialog

If (DLG) DoModal ()==IDOK)
{
The CDC dc;
//define the size of the printing paper
LPDEVMODE dev=DLG. GetDevMode ();
Dev - & gt; DmPaperSize=DMPAPER_USER;
Dev - & gt; DmPaperLength=1900;
Dev - & gt; DmPaperWidth=1600;
Dev - & gt; DmFields=DM_PAPERSIZE | DM_PAPERWIDTH | DM_PAPERLENGTH | dev - & gt; DmFields;
Dev - & gt; DmFields=dev - & gt; DmFields | DMBIN_MANUAL;
Dev - & gt; DmDefaultSource=DMBIN_MANUAL;

//typed for printable area of the long and wide
Dc. Attach (DLG) CreatePrinterDC ());
CSize size;
Size. Cx=dc. GetDeviceCaps (VERTSIZE);
Size. Cy=dc. GetDeviceCaps (HORZSIZE);
CString str;
STR. The Format (" long: \ n % d mm wide: % d mm ", the size. The cx, size. The cy);
AfxMessageBox (STR);
Dc. DeleteDC ();
}
return 1;
}
  • Related