Solved

WM_CTLCOLOR problem

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now