How to use API directly in VC ++

xiaoxiao2021-03-06  120

In Visual C , the application is usually used in ONPRINT () or OnDRAW () in Onprint () or OnDraw (). But for data in the dialog, or printed into a cumbersome work based on the dialog. This section provides the user with the PrintListCtrl () function for printing the contents of the user in the dialog or FormView (the control must be the form of the Report View) control. During the printing process, the width of the columns when the printout is calculated according to the width of each column title in the control, and automatically pane according to the number of lines of the data. On the basis of this code, it can be adapted to the output of various data. (Usage :) This segment code uses Visual C 6.0, use the Windows API to complete the desired function, use this text as header files. Call directly of PrintListCtrl (), and the parameters of the function are the listctrl to be printed. ? Contact: typedef struct lff@mail.wl.xj.cn * /// information of the structures for each column is stored tagColAtt {int nColIndex; CString strColText; int nPrintX; int nSubItemIndex;} COLATT; BOOL PrintListCtrl (CListCtrl & list ) {Printdlg pd; pd.lstructSize = sizeof (printdlg); pd.flags = pd_returndc; pd.hdc = null; pd.hwndowner = null; pd.hinstance = null; pd.nmaxpage = 1; pd.nminpage = 1; Pd.nFromPage = 1; pd.ntopage = 1; pd.ncopies = 1; pd.hdevmode = null; pd.hdevnames = null; // Displays the print dialog, by the user to set the paper size.

IF (! PrintDLG (& PD)) Return False; assert (pd.hdc! = null); int norres = getDeviceCaps (pd.hdc, horzres); int NVERRES = getDeviceCaps (pd.hdc, vertres); int nxmargin = 2; int nYMargin = 2; TEXTMETRIC tm; GetTextMetrics (pd.hDC, & tm); int nCharHeight = tm.tmHeight; int nCharWidth = tm.tmAveCharWidth; CHeaderCtrl * pHeader = list.GetHeaderCtrl (); // get the line, the number of columns int nColCount = pHeader-> GetItemCount (); int nLineCount = list.GetItemCount (); int ColOrderArray [100]; COLATT ca [100]; list.GetColumnOrderArray (ColOrderArray, nColCount); int nColX = nXMargin * nCharWidth; // retrieving The information of each column determines the content length of the column header. For (int i = 0; i nhorres) {deletedc (pd.hdc); afXMESSAGEBOX ("There are too many fields, unable to print in one line, please try large paper, or Transverse printing. "); Returnfo di; di.cbsize = sizeof (di.lpszdocname =" listctrl data print "; di.lpszoutput = (lptstr) NULL; di.lpszdattype = (lptstr) NULL Di.fWType = 0; StartDoc (PD.HDC, & DI); STARTPAGE (PD.HDC); // Adjust the width of each column to make each column to print more uniformly on paper when printing out.

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

New Post(0)