Use of the printer under VC

zhaozj2021-02-11  194

VC 5.0 is a powerful tool for developing Windows 95 applications. This article will discuss some techniques for printing text and graphics with VC through a specific example. Under Windows 95, the display and printer, the plotter is considered an output device. The default output device of the system is a display. To use a printer, you first need to create a device environment handle pointing to the printer, then call the related drawing function by this handle to output the desired text and graphics to the printer. When the print is over, delete this device environment handle. I. Technical details When we install the printer in Windows 95, we always need to set up a default printer in WinDOWS 95 launch profile Win.ini [Window] segment. If there is a few lines in the file win.ini: [Windows] [other procedures] Device = EPSON LQ-1600K, EPSON24, LPT1: The three important printers in the system are included in the system's strings. Attributes. They are in turn is the device name of the printer is LQ-1600K, the driver name is EPSON24, the output port is LPT1. In the program we can call the API function getProfileString to get this device string from the win.ini file. Then, decompose this device string, get these three properties, and use the API function createDC as a parameter. If the call is successful, create a device environment handle for the default printer, otherwise a null value is returned. The original shape of the CreatedC function is as follows: HDC Createdc (LPCTSTSTSTSZZDRIVER, LPCTSTSTSTSTSZZDEVICE, LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSZOTPUT, Const devMode * LpinitData); Second, program code and new projects named TEST, form type Dialog (Dialog Based) mode. Add a button (Button) to set this button attribute: ID = IDC_PRINT, CAPTION = "Print". In the class wizard, find the message BN_Clicked of the BUTTON in the class wizard to increase its member function onprint. Find the onPrint function in the TestDlg.cpp file and make the following changes.

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

New Post(0)