15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


OnCtlColor not behaving

Brad Wilson -- bradw@netnet.net
Sunday, January 14, 1996

Enviro: VC++ 4.0
        NT 3.51 (develop/run) & Win95 (run)
        App is marked /subsystem:windows,4.0
        Using CTL3D32.DLL under NT

I have a dialog box whose body is a bitmap (ie, I have created an owner
draw button and during OnInitDialog() I resize the dialog and the button
to fit the size of the bitmap).

On this dialog I also have two pushbuttons.

The body of the bitmap is gray (192,192,192) and I don't want it to change
from that.  I would like to automatically change the backgrounds of the
buttons from COLOR_3DFACE to (192,192,192) so that they match the bitmap.

I have placed the OnCtlColor() handler in my application, and it does
get called numerous times (once for each of the buttons, once for the
dialog itself, and one extra time for the owner draw button with
CTLCOLOR_MSGBOX, which I don't understand).

In OnCtlColor() I return a handle to a solid brush that I created
in the constructor of the dialog.  It would appear, however, that
the system is *not* using the brush I passed it, since the two regular
pushbuttons still come up with the COLOR_3DFACE color instead of the
color of my brush.

I have also tried (just to see if it worked) to return some of the
various brushes from GetStockObject() and none of them work either
(both NT and 95 refuse to use the brush I'm passing back no matter
where I get the brush from).

Because I was desperate, I even tried to select the brush into the
DC pointer that I got and that didn't work either.

Thinking CTL3D was my problem under NT, I disabled the line that
called Enable3dControls() and that didn't do anything either (other
than taking the 3D controls away).

Here is my OnCtlColor code:

  HBRUSH
  CAboutBoxBitmapDlg :: OnCtlColor
      (
      CDC* pDC,
      CWnd* pWnd,
      UINT nCtlColor
      )

      {
      if( nCtlColor == CTLCOLOR_BTN )
          {
          return (HBRUSH)( m_brushBackground.m_hObject );
          }
      else
          {
          return CDialog :: OnCtlColor( pDC, pWnd, nCtlColor );
         }
      }

In the constructor, I do:

      m_brushBackground.CreateSolidBrush( RGB( 192, 192, 192 ));

Anybody have any idea what's going on here?

--
class CBradWilson : public CWorldWatchProgrammingTeam {
  public:
    CString GetInetAddr()   { return CString("bradw@exptech.com");      }
    CString GetPhone()      { return CString("+1 (810) 620-9803");      }
    CString GetURL()        { return CString("http://www.exptech.com"); }
    CString GetDisclaimer() { return CString("All I say is fact :-p");  }
};

//  QOTW: "There is no right or wrong ... just popular opinion"




Kit Kauffmann -- kitk@mudshark.sunquest.com
Thursday, January 18, 1996

>Enviro: VC++ 4.0
>        NT 3.51 (develop/run) & Win95 (run)
>        App is marked /subsystem:windows,4.0
>        Using CTL3D32.DLL under NT
>
>I have a dialog box whose body is a bitmap (ie, I have created an owner
>draw button and during OnInitDialog() I resize the dialog and the button
>to fit the size of the bitmap).
>
>On this dialog I also have two pushbuttons.
>
>The body of the bitmap is gray (192,192,192) and I don't want it to change
>from that.  I would like to automatically change the backgrounds of the
>buttons from COLOR_3DFACE to (192,192,192) so that they match the bitmap.
>
>I have placed the OnCtlColor() handler in my application, and it does
>get called numerous times (once for each of the buttons, once for the
>dialog itself, and one extra time for the owner draw button with
>CTLCOLOR_MSGBOX, which I don't understand).
>
>In OnCtlColor() I return a handle to a solid brush that I created
>in the constructor of the dialog.  It would appear, however, that
>the system is *not* using the brush I passed it, since the two regular
>pushbuttons still come up with the COLOR_3DFACE color instead of the
>color of my brush.
>
>I have also tried (just to see if it worked) to return some of the
>various brushes from GetStockObject() and none of them work either
>(both NT and 95 refuse to use the brush I'm passing back no matter
>where I get the brush from).
>
>Because I was desperate, I even tried to select the brush into the
>DC pointer that I got and that didn't work either.
>
>Thinking CTL3D was my problem under NT, I disabled the line that
>called Enable3dControls() and that didn't do anything either (other
>than taking the 3D controls away).
>
>Here is my OnCtlColor code:
>
>  HBRUSH
>  CAboutBoxBitmapDlg :: OnCtlColor
>      (
>      CDC* pDC,
>      CWnd* pWnd,
>      UINT nCtlColor
>      )
>
>      {
>      if( nCtlColor == CTLCOLOR_BTN )
>          {
>          return (HBRUSH)( m_brushBackground.m_hObject );
>          }
>      else
>          {
>          return CDialog :: OnCtlColor( pDC, pWnd, nCtlColor );
>         }
>      }
>
>In the constructor, I do:
>
>      m_brushBackground.CreateSolidBrush( RGB( 192, 192, 192 ));
>
>Anybody have any idea what's going on here?
>
>--
>class CBradWilson : public CWorldWatchProgrammingTeam {
>  public:
>    CString GetInetAddr()   { return CString("bradw@exptech.com");      }
>    CString GetPhone()      { return CString("+1 (810) 620-9803");      }
>    CString GetURL()        { return CString("http://www.exptech.com"); }
>    CString GetDisclaimer() { return CString("All I say is fact :-p");  }
>};
>
>//  QOTW: "There is no right or wrong ... just popular opinion"
>
>

Havne't tried this, but 'netlore has it that you still don't have complete 
OnCtlColor for non-owner-draw buttons, even with the 32-bit OS's :(

I think I saw an article on MSDN that mentioned what you can & can't do...







| Вернуться в корень Архива |