Call the system API to print image text

Source: Internet
Author: User
{
Lpctstr filename = _ T ( " D: \ 1.bmp " );
Cprintdialog printdlg (false );
Printdlg. getdefaults ();
// Or get from user:
// If (printdlg. domodal () = idcancel)
// Return;
Cdc dc;
If (! DC. Attach (printdlg. getprinterdc ())){
Afxmessagebox (_ T ( " No printer founhh NN nd! " )); Return ;
}

Hfont, holdfont;
Hfont = createfont (36,18,0,0, Fw_normal, false, gb2312_charset, out_default_precis, clip_default_precis, default_quality, default_pitch | ff_modern, _ T ("Simhei"));
Holdfont = (hfont) SelectObject (DC, hfont );

DC. m_bprinting = true;
Docinfo di;
// Initialise print document details
: Zeromemory (& Di, Sizeof (Docinfo ));
Di. cbsize = Sizeof (Docinfo );
Di. lpszdocname = filename;
Bool bprintingok = Dc. startdoc (& di ); // Begin a new print job
// Get the printing extents
// And store in the m_rectdraw field of
// Cprintinfo object
Cprintinfo Info;
Info. setmaxpage ( 1 ); // Just one page
Int Maxw = Dc. getdevicecaps (horzres );
Int Maxh = Dc. getdevicecaps (vertres );
Info. m_rectdraw.setrect ( 0 , 0 , Maxw, maxh );
For (Uint page = info. getminpage (); page <=
Info. getmaxpage () & bprintingok; Page ++ ){
DC. startpage (); // Begin new page
Info. m_ncurpage = page;
Cbitmap bitmap;
If (! Bitmap. Attach (: LoadImage (
: Getmodulehandle (null), filename, image_bitmap, 0 , 0 ,
Lr_loadfromfile | lr_createdibsection | lr_defaultsize ))){
Afxmessagebox (_ T ( " Error loading bitmap! " )); Return ;
}
Bitmap bm;
Bitmap. getbitmap (& BM );
Int W = BM. bmwidth;
Int H = BM. bmheight;
// Create memory device context
CDC memdc;
Memdc. createcompatibledc (& DC );
Cbitmap * pbmp = memdc. SelectObject (& Bitmap );
Memdc. setmapmode (DC. getmapmode ());
DC. setstretchbltmode (halftone );
// Now stretchblt to maximum width on page
DC. stretchblt (15 , 20 , 300 , 110 , & Memdc, 0 , 0 , W, H, srccopy );
// Textout
Hpen = createpen (ps_solid, 3 , RGB (0 , 0 , 0 ));
Hgdiobj holdpen = SelectObject (DC, Hpen );
Cstringw text;
TEXT = " Resource code " ;
Textout (DC, 15 ,144 + 80 , Text, text. getlength ());
TEXT = " Design Unit " ;
Textout (DC, 15 , 210 + 80 , Text, text. getlength ());
TEXT = " Construction Unit " ;
Textout (DC, 15 , 276 + 80 , Text, text. getlength ());
TEXT = " Acceptance Unit " ;
Textout (DC, 15 , 342 + 80 , Text, text. getlength ());
TEXT = " Completion date " ;
Textout (DC, 15 , 408 + 80 , Text, text. getlength ());
// Line
Movetoex (DC, 160 , 180 + 80 , Null );
Lineto (DC, 516 , 180 + 80 );

Movetoex (DC,160,246+80, Null );
Lineto (DC,516,246+80);

Movetoex (DC,160,312+80, Null );
Lineto (DC,516,312+80);

Movetoex (DC,160,378+80, Null );
Lineto (DC,516,378+80);

Movetoex (DC,160,444+80, Null );
Lineto (DC,516,444+80);

SelectObject (DC, holdpen );
Deleteobject (Hpen );
// Clean up
Memdc. SelectObject (pbmp );
Bprintingok = (DC. endpage ()> 0 ); // End page
}
If (Bprintingok)
DC. enddoc (); // End a print job
Else DC. abortdoc (); // Abort job.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.