Archived

This topic is now archived and is closed to further replies.

Meister_J

Printers...

Recommended Posts

Meister_J    122
I just finished up a program for keeping stock and stuff, how do I access a printer to print a reciept? I need to know how to access it and how I arrange the aesthetics of the printed material. Thanks in advance!

Share this post


Link to post
Share on other sites
I'm assuming here you're using C++ for Windows. If that's the case, what you need to do is get a device context to the printer. The easiest way to do this is to create a PRINTDLG structure, and use it with the PrintDlg function. See this code:


    
PRINTDLG pd;
memset ((void *) &pd, 0, sizeof(PRINTDLG));

pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd;
pd.Flags = PD_RETURNDC;
pd.hInstance = NULL;

PrintDlg(&pd);
HDC ghdc = pd.hDC;

if (pd.hDevMode)
GlobalFree (pd.hDevMode);

if (pd.hDevNames)
GlobalFree (pd.hDevNames);

DOCINFO di;
SetMapMode (ghdc, MM_TEXT);
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Test";
di.lpszOutput = NULL;

StartDoc(ghdc, &di);
StartPage(ghdc);

// Print your stuff here


EndPage(ghdc);
EndDoc(ghdc);


Most of this is taken more or less straight from MSDN stuff. As far as actually printing what you want to a page, you'd treat it exactly like you would to a window. Any functions like StretchBlt, FrameRect, etc., work just as they do on a window, to my experience anyway.

Hope this helps-
-Arek the Absolute

[edited by - Arek the Absolute on June 9, 2002 9:34:36 PM]

Share this post


Link to post
Share on other sites