bool CRightListView::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;
//显示打印对话框,由用户来设定纸张大小等。
if(!PrintDlg(&pd)) return FALSE;
ASSERT(pd.hDC!=NULL);
int nHorRes = 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();
//获得行,列的个数
int nColCount = pHeader->GetItemCount();
int nLineCount = list.GetItemCount();
int ColOrderArray[100];
COLATT ca[100];
list.GetColumnOrderArray(ColOrderArray, nColCount);
int nColX =nXMargin*nCharWidth;
//检索各列的信息,确定列标题的内容长度。
for(int i =0; i< nColCount; i++)
{
ca[i].nColIndex = ColOrderArray[i];
LVCOLUMN lvc;
char text[100];
lvc.mask = LVCF_TEXT|LVCF_SUBITEM;
lvc.pszText = text;
lvc.cchTextMax = 100;
list.GetColumn(ca[i].nColIndex, &lvc);
ca[i].strColText = lvc.pszText;
ca[i].nSubItemIndex = i;//lvc.iSubItem;
ca[i].nPrintX = nColX;
nColX += nCharWidth * strlen(ca[i].strColText);if(nColX > nHorRes)
{
DeleteDC(pd.hDC);
AfxMessageBox("字段太多,无法在一行内打印,请试用较大的纸,或横向打印。");
return FALSE;
}
}
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "ListCtrl Data Printing";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
StartDoc(pd.hDC, &di);
StartPage(pd.hDC);
//调整各列的宽度,以使各列在后面的打印输出时更均匀的打印在纸上。
int space = (nHorRes-nXMargin*nCharWidth-nColX) / (nColCount -1);
for(i =1; i<nColCount; i++)
{
ca[i].nPrintX += i*space;
}
//输出列标题
CClientDC dc(this);
CFont font;
CFont *pOldFont=NULL;
font.CreatePointFont(320,"宋体");
pOldFont=(CFont *)dc.SelectObject(&font); for(i = 0; i<nColCount; i++)
TextOut(pd.hDC, ca[i].nPrintX, nYMargin,
ca[i].strColText, strlen(ca[i].strColText));
int nMaxLinePerPage = nVerRes/nCharHeight -3;
int nCurPage =1;
//输出各列的数据
for(i =0; i<nLineCount; i++)
{
for(int j =0; j<nColCount; j++)
{
if(i+1-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)
{
//新的一页
EndPage(pd.hDC);
StartPage(pd.hDC);
nCurPage ++;
}
CString subitem = list.GetItemText(i, ca[j].nSubItemIndex); TextOut(pd.hDC, ca[j].nPrintX,
nYMargin+(i+1-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
subitem, strlen(subitem));
}
//dc.SelectObject(pOldpen);
}
EndPage(pd.hDC);
EndDoc(pd.hDC);
//打印结束
DeleteDC(pd.hDC);
return TRUE;}
//---------------------------------以上是代码 可以实现打印,网上D的:P
打印的时候字太小了,怎么创建个PEN,然后再调用那个TEXTOUT呢?
也就是改变字体大小,谢谢了。还有一个数据结构
typedef struct tagColAtt
{
int nColIndex;
CString strColText;
int nPrintX;
int nSubItemIndex;
}COLATT;
{
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;
//显示打印对话框,由用户来设定纸张大小等。
if(!PrintDlg(&pd)) return FALSE;
ASSERT(pd.hDC!=NULL);
int nHorRes = 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();
//获得行,列的个数
int nColCount = pHeader->GetItemCount();
int nLineCount = list.GetItemCount();
int ColOrderArray[100];
COLATT ca[100];
list.GetColumnOrderArray(ColOrderArray, nColCount);
int nColX =nXMargin*nCharWidth;
//检索各列的信息,确定列标题的内容长度。
for(int i =0; i< nColCount; i++)
{
ca[i].nColIndex = ColOrderArray[i];
LVCOLUMN lvc;
char text[100];
lvc.mask = LVCF_TEXT|LVCF_SUBITEM;
lvc.pszText = text;
lvc.cchTextMax = 100;
list.GetColumn(ca[i].nColIndex, &lvc);
ca[i].strColText = lvc.pszText;
ca[i].nSubItemIndex = i;//lvc.iSubItem;
ca[i].nPrintX = nColX;
nColX += nCharWidth * strlen(ca[i].strColText);if(nColX > nHorRes)
{
DeleteDC(pd.hDC);
AfxMessageBox("字段太多,无法在一行内打印,请试用较大的纸,或横向打印。");
return FALSE;
}
}
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "ListCtrl Data Printing";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
StartDoc(pd.hDC, &di);
StartPage(pd.hDC);
//调整各列的宽度,以使各列在后面的打印输出时更均匀的打印在纸上。
int space = (nHorRes-nXMargin*nCharWidth-nColX) / (nColCount -1);
for(i =1; i<nColCount; i++)
{
ca[i].nPrintX += i*space;
}
//输出列标题
CClientDC dc(this);
CFont font;
CFont *pOldFont=NULL;
font.CreatePointFont(320,"宋体");
pOldFont=(CFont *)dc.SelectObject(&font); for(i = 0; i<nColCount; i++)
TextOut(pd.hDC, ca[i].nPrintX, nYMargin,
ca[i].strColText, strlen(ca[i].strColText));
int nMaxLinePerPage = nVerRes/nCharHeight -3;
int nCurPage =1;
//输出各列的数据
for(i =0; i<nLineCount; i++)
{
for(int j =0; j<nColCount; j++)
{
if(i+1-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)
{
//新的一页
EndPage(pd.hDC);
StartPage(pd.hDC);
nCurPage ++;
}
CString subitem = list.GetItemText(i, ca[j].nSubItemIndex); TextOut(pd.hDC, ca[j].nPrintX,
nYMargin+(i+1-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
subitem, strlen(subitem));
}
//dc.SelectObject(pOldpen);
}
EndPage(pd.hDC);
EndDoc(pd.hDC);
//打印结束
DeleteDC(pd.hDC);
return TRUE;}
//---------------------------------以上是代码 可以实现打印,网上D的:P
打印的时候字太小了,怎么创建个PEN,然后再调用那个TEXTOUT呢?
也就是改变字体大小,谢谢了。还有一个数据结构
typedef struct tagColAtt
{
int nColIndex;
CString strColText;
int nPrintX;
int nSubItemIndex;
}COLATT;
解决方案 »
- 设置combobox的文本
- 已经connect的SOCKET,如何disconnect(不要重新CreateSocket)
- 寒寒的问下!!!
- 调用dll时找不到函数
- 有两个非模态窗口时,如何使一个非模态窗口一直保持为当前窗口,而不让另一个非模态窗口响应鼠标事件呢?
- 救命啊!各位高手、打印问题!
- 谁有Prof-UIS界面库编程的详细资料啊
- 《Inside VCL(深入核心——VCL架构剖析)》
- 怎样改变OpenGL绘图的坐标原点的位置?
- 为什么用ODBC能连ORACLE和ACESS,不能连SQL SERVER
- 关于命令的转化 字符串变为16进制格式.
- 关于MFC Windows程序设计(第二版)第2.2.10节,64页上关于删除GDI对象的一个问题看不懂,谢谢大家帮助。(有图)
CFont font;
CFont *pOldFont=NULL;
font.CreatePointFont(320,"宋体");
pOldFont=(CFont *)dc.SelectObject(&font)
这不是原代码里的
怎么没有人呢 :(
CFont font;
CFont *pOldFont=NULL;
font.CreatePointFont(320,"宋体");
pOldFont=(CFont *)dc.SelectObject(&font)
这不是原代码里的
怎么没有人呢 :(