印度钦奈天气:如何使用MFC将CListCtrl中内容输出到打印机
来源:百度文库 编辑:偶看新闻 时间:2024/06/12 01:41:55
//该结构用于存储各列的信息
typedef struct 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;
//显示打印对话框,由用户来设定纸张大小等。
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 = 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{
ca[i].nPrintX += i*space;
}
//输出列标题
for(i =0; iTextOut(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{
for(int j =0; 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));
}
}
EndPage(pd.hDC);
EndDoc(pd.hDC);
//打印结束
DeleteDC(pd.hDC);
return TRUE;
}
typedef struct 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;
//显示打印对话框,由用户来设定纸张大小等。
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 = 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
ca[i].nPrintX += i*space;
}
//输出列标题
for(i =0; i
ca[i].strColText, strlen(ca[i].strColText));
int nMaxLinePerPage = nVerRes/nCharHeight -3;
int nCurPage =1;
//输出各列的数据
for(i =0; i
for(int j =0; 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));
}
}
EndPage(pd.hDC);
EndDoc(pd.hDC);
//打印结束
DeleteDC(pd.hDC);
return TRUE;
}
如何读取其他应用程序中CListCtrl的内容
MFC中如何使用API函数?
vc CListCtrl 如何判断列表中的内容是否被选中?
mfc 210c 如何使用
怎样在mfc 中使用 string 类??
vc下,使用ado 如何获得数据库中的表名并显示在clistctrl控件上
VC++中CListCtrl如何更改其行高与Header高度?
如何快速的向CListCtrl中插入大量的记录(VC)?
MFC中如何设置代码页?
如何将百度中搜索的内容删去
如何将光盘中的内容拷贝到硬盘中
如何将光盘的内容放在硬盘中。
如何将幻灯片中的内容复制到word 中
如何将Powerpoint中的内容导入到authorware7.0中
如何将摄像机的内容加入到电脑中
如何将光盘里的内容复制到计算机中
如何将EXCEL的内容倒入WORD 中?
EVC4.0 中static MFC libraries不能使用?
如何将一个Excel表格中的指定的表格中的内容复制到另外一个Excel表格中的指定表格中(最好使用VBA)?
如何使用mfc进行dao编程?请提供实例。
ASP中如何将页面中文本框的内容传入到数据库表中
怎么使用MFC
MFC使用中的问题
什么是MFC,使用MFC有什么好处?