I want to print some vector graphics (or to be more exact: nothing more than some polylines) using Windows API. Printing has to be done out of an own thread.
When I ask Google/MSDN for some code-snippets or examples I mainly find documentation how to print using some WindowsForms/.NET crap, but no WinAPI examples. Or I find a really huge example of XPS printing provided by MS which is very confusing and does much more than only sending some data to printer.
So my question: is there a simple example somewhere that demonstrates how to print out some stupid lines?
If you want to use the traditional GDI functions to do this, you have two main steps:
First, learn to use GDI functions to draw in your own window. Some functions in this category include PolyLine, LineTo – and so on.
Next, getting it to work with a printer. It’s really the same concept as drawing to the screen, except you instead get a HDC that represents a portion of a page rather than a portion of screen – plus there’s more setup and cleanup involved. When drawing on screen, you can just get the window DC, draw, and you’re done; printing to a page is more involved – you have to select a printer, start a document, start a page, and so on.
I found this fairly decent tutuorial on Win32 GDI printing that might work for you – it covers all the setup/cleanup steps. One thing to watch for is that it sends a bitmap to the printer; instead you would want to replace the
StretchDIBitscall with your ownPolyLineetc calls.