EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+

#Previous question #Index of VC++/WIN32/MFC Questions #Next question

Windows decides the foreground and background color of any window using current applied theme and color scheme. Windows programming does not provide any property to set the background color of any window widgets. But these are not rigid; programmer can alter these colors if needed. This is essential when programmer wants some control to have different color to highlight it before user or to give some notification to the user. This background property can be modified during handing specific window message called WM_CTLCOLORXXX. Windows sends WM_CTLCOLORXXX message just before drawing of the control. Thus Programmer can alter requited parameters while handing the message.

Message series number is WM_CTLCOLORXXX where XXX is the name of the call of the widget. Say for example for coloring EDIT box message is WM_CTLCOLOREDIT and thus for label/static window it will be WM_CTLCOLORSTATIC.

WM_CTLCOLORXXX : Windows sends these messages before drawing the control. HDC of the child window will be in wParam and HWND will be available in lParam. STATIC, BUTTON, EDIT, LIST, DLG, SCROLLBAR falls under these group. Followings are the name of individual messages.

  • WM_CTLCOLOREDIT (0x0133)
  • WM_CTLCOLORBTN (0x0135)
  • WM_CTLCOLORDLG (0x0136)
hdc = (HDC) wParam;   // handle to display context 
hwnd = (HWND) lParam; // handle to control window

Parameters -
hdc - Value of wParam. Handle to the device context for the control window.
hwnd - Value of lParam. Handle to the window control.

Return Values
If an application processes this message, it must return the handle of a brush. The system uses the brush to paint the background of the edit control.

Default Action
The DefWindowProc function selects the default system colors for the edit control.


    HDC hdcStatic = (HDC) wParam;
    SetTextColor(hdcStatic, RGB(0,0,255));
    SetBkColor(hdcStatic, RGB(250,250,0));
    return (INT_PTR)CreateSolidBrush(RGB(250,250,0));
    HDC hdcStatic = (HDC) wParam;
    SetTextColor(hdcStatic, RGB(0,0,255));
    SetBkColor(hdcStatic, RGB(0,230,0));
    return (INT_PTR)CreateSolidBrush(RGB(0,230,0));

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Sat 26 Apr/2014 22:37:42(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.


Your message goes here:

My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.