What does (need to clear the background) mean?
-
here is the question I did ask before: I have a listview REPORT with fullrowselect style everything works fine, but after i used customdraw I faced a problem such pic included, it seems I click on the item col 3 it becomes bold and more bold.. Picture[^] if i use listview_update the bold text from the col 3 will be gone so why happens? and i just want to click on the raw without having that bold problem? any ideas? The Code
if (lpNMHdr->code == NM_CUSTOMDRAW)
{
LPNMLVCUSTOMDRAW lpCD = (LPNMLVCUSTOMDRAW)lpNMHdr;
if (lpCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
return CDRF_NOTIFYITEMDRAW;
}if (lpCD->nmcd.dwDrawStage == CDDS\_ITEMPREPAINT) { return CDRF\_NOTIFYSUBITEMDRAW; } if (lpCD->nmcd.dwDrawStage == (CDDS\_ITEMPREPAINT|CDDS\_SUBITEM)) { if (lpCD->iSubItem == 0) //detect which subitem is being drawn { LPCTSTR lpcszBuf1 = \_T("example"); LPCTSTR lpcszBuf2 = \_T("text"); RECT iR = { 0 }; ListView\_GetSubItemRect(lpCD->nmcd.hdr.hwndFrom, lpCD->nmcd.dwItemSpec, lpCD->iSubItem, LVIR\_BOUNDS, &iR); SetBkMode(lpCD->nmcd.hdc, TRANSPARENT); SIZE sz = { 0 }; GetTextExtentPoint32(lpCD->nmcd.hdc, lpcszBuf1, 7, &sz); SetTextColor(lpCD->nmcd.hdc, RGB(255, 0, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf1, -1, &iR, DT\_LEFT); iR.left += sz.cx; SetTextColor(lpCD->nmcd.hdc, RGB(0, 255, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf2, -1, &iR, DT\_LEFT); return CDRF\_SKIPDEFAULT; } }
So someone answered me: If you draw it yourself you need to clear the background as well, which you are not doing. Try using OPAQUE instead of TRANSPARENT. However, I used OPAQUE but it does not help a lot so, I am trying now with clear the background: the message is wm_ERASEBACKGROUND but what I suppose to do? should I add the code there or what?
-
here is the question I did ask before: I have a listview REPORT with fullrowselect style everything works fine, but after i used customdraw I faced a problem such pic included, it seems I click on the item col 3 it becomes bold and more bold.. Picture[^] if i use listview_update the bold text from the col 3 will be gone so why happens? and i just want to click on the raw without having that bold problem? any ideas? The Code
if (lpNMHdr->code == NM_CUSTOMDRAW)
{
LPNMLVCUSTOMDRAW lpCD = (LPNMLVCUSTOMDRAW)lpNMHdr;
if (lpCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
return CDRF_NOTIFYITEMDRAW;
}if (lpCD->nmcd.dwDrawStage == CDDS\_ITEMPREPAINT) { return CDRF\_NOTIFYSUBITEMDRAW; } if (lpCD->nmcd.dwDrawStage == (CDDS\_ITEMPREPAINT|CDDS\_SUBITEM)) { if (lpCD->iSubItem == 0) //detect which subitem is being drawn { LPCTSTR lpcszBuf1 = \_T("example"); LPCTSTR lpcszBuf2 = \_T("text"); RECT iR = { 0 }; ListView\_GetSubItemRect(lpCD->nmcd.hdr.hwndFrom, lpCD->nmcd.dwItemSpec, lpCD->iSubItem, LVIR\_BOUNDS, &iR); SetBkMode(lpCD->nmcd.hdc, TRANSPARENT); SIZE sz = { 0 }; GetTextExtentPoint32(lpCD->nmcd.hdc, lpcszBuf1, 7, &sz); SetTextColor(lpCD->nmcd.hdc, RGB(255, 0, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf1, -1, &iR, DT\_LEFT); iR.left += sz.cx; SetTextColor(lpCD->nmcd.hdc, RGB(0, 255, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf2, -1, &iR, DT\_LEFT); return CDRF\_SKIPDEFAULT; } }
So someone answered me: If you draw it yourself you need to clear the background as well, which you are not doing. Try using OPAQUE instead of TRANSPARENT. However, I used OPAQUE but it does not help a lot so, I am trying now with clear the background: the message is wm_ERASEBACKGROUND but what I suppose to do? should I add the code there or what?
Just out of curiosity, why are you drawing the text yourself rather than using
SetWindowText()
?JoneLe86 wrote:
I click on the item col 3 it becomes bold and more bold..
I think either your X or Y coordinate is changing by 1 pixel each time. Without actually testing, that's just a guess, though.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Just out of curiosity, why are you drawing the text yourself rather than using
SetWindowText()
?JoneLe86 wrote:
I click on the item col 3 it becomes bold and more bold..
I think either your X or Y coordinate is changing by 1 pixel each time. Without actually testing, that's just a guess, though.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Fair enough, but you can still use
SetWindowText()
(elsewhere, not in response toNM_CUSTOMDRAW
) rather thanDrawText()
for that."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Fair enough, but you can still use
SetWindowText()
(elsewhere, not in response toNM_CUSTOMDRAW
) rather thanDrawText()
for that."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
thanks for this info... do you know what I should do? i still do get what i want, the more i click on them the more bold the become.....
JoneLe86 wrote:
do you know what I should do? i still do get what i want, the more i click on them the more bold the become.....
Check the X and Y coordinates to make sure they are the same each time your message handler is called.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
here is the question I did ask before: I have a listview REPORT with fullrowselect style everything works fine, but after i used customdraw I faced a problem such pic included, it seems I click on the item col 3 it becomes bold and more bold.. Picture[^] if i use listview_update the bold text from the col 3 will be gone so why happens? and i just want to click on the raw without having that bold problem? any ideas? The Code
if (lpNMHdr->code == NM_CUSTOMDRAW)
{
LPNMLVCUSTOMDRAW lpCD = (LPNMLVCUSTOMDRAW)lpNMHdr;
if (lpCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
return CDRF_NOTIFYITEMDRAW;
}if (lpCD->nmcd.dwDrawStage == CDDS\_ITEMPREPAINT) { return CDRF\_NOTIFYSUBITEMDRAW; } if (lpCD->nmcd.dwDrawStage == (CDDS\_ITEMPREPAINT|CDDS\_SUBITEM)) { if (lpCD->iSubItem == 0) //detect which subitem is being drawn { LPCTSTR lpcszBuf1 = \_T("example"); LPCTSTR lpcszBuf2 = \_T("text"); RECT iR = { 0 }; ListView\_GetSubItemRect(lpCD->nmcd.hdr.hwndFrom, lpCD->nmcd.dwItemSpec, lpCD->iSubItem, LVIR\_BOUNDS, &iR); SetBkMode(lpCD->nmcd.hdc, TRANSPARENT); SIZE sz = { 0 }; GetTextExtentPoint32(lpCD->nmcd.hdc, lpcszBuf1, 7, &sz); SetTextColor(lpCD->nmcd.hdc, RGB(255, 0, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf1, -1, &iR, DT\_LEFT); iR.left += sz.cx; SetTextColor(lpCD->nmcd.hdc, RGB(0, 255, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf2, -1, &iR, DT\_LEFT); return CDRF\_SKIPDEFAULT; } }
So someone answered me: If you draw it yourself you need to clear the background as well, which you are not doing. Try using OPAQUE instead of TRANSPARENT. However, I used OPAQUE but it does not help a lot so, I am trying now with clear the background: the message is wm_ERASEBACKGROUND but what I suppose to do? should I add the code there or what?
You must fill the cell rect with the background color before drawing the text. The CDC class provides the
FillSolidRect()
function which can be used to do this. When using DC handles, you can do it the same way as the CDC class:::SetBkColor(lpCD->nmcd.hdc, GetBkColor());
::ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, NULL, 0, NULL); -
here is the question I did ask before: I have a listview REPORT with fullrowselect style everything works fine, but after i used customdraw I faced a problem such pic included, it seems I click on the item col 3 it becomes bold and more bold.. Picture[^] if i use listview_update the bold text from the col 3 will be gone so why happens? and i just want to click on the raw without having that bold problem? any ideas? The Code
if (lpNMHdr->code == NM_CUSTOMDRAW)
{
LPNMLVCUSTOMDRAW lpCD = (LPNMLVCUSTOMDRAW)lpNMHdr;
if (lpCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
return CDRF_NOTIFYITEMDRAW;
}if (lpCD->nmcd.dwDrawStage == CDDS\_ITEMPREPAINT) { return CDRF\_NOTIFYSUBITEMDRAW; } if (lpCD->nmcd.dwDrawStage == (CDDS\_ITEMPREPAINT|CDDS\_SUBITEM)) { if (lpCD->iSubItem == 0) //detect which subitem is being drawn { LPCTSTR lpcszBuf1 = \_T("example"); LPCTSTR lpcszBuf2 = \_T("text"); RECT iR = { 0 }; ListView\_GetSubItemRect(lpCD->nmcd.hdr.hwndFrom, lpCD->nmcd.dwItemSpec, lpCD->iSubItem, LVIR\_BOUNDS, &iR); SetBkMode(lpCD->nmcd.hdc, TRANSPARENT); SIZE sz = { 0 }; GetTextExtentPoint32(lpCD->nmcd.hdc, lpcszBuf1, 7, &sz); SetTextColor(lpCD->nmcd.hdc, RGB(255, 0, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf1, -1, &iR, DT\_LEFT); iR.left += sz.cx; SetTextColor(lpCD->nmcd.hdc, RGB(0, 255, 0)); DrawText(lpCD->nmcd.hdc, lpcszBuf2, -1, &iR, DT\_LEFT); return CDRF\_SKIPDEFAULT; } }
So someone answered me: If you draw it yourself you need to clear the background as well, which you are not doing. Try using OPAQUE instead of TRANSPARENT. However, I used OPAQUE but it does not help a lot so, I am trying now with clear the background: the message is wm_ERASEBACKGROUND but what I suppose to do? should I add the code there or what?
-
You must fill the cell rect with the background color before drawing the text. The CDC class provides the
FillSolidRect()
function which can be used to do this. When using DC handles, you can do it the same way as the CDC class:::SetBkColor(lpCD->nmcd.hdc, GetBkColor());
::ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, NULL, 0, NULL);Thanks for this info.. You must fill the cell rect with the background color before drawing the text. SetBkColor(lpCD->nmcd.hdc, GetBkColor()); ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, NULL, 0, NULL); but may function looks like this fillrect(); //i am using this to fill out the specific rect settextcolor(); //then I set the text color Drawtext() //then I draw the text (1) if use ExtTextOut then there is no need to drawtext? ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, Buffer, strlen(Buffer), NULL); (2) i used SetBkColor(lpCD->nmcd.hdc, GetBkColor(..)); nothing happened, i do not set a bk color in my listview, i did set a row color manually... so If I do SetBkColor(lpCD->nmcd.hdc, RGB(255,0,0)); the whole list bk changed to red? maybe the method i use is wrong..
-
Thanks for this info.. You must fill the cell rect with the background color before drawing the text. SetBkColor(lpCD->nmcd.hdc, GetBkColor()); ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, NULL, 0, NULL); but may function looks like this fillrect(); //i am using this to fill out the specific rect settextcolor(); //then I set the text color Drawtext() //then I draw the text (1) if use ExtTextOut then there is no need to drawtext? ExtTextOut(lpCD->nmcd.hdc, 0, 0, ETO_OPAQUE, &iR, Buffer, strlen(Buffer), NULL); (2) i used SetBkColor(lpCD->nmcd.hdc, GetBkColor(..)); nothing happened, i do not set a bk color in my listview, i did set a row color manually... so If I do SetBkColor(lpCD->nmcd.hdc, RGB(255,0,0)); the whole list bk changed to red? maybe the method i use is wrong..
My example code is those used by
CDC::FillSolidRect()
. It will erase the cell using the actual background color of the HDC which can be set to the default returned byCListView::GetBkColor()
or any other you are specifying (e.g. a row specific color). You may of course useExtTextOut()
to print the cell text parts with different colors when adjusting the rect. When usingCListView::SetBkColor()
this will set the default color for the list. When calling::SetBkColor(HDC)
, this specifies the color for the drawing functions using the HDC. If you change the background color (or the text color) of the HDC, you should restore it to the original value that is returned by the first set call. Restoring the colors may be omitted when all cells are owner drawn. -
My example code is those used by
CDC::FillSolidRect()
. It will erase the cell using the actual background color of the HDC which can be set to the default returned byCListView::GetBkColor()
or any other you are specifying (e.g. a row specific color). You may of course useExtTextOut()
to print the cell text parts with different colors when adjusting the rect. When usingCListView::SetBkColor()
this will set the default color for the list. When calling::SetBkColor(HDC)
, this specifies the color for the drawing functions using the HDC. If you change the background color (or the text color) of the HDC, you should restore it to the original value that is returned by the first set call. Restoring the colors may be omitted when all cells are owner drawn.