小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

如何使用MFC將CListCtrl中內(nèi)容輸出到打印機

 fcs_110 2011-04-06
//該結(jié)構(gòu)用于存儲各列的信息
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();
//獲得行,列的個數(shù)
int   nColCount   =   pHeader-> GetItemCount();
int   nLineCount   =   list.GetItemCount();

int   ColOrderArray[100];
COLATT   ca[100];
list.GetColumnOrderArray(ColOrderArray,   nColCount);
int   nColX   =nXMargin*nCharWidth;

//檢索各列的信息,確定列標題的內(nèi)容長度。
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( "字段太多,無法在一行內(nèi)打印,請試用較大的紙,或橫向打印。 ");
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);

//調(diào)整各列的寬度,以使各列在后面的打印輸出時更均勻的打印在紙上。
int   space   =   (nHorRes-nXMargin*nCharWidth-nColX)   /   (nColCount   -1);
for(i   =1;   i <nColCount;   i++)
{
ca[i].nPrintX   +=   i*space;
}

//輸出列標題
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;
//輸出各列的數(shù)據(jù)
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));
}
}

EndPage(pd.hDC);
EndDoc(pd.hDC);
//打印結(jié)束
DeleteDC(pd.hDC);
return   TRUE;
}

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多