Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to use WM_CTLCOLORLISTBOX

doofusboydoofusboy Posts: 256Member
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.


Anyone have an idea how I can use this message to subclass a listbox to change the color of the text in the listbox?

Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : 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.
    :
    :
    : Anyone have an idea how I can use this message to subclass a listbox to change the color of the text in the listbox?
    :

    Isn't there a VB way to do this?!

    Anyway, you'll have to Subclass the Form, meaning you'll make it impossible to debug. EXCEPT for when you use VB.NET where you can install a message loop without 'hacking'.

    Have you ever subclassed a form before? It's pretty much to explain, so I'd advise you search google for something like "VB Subclassing Form". The first match already showed a subclassing example...

    Greets...
    Richard

  • doofusboydoofusboy Posts: 256Member
    : : 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.
    : :
    : :
    : : Anyone have an idea how I can use this message to subclass a listbox to change the color of the text in the listbox?
    : :
    :
    : Isn't there a VB way to do this?!
    :
    : Anyway, you'll have to Subclass the Form, meaning you'll make it impossible to debug. EXCEPT for when you use VB.NET where you can install a message loop without 'hacking'.
    :
    : Have you ever subclassed a form before? It's pretty much to explain, so I'd advise you search google for something like "VB Subclassing Form". The first match already showed a subclassing example...
    :
    : Greets...
    : Richard
    :
    :
    Thanks for responding......I'm trying to teach myself subclassing, but can't figure out how to use WM_CTLCOLORLISTBOX message.

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : : : 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.
    : : :
    : : :
    : : : Anyone have an idea how I can use this message to subclass a listbox to change the color of the text in the listbox?
    : : :
    : :
    : : Isn't there a VB way to do this?!
    : :
    : : Anyway, you'll have to Subclass the Form, meaning you'll make it impossible to debug. EXCEPT for when you use VB.NET where you can install a message loop without 'hacking'.
    : :
    : : Have you ever subclassed a form before? It's pretty much to explain, so I'd advise you search google for something like "VB Subclassing Form". The first match already showed a subclassing example...
    : :
    : : Greets...
    : : Richard
    : :
    : :
    : Thanks for responding......I'm trying to teach myself subclassing, but can't figure out how to use WM_CTLCOLORLISTBOX message.
    :
    :

    Just check if the message is WM_CTLCOLORLISTBOX. Look up what needs to be done to handle this message in MSDN.

    Greets...
    Richard

  • doofusboydoofusboy Posts: 256Member
    : : : : 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.
    : : : :
    : : : :
    : : : : Anyone have an idea how I can use this message to subclass a listbox to change the color of the text in the listbox?
    : : : :
    : : :
    : : : Isn't there a VB way to do this?!
    : : :
    : : : Anyway, you'll have to Subclass the Form, meaning you'll make it impossible to debug. EXCEPT for when you use VB.NET where you can install a message loop without 'hacking'.
    : : :
    : : : Have you ever subclassed a form before? It's pretty much to explain, so I'd advise you search google for something like "VB Subclassing Form". The first match already showed a subclassing example...
    : : :
    : : : Greets...
    : : : Richard
    : : :
    : : :
    : : Thanks for responding......I'm trying to teach myself subclassing, but can't figure out how to use WM_CTLCOLORLISTBOX message.
    : :
    : :
    :
    : Just check if the message is WM_CTLCOLORLISTBOX. Look up what needs to be done to handle this message in MSDN.
    :
    : Greets...
    : Richard
    :
    :
    Actually, what I originally posted CAME from MSDN and wasn't thoroughly explained, which is why I came here.
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    [b][red]This message was edited by BitByBit_Thor at 2005-9-1 13:14:3[/red][/b][hr]
    : :
    : Actually, what I originally posted CAME from MSDN and wasn't thoroughly explained, which is why I came here.
    :

    You mean the first post?

    Hmmm... let me check MSDN.

    Basically, you have to use the GDI Draw functions on the ListBox. Also, you should return a brush... It's all there. Good luck finding out what functions to use (I think you need to either change the Pen or the Brush).

    EDIT: But why in heavens name do so difficult? Just change the ForeColor property of the ListBox...

    Greets...
    Richard
  • doofusboydoofusboy Posts: 256Member
    : [b][red]This message was edited by BitByBit_Thor at 2005-9-1 13:14:3[/red][/b][hr]
    : : :
    : : Actually, what I originally posted CAME from MSDN and wasn't thoroughly explained, which is why I came here.
    : :
    :
    : You mean the first post?
    :
    : Hmmm... let me check MSDN.
    :
    : Basically, you have to use the GDI Draw functions on the ListBox. Also, you should return a brush... It's all there. Good luck finding out what functions to use (I think you need to either change the Pen or the Brush).
    :
    : EDIT: But why in heavens name do so difficult? Just change the ForeColor property of the ListBox...
    :
    : Greets...
    : Richard
    :
    I understand that the easiest way is to change the ForeColor property, but that is not my objective. I'm trying to teach myself subclassing and just can't seem to grasp how to code that particular Windows message and the MSDN explanation was not clear to me.
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I understand that the easiest way is to change the ForeColor property, but that is not my objective. I'm trying to teach myself subclassing and just can't seem to grasp how to code that particular Windows message and the MSDN explanation was not clear to me.
    :

    I was beginning to suspect such.
    Anyway, is the explanation clear to you now, or not?

    Greets...
    Richard

  • doofusboydoofusboy Posts: 256Member
    : : I understand that the easiest way is to change the ForeColor property, but that is not my objective. I'm trying to teach myself subclassing and just can't seem to grasp how to code that particular Windows message and the MSDN explanation was not clear to me.
    : :
    :
    : I was beginning to suspect such.
    : Anyway, is the explanation clear to you now, or not?
    :
    : Greets...
    : Richard
    :
    :
    No sir, still no clear....I'm just not getting it.
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member

    : No sir, still no clear....I'm just not getting it.
    :

    Perhaps you need to look into the GDI objects first. I do not know much about it, so I can't help you with it.

    [code]
    wParam
    Handle to the device context for the list box.
    lParam
    Handle to the list box.
    [/code]
    wParam holds the DC (often named hDC in API's). It's like the 'graphics handle' of the Listbox. You pass this handle to GDI functions so that the functions know where to draw on. Also, the DC 'object' holds a lot of information on how things are drawn.

    lParam is the handle to the listbox. This is the same value as ListBox1.Handle (or .hWnd?).

    [code]
    If an application processes this message, it must return a handle to a
    brush. The system uses the brush to paint the background of the list
    box.
    [/code]
    I guess the brush is used to set the background color.

    Also note what is said at remarks:
    [code]
    The system does not automatically destroy the returned brush.
    It is the application's responsibility to destroy the brush when
    it is no longer needed.
    [/code]
    Meaning you'll probably want to make the brush a global object in your application that you intialize when the app starts and you destroy when the app shuts down.

    Now as to set the ForeColor, I guess you need to use the appropriate GDI functions on the DC object to change the font color.

    Good luck, and if you need any help, you know where to find it ;-)

    Greets...
    Richard

Sign In or Register to comment.