VC print practice

zhaozj2021-02-17  54

I often see some friends in the VC Forum to ask questions about printing. Many of them have asked many times. In fact, searching for the original post can find a lot, and all give correct solutions. But I have searched the document center, I found out that I have not yet. So I decided to write down my problems that I have encountered during the program, and the implementation methods and experience will be written down. If you have an omission in the text, please take a timely pointed out to avoid my mistakes.

When making a print module, the default configuration of the printer is often changed for different purposes. One of the most important structures for printer configuration is the DEVMODE structure (concrete constitutes of structures), which contains almost all configuration information of the printer. The implementation of several configuration items that are often used below will be given below.

PrintDLG PD; // This structure contains all information in the print dialog, LPDEVMODE LPDEVMODE; if (AFXGetApp () -> GetPrinterDeviceDefaults (& PD)) // Get the default printer information {LPDEVMODE = (LPDEVMode) Globalock (Pd.hdevmode) If (lpdevmode) {lpdevmode-> DMPAPAPERSIZE = DMPAPER_A4; // Set the printing paper to a4 lpdevmode-> dmorientation = DMORIENT_LANDSCAPE; // Set the printer horizontally printed. LPDEVMODE-> DMPRINTQUALITY = 600 // Print resolution is 600dpi} GlobalUnlock (pd.hdevmode);} In fact, look at the documentation of the DevMode structure in MSDN, you can configure your printer casually. If you want to configure it, you also display the print dialog for the user. You can replace the PD to printdlg.m_pd, of course you have to define PrintDLG prior. Implementation language is "CPrintDialog PrintDLG (FALSE);".

The content I have to say is that I want to write the original intention of this article. This is the question I just solved. No one can answer in the online post, so I wrote it to share it with friends.

I wrote the print program, printing it normally on my machine, but the print is not normal, the printed font is more than me, the entire layout is messy. I can give it confused, the same printer, I also set the mapping mode in MM_TEXT, how can this happen? Later, colleagues found the problem, because the resolution used in printing was different. Since our different machines are loaded with different versions of print drivers, their default print resolution is different. The print drive on my machine default is the resolution of 1200DPI, and the resolution of the problem of the problem is 600dpi. So the fonts played twice more than the original. Let me analyze the reason: the height of the font in Windows, the width is represented by logical units, and the logic unit itself is not a length unit. However, fonts can be displayed on different device terminals after calculating according to a certain mapping mode. For example: there is a font higher than 240 logical units, the system's mapping mode is mm_text (ie, a logical unit corresponds to a device pixel), then the font is over 240 pixels in the output of the screen, and if you change to another mapping mode It will output different sizes on the screen. If we change the resolution of the display, the resolution is increased, and the corresponding amount of pixels will become smaller. Then follow the mm_text mapping mode, display the font on the display, then the font will also look small than just.

Similarly, this is also suitable for printers, and the device pixels of the printer are points. 1200DPI indicates that the printer can play 1200 points per inch. 600DPI indicates that you can play 600 points per inch. Obviously for any font, the size printed on the printer of 600 dpi is twice the size of the print size on the 1200DPI resolution printer. So in order to deal with this problem I set a print factor, multiplying this factor for all the parameters used in all print layouts, so that the problem is solved. Below is the implementation of the print coefficient: #define print_dpi_default 1200 // I adjusted the program resolution of 1200dpi m_fxcoEfficient = 1; // Initialize the print coefficient

Printdlg Pd; lpdevmode lpdevmode; double fxdpi = print_dpi_default; //

CPrintDialog Printdlg (false);

if (AfxGetApp () -> GetPrinterDeviceDefaults (& pd)) {lpDevMode = (LPDEVMODE) GlobalLock (pd.hDevMode); if (lpDevMode) {lpDevMode-> dmPaperSize = DMPAPER_A4;} GlobalUnlock (pd.hDevMode);}

printDlg.m_pd.hDevMode = pd.hDevMode; if (printDlg.DoModal () == IDCANCEL) return; fXDPI = (double) lpDevMode-> dmPrintQuality; if (fXDPI> 0) {m_fXCoefficient = fXDPI / PRINT_DPI_DEFAULT;}

Ugh! I have limited Chinese ability, I can only write this, I hope that all friends don't want to see! ! !

转载请注明原文地址:https://www.9cbs.com/read-30807.html

New Post(0)