jaiken
asked on
PRINTING PROBLEMS
I have a listview in report mode that has a checkbox, an icon, and a label in the first column. All prints correctly except the size of the checkbox (state icon) and the icon. I'm pretty confused about the mapping modes so I'm thinking that is the problem. Below is code to print that 1st column of the list view. If anyone has any ideas what I'm doing wrong I'd be very greatful.
void CPrintListCtrl::Draw_Icons (int nItem, CRect stRect)
{
HIMAGELIST himl;
UINT dtFlags = DT_SINGLELINE|DT_NOPREFIX| DT_VCENTER ;
int nSaveDC = SaveDC(m_hPrintDC);
CClientDC dcScreen(NULL);
SetMapMode(m_hPrintDC, MM_ANISOTROPIC);
// map 1 screen logical inch to 1 printer (/output) logical inch
CSize CalcSize;
SetWindowExtEx(m_hPrintDC, dcScreen.GetDeviceCaps(LOG PIXELSX),
dcScreen.GetDeviceCaps(LOG PIXELSY), &CalcSize);
SetViewportExtEx(m_hPrintD C, GetDeviceCaps(m_hPrintDC, LOGPIXELSX),
GetDeviceCaps(m_hPrintDC, LOGPIXELSY), &CalcSize);
// get item data
LV_ITEM lvi;
lvi.mask = LVIF_IMAGE | LVIF_STATE | LVIF_INDENT;
lvi.iItem=nItem;
lvi.iSubItem=0;
lvi.stateMask=0xFFFF; // get all state flags
SendMessage(m_hListCtrl, LVM_GETITEM, (WPARAM)(int)0, (LPARAM)(LPLVITEM)&lvi);
//Get rectangles for painting
CRect rcBounds, rcLabel, rcIcon;
rcBounds.left = LVIR_BOUNDS;
rcLabel.left = LVIR_LABEL;
rcIcon.left = LVIR_ICON;
SendMessage(m_hListCtrl, LVM_GETITEMRECT, (WPARAM) (int) nItem, (LPARAM) (LPRECT) rcBounds);
SendMessage(m_hListCtrl, LVM_GETITEMRECT, (WPARAM) (int) nItem, (LPARAM) (LPRECT) rcLabel);
SendMessage(m_hListCtrl, LVM_GETITEMRECT, (WPARAM) (int) nItem, (LPARAM) (LPRECT) rcIcon);
CRect rcCol(rcBounds);
CRect rcWnd;
LVITEM stLVI;
char szBuf[255];
memset(szBuf, 0, sizeof(szBuf));
stLVI.iSubItem = 0;
stLVI.pszText = szBuf;
stLVI.cchTextMax = sizeof(szBuf);
SendMessage(m_hListCtrl, LVM_GETITEMTEXT, (WPARAM)(int)nItem, (LPARAM)(LPLVITEM)&stLVI);
//Label offset
CSize size;
GetTextExtentPoint32(m_hPr intDC, _T(" "), 1, &size);
int offset = size.cx;
CRect rcHighlight;
int nExt = 0;
GetTextExtentPoint32(m_hPr intDC, szBuf, sizeof(szBuf), &size);
nExt = size.cx + offset;
rcHighlight = rcLabel;
if(rcLabel.left + nExt < rcLabel.right)
rcHighlight.right = rcLabel.left + nExt;
SetBkColor(m_hPrintDC, ::GetSysColor(COLOR_WINDOW ));
//set clip region
int iColWidth = SendMessage(m_hListCtrl, LVM_GETCOLUMNWIDTH, (WPARAM)(int)0, 0);
rcCol.right = rcCol.left + iColWidth;
//Draw state icon
if(lvi.state & LVIS_STATEIMAGEMASK)
{
int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1;
himl = (HIMAGELIST)SendMessage(m_ hListCtrl, LVM_GETIMAGELIST,(WPARAM)L VSIL_STATE , 0);
int nImageCount = ImageList_GetImageCount(hi ml);
//offset the state image icon indent levels.
nExt = rcCol.left + lvi.iIndent*rcIcon.Width() ; //nExt reused
if(nImageCount > 0)
ImageList_Draw(himl, nImage, m_hPrintDC, stRect.left, stRect.top, ILD_TRANSPARENT);
}
//Draw Normal and overlay icon
himl = (HIMAGELIST)SendMessage(m_ hListCtrl, LVM_GETIMAGELIST,(WPARAM)L VSIL_SMALL , 0);
int nImageCount = ImageList_GetImageCount(hi ml);
if(nImageCount > 0)
{
UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK;
ImageList_Draw(himl, lvi.iImage, m_hPrintDC, (stRect.left + rcIcon.left), stRect.top, ILD_TRANSPARENT|nOvlImageM ask);
}
//if state image mask is on and indent is 0 then consider it as Server row
if((lvi.state & LVIS_STATEIMAGEMASK) && !lvi.iIndent)
{
rcLabel.right = rcBounds.right; //draw server name to full row width
}
//Draw item label
stRect.left = stRect.left + rcIcon.Width() + rcIcon.Width() + 16;
dtFlags |= DT_LEFT;
DrawText(m_hPrintDC, szBuf, strlen(szBuf), stRect, dtFlags);
RestoreDC(m_hPrintDC, nSaveDC);
return;
}
void CPrintListCtrl::Draw_Icons
{
HIMAGELIST himl;
UINT dtFlags = DT_SINGLELINE|DT_NOPREFIX|
int nSaveDC = SaveDC(m_hPrintDC);
CClientDC dcScreen(NULL);
SetMapMode(m_hPrintDC, MM_ANISOTROPIC);
// map 1 screen logical inch to 1 printer (/output) logical inch
CSize CalcSize;
SetWindowExtEx(m_hPrintDC,
dcScreen.GetDeviceCaps(LOG
SetViewportExtEx(m_hPrintD
GetDeviceCaps(m_hPrintDC, LOGPIXELSY), &CalcSize);
// get item data
LV_ITEM lvi;
lvi.mask = LVIF_IMAGE | LVIF_STATE | LVIF_INDENT;
lvi.iItem=nItem;
lvi.iSubItem=0;
lvi.stateMask=0xFFFF; // get all state flags
SendMessage(m_hListCtrl, LVM_GETITEM, (WPARAM)(int)0, (LPARAM)(LPLVITEM)&lvi);
//Get rectangles for painting
CRect rcBounds, rcLabel, rcIcon;
rcBounds.left = LVIR_BOUNDS;
rcLabel.left = LVIR_LABEL;
rcIcon.left = LVIR_ICON;
SendMessage(m_hListCtrl, LVM_GETITEMRECT, (WPARAM) (int) nItem, (LPARAM) (LPRECT) rcBounds);
SendMessage(m_hListCtrl, LVM_GETITEMRECT, (WPARAM) (int) nItem, (LPARAM) (LPRECT) rcLabel);
SendMessage(m_hListCtrl, LVM_GETITEMRECT, (WPARAM) (int) nItem, (LPARAM) (LPRECT) rcIcon);
CRect rcCol(rcBounds);
CRect rcWnd;
LVITEM stLVI;
char szBuf[255];
memset(szBuf, 0, sizeof(szBuf));
stLVI.iSubItem = 0;
stLVI.pszText = szBuf;
stLVI.cchTextMax = sizeof(szBuf);
SendMessage(m_hListCtrl, LVM_GETITEMTEXT, (WPARAM)(int)nItem, (LPARAM)(LPLVITEM)&stLVI);
//Label offset
CSize size;
GetTextExtentPoint32(m_hPr
int offset = size.cx;
CRect rcHighlight;
int nExt = 0;
GetTextExtentPoint32(m_hPr
nExt = size.cx + offset;
rcHighlight = rcLabel;
if(rcLabel.left + nExt < rcLabel.right)
rcHighlight.right = rcLabel.left + nExt;
SetBkColor(m_hPrintDC, ::GetSysColor(COLOR_WINDOW
//set clip region
int iColWidth = SendMessage(m_hListCtrl, LVM_GETCOLUMNWIDTH, (WPARAM)(int)0, 0);
rcCol.right = rcCol.left + iColWidth;
//Draw state icon
if(lvi.state & LVIS_STATEIMAGEMASK)
{
int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1;
himl = (HIMAGELIST)SendMessage(m_
int nImageCount = ImageList_GetImageCount(hi
//offset the state image icon indent levels.
nExt = rcCol.left + lvi.iIndent*rcIcon.Width()
if(nImageCount > 0)
ImageList_Draw(himl, nImage, m_hPrintDC, stRect.left, stRect.top, ILD_TRANSPARENT);
}
//Draw Normal and overlay icon
himl = (HIMAGELIST)SendMessage(m_
int nImageCount = ImageList_GetImageCount(hi
if(nImageCount > 0)
{
UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK;
ImageList_Draw(himl, lvi.iImage, m_hPrintDC, (stRect.left + rcIcon.left), stRect.top, ILD_TRANSPARENT|nOvlImageM
}
//if state image mask is on and indent is 0 then consider it as Server row
if((lvi.state & LVIS_STATEIMAGEMASK) && !lvi.iIndent)
{
rcLabel.right = rcBounds.right; //draw server name to full row width
}
//Draw item label
stRect.left = stRect.left + rcIcon.Width() + rcIcon.Width() + 16;
dtFlags |= DT_LEFT;
DrawText(m_hPrintDC, szBuf, strlen(szBuf), stRect, dtFlags);
RestoreDC(m_hPrintDC, nSaveDC);
return;
}
ASKER
Adjusted points from 50 to 55
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adjusted points from 55 to 85
ASKER
Edited text of question.
ASKER
Adjusted points from 85 to 90
ASKER
I found on codeguru sight where they convert the icon to a bitmap and then stretch the bitmap to the correct size to print it. This worked for me.
ASKER
This question has a deletion request Pending
ASKER
I didn't see sun307 but now that I am looking he has the right answer. how do i change this to give him the points.
Changing status of question.
darinw
Customer Service
darinw
Customer Service
This question no longer is pending deletion
Changing status of question.
darinw
Customer Service
darinw
Customer Service
ASKER