Click here to Skip to main content
15,897,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How send/reseive SMS with a GSM Modem in C++(MFC) Pin
Rhuros19-May-11 21:47
professionalRhuros19-May-11 21:47 
QuestionOpen and display any image on dialog Pin
manju 319-May-11 20:54
manju 319-May-11 20:54 
AnswerRe: Open and display any image on dialog Pin
ShilpiP19-May-11 21:14
ShilpiP19-May-11 21:14 
QuestionMFC, How to activate one document template among multiple document templates Pin
swandream19-May-11 15:11
swandream19-May-11 15:11 
QuestionEncrypting Archives with AES Pin
sarfaraznawaz19-May-11 1:57
sarfaraznawaz19-May-11 1:57 
AnswerRe: Encrypting Archives with AES Pin
Chris Losinger19-May-11 3:37
professionalChris Losinger19-May-11 3:37 
GeneralRe: Encrypting Archives with AES Pin
sarfaraznawaz19-May-11 19:53
sarfaraznawaz19-May-11 19:53 
Questionabout CListCtrl Pin
luyuxibaby19-May-11 0:41
luyuxibaby19-May-11 0:41 
hello everybody :

i created a dialog base program and it has a CListCtrl on the dialog. now ,i wanna print the datas of CListCtrl.but the reuslt was wrong.

may be the wrong in TextOut function

following 's my code , help me please.



BOOL CBingLiGuanLi::PrintList(CListCtrl *pListCtrl)<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 />
	if(!PrintDlg(&pd))   return   FALSE;   <br />
	ASSERT(pd.hDC!=NULL);   <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 />
	CHeaderCtrl*   pHeader   =   pListCtrl->GetHeaderCtrl();   <br />
	//获得行,列的个数   <br />
	int   nColCount   =   pHeader->GetItemCount();   <br />
	int   nLineCount   =   pListCtrl->GetItemCount();   <br />
	int   ColOrderArray[100];   <br />
	COLATT   ca[100];   <br />
	pListCtrl->GetColumnOrderArray(ColOrderArray,   nColCount);   <br />
	int   nColX   =nXMargin*nCharWidth;   <br />
	//检索各列的信息,确定列标题的内容长度。   <br />
	for(int   iXinXi   =0   ;   iXinXi<   nColCount;   iXinXi++)   <br />
	{   <br />
		ca[iXinXi].nColIndex   =   ColOrderArray[iXinXi];   <br />
		LVCOLUMN   lvc;   <br />
		char   text[100];   <br />
		lvc.mask   =   LVCF_TEXT|LVCF_SUBITEM;   <br />
		lvc.pszText   =   text;   <br />
		lvc.cchTextMax   =   100;   <br />
		pListCtrl->GetColumn(ca[iXinXi].nColIndex,   &lvc);   <br />
		ca[iXinXi].strColText   =   lvc.pszText;   <br />
		ca[iXinXi].nSubItemIndex   =   lvc.iSubItem;   <br />
		ca[iXinXi].nPrintX   =   nColX;   <br />
		nColX   +=   nCharWidth   *   strlen(ca[iXinXi].strColText);   <br />
		if(nColX   >   nHorRes)   <br />
		{   <br />
			DeleteDC(pd.hDC);   <br />
			AfxMessageBox("字段太多,无法在一行内打印,请试用较大的纸,或横向打印。");   <br />
			return   FALSE;   <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 />
	int   space   =   (nHorRes-nXMargin*nCharWidth-nColX)   /   (nColCount   -1);   <br />
	for(int	iKuanDu  =1;   iKuanDu<nColCount;  iKuanDu++)   <br />
	{   <br />
		ca[iKuanDu].nPrintX   +=   iKuanDu*space;   <br />
	}   <br />
	//输出列标题   <br />
	for(int	iLieBiaoTi  =0;   iLieBiaoTi<nColCount;   iLieBiaoTi++)   <br />
	{<br />
		TextOut(pd.hDC,   ca[iLieBiaoTi].nPrintX,   nYMargin,   <br />
			ca[iLieBiaoTi].strColText,   strlen(ca[iLieBiaoTi].strColText));   <br />
	}<br />
	int   nMaxLinePerPage   =   nVerRes/nCharHeight   -3;   <br />
	int   nCurPage   =1;   <br />
	//输出各列的数据   <br />
	for(int 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   =   pListCtrl->GetItemText(j,   ca[j].nSubItemIndex);   <br />
			TextOut(pd.hDC,   ca[j].nPrintX,nYMargin+(j+1-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,subitem,   strlen(subitem));  <br />
			<br />
			<br />
		}   <br />
	}   <br />
	EndPage(pd.hDC);   <br />
	EndDoc(pd.hDC);   <br />
	//打印结束   <br />
	DeleteDC(pd.hDC);   <br />
	return   TRUE;    <br />
}

AnswerRe: about CListCtrl Pin
CPallini19-May-11 2:23
mveCPallini19-May-11 2:23 
QuestionMFC Program and Very Large Text Files Pin
Andy20219-May-11 0:37
Andy20219-May-11 0:37 
AnswerRe: MFC Program and Very Large Text Files Pin
Maximilien19-May-11 1:05
Maximilien19-May-11 1:05 
GeneralRe: MFC Program and Very Large Text Files [modified] Pin
federico.strati19-May-11 1:26
federico.strati19-May-11 1:26 
GeneralRe: MFC Program and Very Large Text Files Pin
Andy20219-May-11 22:04
Andy20219-May-11 22:04 
GeneralRe: MFC Program and Very Large Text Files Pin
federico.strati20-May-11 23:25
federico.strati20-May-11 23:25 
GeneralRe: MFC Program and Very Large Text Files Pin
Andy20225-May-11 21:33
Andy20225-May-11 21:33 
GeneralRe: MFC Program and Very Large Text Files Pin
federico.strati26-May-11 2:14
federico.strati26-May-11 2:14 
AnswerRe: MFC Program and Very Large Text Files Pin
Chandrasekharan P19-May-11 1:22
Chandrasekharan P19-May-11 1:22 
AnswerRe: MFC Program and Very Large Text Files Pin
jschell19-May-11 8:21
jschell19-May-11 8:21 
GeneralRe: MFC Program and Very Large Text Files Pin
Andy20219-May-11 22:10
Andy20219-May-11 22:10 
GeneralRe: MFC Program and Very Large Text Files Pin
jschell20-May-11 10:13
jschell20-May-11 10:13 
QuestionEmbedding Excel in a dialog Pin
efraimyy18-May-11 22:49
efraimyy18-May-11 22:49 
AnswerRe: Embedding Excel in a dialog Pin
Chandrasekharan P19-May-11 1:35
Chandrasekharan P19-May-11 1:35 
GeneralRe: Embedding Excel in a dialog Pin
efraimyy19-May-11 2:58
efraimyy19-May-11 2:58 
GeneralRe: Embedding Excel in a dialog Pin
efraimyy19-May-11 3:00
efraimyy19-May-11 3:00 
GeneralRe: Embedding Excel in a dialog Pin
Chandrasekharan P19-May-11 22:04
Chandrasekharan P19-May-11 22:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.