Solved

HBRBACKGROUND class member Question

Posted on 1997-09-12
5
977 Views
Last Modified: 2013-12-03
I would like my dialog box to display using a different background color for the buttons, static displays, dialog background (pretty much everything). In my WM_INITDIALOG, I'm calling SetClassLong with parms:

hwnd (dialog box hwnd),
GCL_HBRBACKGROUND,
HBRUSH (brush handle from successful CreateSolidBrush)

However, I receive error back. Why won't this work.

Alternatively, I can use WM_CTLCOLORBTN/DLG/EDIT/... and return my brush handle there. However, doing so works for DLG but BTN ignores me. Also, even if I got BTN to take my brush the borders around DLG and BTN are still colored according to system 3-D objects color. Therefore, I would like to get the first method to work instead.

Thanks for help!
0
Comment
Question by:elmo2
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1406715
Your first method would not be the preferrd way to go.  I don't think it works anyway if you you have 3D style dialogs.  Also it would only change background of the dialog not anything else (like frames and button etc).

The best and most flexible solution is WM_CTLCOLORxxx

However, as you said, this does NOT work for buttons (as you said).  You need to make owner drawn buttons and paint them yourself.  From the sounds of things, you want pretty much complete control over the appearance of your dialog, so that is probably the best way to go anyway.
 
0
 

Author Comment

by:elmo2
ID: 1406716
Hmm, but the border problem applies to everything in addition to buttons, including text frames, list box borders, dialog itself borders etc. etc. I can't ownerdraw everything and I'm sure there's gotta be a simple solution since SDK says that all controls derive their bg color from HBRBACKGROUND class style. If I change appearance color for 3-d objects in control panel, everything works how I would like (except for ALL programs using my color). I apreciate your time/help but I gotta hope for and hold out for a better solution (if there is one).

0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1406717
But borders do NOT derive their color from the HBRBACKGROUND brush - they come from the system colors for 3dhighlight , 3d shadow etc (ie. the ones in the control panel)  Changing the background brush will NOT do it.  The only way is to owner draw them.  This is because your app is using CTL3D32.DLL to do the drawing of controls (see your winapp for wher eit turns on 3D controls).

If you _weren't_ doing 3d controls, you'd be better off calling SetDialogBkColor instead - which also changes button faces. Or you could then change individual button faces with the OnCtlColor (which will work if you don't have 3D controls on).  But if you turn off 3D controls, they will not appear 3D - so if you want nice borders, you're back to owner drawn again.

I'm sorry - but changing HBRBACKGROUND won't do what you want anyway.  In any case, there is not much point persuing HBRBACKGROUND.

The only solution if you want 3D controls is to draw your own - either owner drawn or bitmap button (for buttons).  It is a pain, but if you want that much control over the drawing of control, then thats the path to take.

0
 

Author Comment

by:elmo2
ID: 1406718
Is there a winapi equivalent to SetDialogBkColor. I'm not using MFC and am unable to.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1406719
SetDialogBkColor just sets some values used by OnCtlColor - if you are not using MFC, just turn off 3D support and respond to the OnCtrlColor message

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

21 Experts available now in Live!

Get 1:1 Help Now