In Win32, how can the colour of STATIC text be changed?

前端 未结 2 820
南旧
南旧 2021-01-21 23:12

I have some static text on a window which is black, and I would like to change it at runtime using a Colour Chooser dialog. I have successfully obtained the colour, now I just n

相关标签:
2条回答
  • 2021-01-21 23:48

    You're on the right track with WM_CTLCOLORSTATIC. If you want to change the color, then invalidate the control (probably by using RedrawWindow). That will cause it to be repainted. When it's repainted, your WM_CTLCOLORSTATIC handler will be invoked again.

    0 讨论(0)
  • 2021-01-21 23:55

    A few suggestions:

    • Are you aware that it's the parent dialog that receives WM_CTLCOLORSTATIC, not the control itself?

    • The return (BOOL)... looks weird - in which function does this code live? You should be returning an LRESULT from your window proc.

    • You're leaking a brush every time - you should maintain a single brush and return that brush each time. Windows doesn't clean up the brush.

    0 讨论(0)
提交回复
热议问题