Solved

WM_CTLCOLOR problem

Posted on 2000-04-26
2
997 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: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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 92
Expand data scrubbing tool 13 32
ORA-01403: no data found 43 101
Shell script to login to remote m/c and execute commands 10 78
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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