Solved

WM_CTLCOLOR problem

Posted on 2000-04-26
2
1,024 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 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