Click here to Skip to main content
15,922,015 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralVisual Studio .net offer Pin
CodeProjectSQ10-Apr-02 14:10
CodeProjectSQ10-Apr-02 14:10 
GeneralRe: Visual Studio .net offer Pin
CodeProjectSQ12-Apr-02 16:06
CodeProjectSQ12-Apr-02 16:06 
GeneralTab Contol on a dialog box Pin
10-Apr-02 13:07
suss10-Apr-02 13:07 
GeneralRe: Tab Contol on a dialog box Pin
Shog910-Apr-02 13:30
sitebuilderShog910-Apr-02 13:30 
Generalquick question on color Pin
jafrazee10-Apr-02 12:30
jafrazee10-Apr-02 12:30 
GeneralRe: quick question on color Pin
Shog910-Apr-02 12:43
sitebuilderShog910-Apr-02 12:43 
GeneralRe: quick question on color Pin
jafrazee10-Apr-02 14:00
jafrazee10-Apr-02 14:00 
GeneralRe: quick question on color Pin
Shog910-Apr-02 18:35
sitebuilderShog910-Apr-02 18:35 
jafrazee wrote:
no i am using setbkcolor()

Sorry, typo (yes i am too lazy to bother checking each post against MSDN before submitting Wink | ;) )

What you need to do is this (assume you've added a member to your class of type HBRUSH and named it m_hBrush, since you'll need to delete this when done with it):
HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
   int nCtrl = pWnd->GetDlgCtrlID();
   switch (nCtrl)
   {
      case IDC_BCOLOR:
         pDC->SetBkColor(RGB(m_red,m_green,m_blue));
         if ( NULL != m_hBrush )
            ::DeleteObject(m_hBrush);
         m_hBrush = ::CreateSolidBrush(RGB(m_red,m_green,m_blue));
         hbr = m_hBrush;
      break;
      /////////////////////plus more
   } 
   return hbr;
} 

Alternately, you could just keep a handle of a pre-created brush as a class member and return that.

Explanation:
The background color set using SetBkColor() applies to the text only, as you've noticed. In order to color the rest of the background, you need to return a brush of the appropriate color. This is what the code in bold does above. Windows does not delete the brush when it is done with it, so you must remember to do so after the window is destroyed (or before creating and returning a different brush, as shown).

Developers that like shiny objects also dig case mods and scratch-and-sniff stickers.

Klaus Probst, The Lounge


GeneralRe: quick question on color Pin
jafrazee11-Apr-02 0:42
jafrazee11-Apr-02 0:42 
GeneralRe: quick question on color Pin
Jeremy Falcon10-Apr-02 13:46
professionalJeremy Falcon10-Apr-02 13:46 
GeneralConversion from Integers to Character String Pin
pjb78910-Apr-02 11:41
pjb78910-Apr-02 11:41 
GeneralRe: Conversion from Integers to Character String Pin
Joaquín M López Muñoz10-Apr-02 11:56
Joaquín M López Muñoz10-Apr-02 11:56 
GeneralFinding if an app is running, not using FindWindow Pin
Atlantys10-Apr-02 10:46
Atlantys10-Apr-02 10:46 
GeneralRe: Finding if an app is running, not using FindWindow Pin
Joaquín M López Muñoz10-Apr-02 10:49
Joaquín M López Muñoz10-Apr-02 10:49 
GeneralRe: Finding if an app is running, not using FindWindow Pin
Atlantys10-Apr-02 11:12
Atlantys10-Apr-02 11:12 
GeneralRe: Finding if an app is running, not using FindWindow Pin
Joaquín M López Muñoz10-Apr-02 11:49
Joaquín M López Muñoz10-Apr-02 11:49 
GeneralProgrammatically setting IE's homepage (how?) Pin
Oz Ben Eliezer10-Apr-02 10:36
Oz Ben Eliezer10-Apr-02 10:36 
GeneralRe: Programmatically setting IE's homepage (how?) Pin
Joaquín M López Muñoz10-Apr-02 10:59
Joaquín M López Muñoz10-Apr-02 10:59 
GeneralRe: Programmatically setting IE's homepage (how?) Pin
Oz Ben Eliezer11-Apr-02 2:39
Oz Ben Eliezer11-Apr-02 2:39 
GeneralModeless dialogs and OnOK Pin
Derek Lakin10-Apr-02 10:15
Derek Lakin10-Apr-02 10:15 
GeneralRe: Modeless dialogs and OnOK Pin
Joaquín M López Muñoz10-Apr-02 10:15
Joaquín M López Muñoz10-Apr-02 10:15 
GeneralRe: Modeless dialogs and OnOK Pin
Derek Lakin10-Apr-02 10:25
Derek Lakin10-Apr-02 10:25 
GeneralRe: Modeless dialogs and OnOK Pin
Joaquín M López Muñoz10-Apr-02 10:29
Joaquín M López Muñoz10-Apr-02 10:29 
GeneralRe: Modeless dialogs and OnOK Pin
Derek Lakin10-Apr-02 10:33
Derek Lakin10-Apr-02 10:33 
GeneralRe: Modeless dialogs and OnOK Pin
Joaquín M López Muñoz10-Apr-02 10:36
Joaquín M López Muñoz10-Apr-02 10:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.