Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WM_CTLCOLOR problem

Posted on 2000-04-26
2
Medium Priority
?
1,035 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
2 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
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 36 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

Industry Leaders: 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. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

885 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