I finally finished printing the image, and here, I will give it all to meet the needs of my friends who have the same experience. Here, I would like to thank the Vckbase in particular liurong! In addition, because this is my first article, unavoidably has unsatisfactory place, welcome everybody to put forward the criticism and the suggestion, first thanks.
VC in the image printing generally there are two ways:
First, the selection of printing equipment environment, with Drawstate can be printed out, this can be used in the resources of the image of the printout, relatively simple, no longer said.
Second, the window content printing, this is the focus of this article, but also I encountered the biggest problem, the following I mainly introduce this type of printing;
1. Brief introduction of the project
Create a dialog based project, the dialog box does not have a title bar, in its customer area, drawing, according to the needs of users to print out the content of the customer area;
2, need to solve the problem
(1), because the dialog box does not have a title bar, menu bar and other buttons, but to allow users to print their content when needed, you can define a hotkey, the definition of the hotkey is (ctrl+p),
(2), because it is a dialog based project, the application framework does not provide printing capabilities, which requires us to create a print device environment that can be implemented using CDC member function CreateDC, but with this method, the printer name and printer driver name must be known beforehand, The author uses another method, the concrete method see the code in the project print function;
(3), the principle of printing: the establishment of memory device environment, the contents of the dialog box to the memory device environment, and then the contents of the memory device environment copy to the print device environment;
(4), the author found in the experiment, "a problem with creating a memory device environment while printing, and then copying the contents of the dialog box to a memory device environment, and then copying content from the memory device environment to the print device environment is that the Print dialog box that pops up when you print will overwrite the dialog we created. So the content in the actual copied memory device environment is not covered, in this case, the author used a member function to store the memory device environment, and in the OnPaint (that is, each time the repaint) to copy the contents of the dialog box to the memory device environment, this is Liurong Give me the inspiration because I originally printed out just a black rectangular box, thank you!
(5), the project also implemented without the Title dialog box Drag!
Iii. Methods of Use
Use, only in the OnPaint "show picture" part of the drawing can be, be sure to copy to the memory device environment before drawing;
Well, for concrete implementation, please see the code in the engineering file (printed successfully under VC6,XP), thank Vckbase and liurong!
Download source code: http://www.vckbase.com/code/downcode.asp?id=2313