[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HBRBACKGROUND class member Question

Posted on 1997-09-12
5
Medium Priority
?
1,065 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 400 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

834 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