Solved

WM_CTLCOLOR problem

Posted on 2000-04-26
2
1,018 Views
Last Modified: 2013-11-20

i handle the WM_CTLCOLOR  message for a checkbox and a command button for changing colors. The  checkbox changes color but not the command button .why is it. the code is as follows

HBRUSH CKKDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
   if (pWnd->GetDlgCtrlID() == IDC_RADIO2)
   {
     
      pDC->SetTextColor(RGB(0, 111, 255));
      pDC->SetBkMode(TRANSPARENT);
      pDC->SetBkColor(RGB(111,11,89));
      hbr = m_brush;
   }//this works fine

   if (pWnd->GetDlgCtrlID() == IDC_BUTTON1)
   {
     
      pDC->SetTextColor(RGB(0, 111, 255));
      pDC->SetBkMode(TRANSPARENT);
      pDC->SetBkColor(RGB(111,11,89));
      hbr = m_brush;
   } // this does not respond in changing color

return hbr;
}
m_brush is declared as
COLORREF cr=RGB(127,127,127);
m_brush.CreateSolidBrush(cr);
0
Comment
Question by:karthik2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2753818
Hi,

I think for the command buttons, U have to make them ownerdrawn and handle the DrawItem() method to draw it.

VinExpert
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 12 total points
ID: 2754100
WM_CTLCOLOR does not work for buttons, nor for common controls.  It only wroks for a subset of the standard controls.

Common controls (like list views etc) have more control and more options for owner-drawing.

Standard controls that don't support WM_CTLCOLOR need to be owner-drawn.  Fortunately for buttons this is fairly easy.

Windows supplies DrawFrameControl to draw the button itself and DrawState to draw the guts (including icons, bitmaps and text).  Combine that with simply filling rectangles in the appropriate colour, and you're there.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question