-3

what I want to do seems simple and straight forward, I wish to print a PNG file to the printer from Microsoft Visual C++ (non-managed code).

Phil
  • 46,436
  • 33
  • 110
  • 175
  • It's easy :) I mean really very very easy . http://technet.microsoft.com/en-us/library/bb490970.aspx is how to use print command, and you know about `system` command also http://msdn.microsoft.com/en-us/library/277bwbdz%28v=vs.71%29.aspx . So just `system(print...)` – abasu May 24 '13 at 08:49
  • 1
    "I wish to print a PNG". I miss "do-my-bidding-minion" tag. – Tadeusz Kopec for Ukraine May 24 '13 at 08:56
  • 2
    Creating the new tag 'do-my-bidding' requires at least 1500 reputation. Try something from the existing tags list instead. – Phil May 24 '13 at 08:59
  • 1
    It was a joke. This is not a "do-my-bidding-minion" site, that's why there's no such tag. Your question needs to show that you've put some effort into solving the problem yourself—e.g., code that you've tried, links to documentation you've explored, etc. You're not a new user, so perhaps you've forgotten what you read [here](http://stackoverflow.com/questions/how-to-ask) when you signed up. – Cody Gray - on strike May 24 '13 at 09:27

1 Answers1

6

Since the question shows little to no research effort, I'm going to treat it like a homework question and provide pointers in the right direction as opposed to a complete solution…

If you're at all familiar with Windows programming already*, you surely know that all graphics operations involve drawing onto or otherwise manipulating device contexts. This is how Windows abstracts away the myriad differences between different types/brands of output devices and allows the programmer to write the same code for all of them. There are device contexts for the screen (i.e., the monitor), and there are also device contexts for the printer. You've already used screen device contexts if you've drawn anything to the screen. Printer device contexts work much the same way.

So your first order of business is to create/obtain a printer device context. The documentation I linked to earlier should get you started, but in case you can't find it, the link you want is this one.

Once you have the printer device context, you just need to draw whatever you want into it. This can be either text or graphics—a PNG image in your case. Working with a PNG as opposed to, say, a bitmap (BMP) is made somewhat more difficult by the fact that GDI does not natively support PNGs. That topic was covered in more detail by this question and plenty of others here and elsewhere on the web. To save you a lot of reading, though, the simple answer is that you need to use GDI+ instead of GDI. The documentation for that starts here. It has a nice C++ API, but it's also usable from C. It works as far back as (at least) Windows 2000, although on those older versions it does require a redistributable DLL.

Using GDI+, there will be two primary classes that you'll use: the Graphics class (which encapsulates a device context), and the Image class (which represents images, including PNGs). Once you've created a Graphics object that represents your device context, and created an Image object from your image, you'll call the DrawImage instance method of your Graphics object to do the actual drawing.

I imagine that you will also find the following two how-to articles useful:

Remember, if you run into any specific problems while trying to write the code, please ask a new question that explains in detail what you've tried (preferably showing a little bit of sample code).

* If not, you've got quite a bit of work ahead of you. I recommend purchasing a book that explains it thoroughly. Windows programming is rather difficult to learn from reading Stack Overflow answers.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574