📄 subject_35184.htm
字号:
<p>
序号:35184 发表者:ohye212 发表日期:2003-04-04 15:33:55
<br>主题:1000分!!!!有本事来那!!!!
<br>内容:用API打印,只有字母,数字,汉字显示为乱码!!!!急!!!!!! <BR><BR><BR>typedef struct tagColAtt<BR>{<BR> int nColIndex;<BR> CString strColText;<BR> int nPrintX;<BR> int nSubItemIndex;<BR>}COLATT;<BR><BR>BOOL PrintListCtrl(CListCtrl &list)<BR>{<BR><BR> PRINTDLG pd;<BR> pd.lStructSize = sizeof(PRINTDLG);<BR> pd.Flags = PD_RETURNDC;<BR> pd.hDC = NULL;<BR> pd.hwndOwner = NULL;<BR> pd.hInstance = NULL;<BR> pd.nMaxPage = 1;<BR> pd.nMinPage = 1;<BR> pd.nFromPage = 1;<BR> pd.nToPage = 1;<BR> pd.nCopies = 1;<BR> pd.hDevMode = NULL;<BR> pd.hDevNames = NULL;<BR><BR> //显示打印对话框,由用户来设定纸张大小等。<BR> if(!PrintDlg(&pd)) return FALSE; <BR> ASSERT(pd.hDC!=NULL);<BR><BR> int nHorRes = GetDeviceCaps(pd.hDC, HORZRES); <BR> int nVerRes = GetDeviceCaps(pd.hDC, VERTRES);<BR> int nXMargin = 2;<BR> int nYMargin = 2;<BR> TEXTMETRIC tm;<BR> GetTextMetrics(pd.hDC, &tm);<BR> int nCharHeight = tm.tmHeight;<BR> int nCharWidth = tm.tmAveCharWidth;<BR> <BR><BR> CHeaderCtrl* pHeader = list.GetHeaderCtrl();<BR> //获得行,列的个数<BR> int nColCount = pHeader->GetItemCount();<BR> int nLineCount = list.GetItemCount();<BR> <BR> int ColOrderArray[100];<BR> COLATT ca[100];<BR> list.GetColumnOrderArray(ColOrderArray, nColCount);<BR> int nColX =nXMargin*nCharWidth;<BR><BR> //检索各列的信息,确定列标题的内容长度。<BR> for(int i =0 ; i< nColCount; i++)<BR> {<BR> ca[i].nColIndex = ColOrderArray[i];<BR> LVCOLUMN lvc;<BR> char text[100];<BR> lvc.mask = LVCF_TEXT|LVCF_SUBITEM;<BR> lvc.pszText = text;<BR> lvc.cchTextMax = 100;<BR> list.GetColumn(ca[i].nColIndex, &lvc);<BR> ca[i].strColText = lvc.pszText;<BR> ca[i].nSubItemIndex = lvc.iSubItem;<BR> ca[i].nPrintX = nColX;<BR> nColX += nCharWidth * strlen(ca[i].strColText);<BR><BR> if(nColX > nHorRes) <BR> {<BR> DeleteDC(pd.hDC);<BR> AfxMessageBox("字段太多,无法在一行内打印,请试用较大的纸,或横向打印。");<BR> return FALSE;<BR> }<BR><BR> <BR> }<BR><BR> DOCINFO di;<BR> di.cbSize = sizeof(DOCINFO);<BR> di.lpszDocName = "ListCtrl Data Printing"; <BR> di.lpszOutput = (LPTSTR) NULL; <BR> di.lpszDatatype = (LPTSTR) NULL; <BR> di.fwType = 0; <BR> StartDoc(pd.hDC, &di);<BR> StartPage(pd.hDC);<BR><BR> //调整各列的宽度,以使各列在后面的打印输出时更均匀的打印在纸上。<BR> int space = (nHorRes-nXMargin*nCharWidth-nColX) / (nColCount -1);<BR> for(i =1; i<nColCount; i++)<BR> {<BR> ca[i].nPrintX += i*space;<BR> }<BR> <BR> //输出列标题<BR> for(i =0; i<nColCount; i++)<BR> TextOut(pd.hDC, ca[i].nPrintX, nYMargin, <BR> ca[i].strColText, strlen(ca[i].strColText));<BR> <BR> int nMaxLinePerPage = nVerRes/nCharHeight -3;<BR> int nCurPage =1;<BR> //输出各列的数据<BR> for(i =0; i<nLineCount; i++)<BR> {<BR> for(int j =0; j<nColCount; j++)<BR> {<BR> if(i+1-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)<BR> {<BR> //新的一页<BR> EndPage(pd.hDC);<BR> StartPage(pd.hDC);<BR> nCurPage ++;<BR> }<BR> CString subitem = list.GetItemText(i, ca[j].nSubItemIndex);<BR> TextOut(pd.hDC, ca[j].nPrintX, <BR> nYMargin+(i+1-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, <BR> subitem, strlen(subitem));<BR> }<BR> }<BR> <BR> EndPage(pd.hDC);<BR> EndDoc(pd.hDC);<BR>//打印结束<BR> DeleteDC(pd.hDC);<BR> return TRUE;<BR>}<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -