for controls other than buttons, you could handle the WM_CTLCOLORXXX notification; eg. WM_CTLCOLOREDIT for an edit control.
for buttons, the button needs to be an owner-drawn button; for such a button the system sends the parent window a WM_DRAWITEM message.
see: http://msdn2.microsoft.com/en-us/library/ms673346.aspx
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
BUT the text in the edit control had a different background colour.
The wparam of the message is a handle to the device context; you can use SetTextColor, SetBkMode, SetTextAlign etc. ion it.
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
Yes but how would one set each of these on one specific control?
for the WM_CTLCLREDIT message,
wparam - handle to the device context for the edit control window (HDC)
lparam - handle to the edit control (HWND)
if you want to make the decision based on the HWND, this is all that is required; if you want to do the same based on control id:
// ...
case WM_CTLCOLOREDIT:
{
HDC dc = HDC(wparam) ;
HWND edit_window = HWND(lparam) ;
int edit_control_id = GetDlgCtrlID(edit_window) ;
switch(edit_control_id)
{
// ...
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
...I need the full background of the test control to be black and the text of the edit control to be white, how could I do this?
what are are you returning? you need to return a handle to the brush with which the control background would be painted. eg. for a black background:return LRESULT( GetStockObject( BLACK_BRUSH ) ) ;
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
you could write a handler for the EN_UPDATE notification sent by the edit control and force a repaint by InvalidateRect/UpdateWindow.
rich edit controls do not send CTLCOLOR messages; however you can set its background colour by sending it a EM_SETBKGNDCOLOR message.
i've not used WC_IPADDRESS (i've not written any gui code for several years now), but i think it is just an edit control with special formatting/validation. so my guess is that you should be able to treat it like an edit control.
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
normally the best online reference is msdn. the ip address control reference is at http://msdn2.microsoft.com/en-us/library/ms671454.aspx
i looked around msdn a bit; but did not see any info on custom colouring this control.
by spying on the ip address control window, it turns out that it has four child windows (each of them an edit control). i suppose that was to be expected. so we could colour the edit controls using the normal WM_CTLCOLOREDIT mechanism. you would need to subclass the ip address control. and in the subclassed window procedure, handle the WM_CTLCOLOREDIT yourself. pass everything else for default handling ( by a return CallWindowProc(....) )
see http://msdn2.microsoft.com/en-us/library/ms633569.aspx#instance_subclassing
on how to subclass a window instance
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287