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. Owner-drawn CListBox-derived background color question

Owner-drawn CListBox-derived background color question

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebugginghelp
3 Posts 3 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.
  • I Offline
    I Offline
    Indrawati
    wrote on last edited by
    #1

    Hi I am creating a class derived from CListBox so I can control the fonts, color, etc2. I also want to control the background color of the listbox (not the text's background color, but the whole listbox' background color), and I am doing it by handling WM_ERASEBKGND message in OnEraseBkgnd() function. The OnEraseBkgnd() implementation is very simple, basically I just obtain the client rect and the use CDC::FillSolidRect to fill it with the background color of my choice. The problem is, the background color is correctly drawn if there is at least one item in the listbox, but when the listbox is empty, the background color is always displayed as white, even though I have stepped in the debugger and make sure that the FillSolidRect function is executed. Could someone tell me what the possible cause for this is? Thanks!

    M A 2 Replies Last reply
    0
    • I Indrawati

      Hi I am creating a class derived from CListBox so I can control the fonts, color, etc2. I also want to control the background color of the listbox (not the text's background color, but the whole listbox' background color), and I am doing it by handling WM_ERASEBKGND message in OnEraseBkgnd() function. The OnEraseBkgnd() implementation is very simple, basically I just obtain the client rect and the use CDC::FillSolidRect to fill it with the background color of my choice. The problem is, the background color is correctly drawn if there is at least one item in the listbox, but when the listbox is empty, the background color is always displayed as white, even though I have stepped in the debugger and make sure that the FillSolidRect function is executed. Could someone tell me what the possible cause for this is? Thanks!

      M Offline
      M Offline
      Mad__
      wrote on last edited by
      #2

      Hi this is from MSDN : The **WM_CTLCOLORLISTBOX** message is sent to the parent window of a list box before the system draws the list box. By responding to this message, the parent window can set the text and background colors of the list box by using the specified display device context handle.

      1 Reply Last reply
      0
      • I Indrawati

        Hi I am creating a class derived from CListBox so I can control the fonts, color, etc2. I also want to control the background color of the listbox (not the text's background color, but the whole listbox' background color), and I am doing it by handling WM_ERASEBKGND message in OnEraseBkgnd() function. The OnEraseBkgnd() implementation is very simple, basically I just obtain the client rect and the use CDC::FillSolidRect to fill it with the background color of my choice. The problem is, the background color is correctly drawn if there is at least one item in the listbox, but when the listbox is empty, the background color is always displayed as white, even though I have stepped in the debugger and make sure that the FillSolidRect function is executed. Could someone tell me what the possible cause for this is? Thanks!

        A Offline
        A Offline
        Antony M Kancidrowski
        wrote on last edited by
        #3

        Are you calling the base class OnEraseBkgnd() ? Ant. I'm hard, yet soft.
        I'm coloured, yet clear.
        I'm fruity and sweet.
        I'm jelly, what am I? Muse on it further, I shall return!
        - David Williams (Little Britain)

        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