Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What does (need to clear the background) mean?

What does (need to clear the background) mean?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncomtutoriallounge
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JoneLe86
    wrote on last edited by
    #1

    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?

    D J L 3 Replies Last reply
    0
    • J JoneLe86

      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?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • D David Crow

        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

        J Offline
        J Offline
        JoneLe86
        wrote on last edited by
        #3

        cuz I am coloring those buffers?!

        D 1 Reply Last reply
        0
        • J JoneLe86

          cuz I am coloring those buffers?!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Fair enough, but you can still use SetWindowText() (elsewhere, not in response to NM_CUSTOMDRAW) rather than DrawText() 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

          J 1 Reply Last reply
          0
          • D David Crow

            Fair enough, but you can still use SetWindowText() (elsewhere, not in response to NM_CUSTOMDRAW) rather than DrawText() 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

            J Offline
            J Offline
            JoneLe86
            wrote on last edited by
            #5

            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.....

            D 1 Reply Last reply
            0
            • J JoneLe86

              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.....

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • J JoneLe86

                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?

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                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);

                J 1 Reply Last reply
                0
                • J JoneLe86

                  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?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I have not tried using direct drawing code such as you do, but maybe this MSDN sample[^] will help.

                  Use the best guess

                  1 Reply Last reply
                  0
                  • J Jochen Arndt

                    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);

                    J Offline
                    J Offline
                    JoneLe86
                    wrote on last edited by
                    #9

                    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..

                    J 1 Reply Last reply
                    0
                    • J JoneLe86

                      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..

                      J Offline
                      J Offline
                      Jochen Arndt
                      wrote on last edited by
                      #10

                      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 by CListView::GetBkColor() or any other you are specifying (e.g. a row specific color). You may of course use ExtTextOut() to print the cell text parts with different colors when adjusting the rect. When using CListView::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.

                      J 1 Reply Last reply
                      0
                      • J Jochen Arndt

                        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 by CListView::GetBkColor() or any other you are specifying (e.g. a row specific color). You may of course use ExtTextOut() to print the cell text parts with different colors when adjusting the rect. When using CListView::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.

                        J Offline
                        J Offline
                        JoneLe86
                        wrote on last edited by
                        #11

                        OMG man (After all that Time) I finally got what I am looking for thanks so much.. those info helped me a lot :thumbsup::thumbsup::thumbsup::thumbsup::thumbsup:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups