Capturing and modifying the WM_CTLCOLORBTN

I would like to change the default color of the buttons in my Delphi app.  I know that I can call the SetSysColor and GetSysColor, however, I only want to modify my app.  I was thinking that I could capture the WM_CTLCOLORBTN or the COLOR_BTNFACE somehow and modify only the window and child windows of the app.  I would like to do this for both buttons and scroll bars. I am using Delphi 7 Pro.

Thanks,
Derrick
dbettsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Slick812Commented:
hello dbetts, , the WM_CTLCOLORBTN has NO effect on a standard TButton, but it may have an effect on an Owner Draw button, like a TBitBtn,  It may change the text color, but it does not change the background color, you may be better off if you go to a component web site like Torry and just  download a "Color Button" component, thses many many of them, but you can also do it in code, scroll bars are a different story, and I do not see how you group them together
dbettsAuthor Commented:
Good thought, however, I am using a component from TMS (TMSGridPack) which is pretty good, however, it doesn't allow me to change the background clolor of the buttons, nor does it allow me to change the color of the scroll bars.  The needs I have basically require me to continue using the TMS components, so I was hoping for a way to change the way my app drew the buttons and scrollbars in the TMS components by trapping a windows message and returning the components with my desired color.  Currently, the windows system colors are being used and they often clash with the other colors and etc. I am using in the Application.

Thanks for your input.
Slick812Commented:
I know Nothing about the TMSGridPack, so I can only generalize about some TButton stuff, However this TMSGridPack may not be derived from a TButton? ? Any way, The windows system is Very reluctant to change ANY drawing aspect of a BUTTON Class, you can change the Font on it but not much else, however these is an Owner Draw option for a BUTTON class, which allows you to draw absolutely ANYTHING you want on the button. . . If you are stuck using this TMSGridPack, then you should contack the makers of this component and ask them about it. . . but it is unlikely that it can be done, if it is Not in it's methods already. . .
as to scroll bars, this is a different thing, unrelated to buttons, I do not think that there are Owner draw Scroll bars, but there is a
WM_CTLCOLORSCROLLBAR message that can change the Shaft color, but NOT the scroll and up and down buttons, besides in win XP these are colored by the XP theme anyway. . . You may not get much help for doing what you say you want to do. . . I seem to be the only one to comment here
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

dbettsAuthor Commented:
I appreciate your time.  This is what I have so far.  I AM capturing the message that is sent when the button is drawn:


protected
    procedure CatchtIt(var Msg: TMessage); message WM_CTLCOLORBTN;
...
...

procedure TForm1.CatchtIt(var Msg: TMessage);
begin
  SetBkColor(Msg.WParam, RGB(0,0,220));   //These parts aren't doing anything for me.  NO CHANGES
  SetTextColor(Msg.WParam, RGB(0,0,220));//These parts aren't doing anything for me.  NO CHANGES
end;

However, in the Win32 Developer's Reference in Delphi it states:

Windows provides default color values for buttons. The system sends a WM_CTLCOLORBTN message to a button's parent window before the button is drawn. This message contains a handle of the button's device context and a handle of the child window. The parent window can use these handles to change the button's text and background colors. The following table shows the default button-color values.

Value                           Element colored
COLOR_BTNFACE           Button faces.
COLOR_BTNHIGHLIGHT    Highlight area (the top and left edges) of a button.
COLOR_BTNSHADOW           Shadow area (the bottom and right edges) of a button.
COLOR_BTNTEXT           Regular (nongrayed) text in buttons.
COLOR_GRAYTEXT           Disabled (gray) text in buttons. This color is set to 0 if the current display driver does not support a solid gray color.
COLOR_WINDOW           Window backgrounds.
COLOR_WINDOWFRAME  Window frames.
COLOR_WINDOWTEXT    Text in windows.

So according to this it should be possible...I just don't know how.
Thanks for looking into it for me Slick812!
dbettsAuthor Commented:
Perhaps this is my problem.  This came from the Win32 help in Delphi for the WM_CTLCOLORBTN:

Return Values:
If an application processes this message, it must return the handle of a brush. Windows uses the brush to paint the background of the button.

How do I return the handle of a brush based on the code I have in my previous note?  What is a brush handle?  (P.S. I have increased the point value).

Thanks.
Slick812Commented:
Look, I have already explained, and I have read that API for that a hundred times,

 IT WILL NOT CHANGE ANY THING ON A STANDARD BUTTON, I do not care what it says. . . It will do all of that if the button is OWNER DRAWN, and ONLY if the button is owner drawn
Slick812Commented:
procedure TForm1.CatchtIt(var Msg: TMessage);
begin
  SetBkColor(Msg.WParam, RGB(0,0,220));  
  SetTextColor(Msg.WParam, RGB(0,0,220)); // this will change the text color on a OWNER DRAW BUTTON

Result := GetStockObject(WHITE_BRUSH);
//The Result can be a Brush for an OWNER DRAWN BUTTON
end;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Slick812Commented:
should be
Msg.Result := GetStockObject(WHITE_BRUSH);
Slick812Commented:
What is a brush handle?

the windows system creates Brushes, to fill in colors in areas of display pixels, and to keep track of which brush is which, it gives them and Identifier called a Handle, When ever you create a brush
hBrush1 := CreateSolidBrush($FFFFA0);
you will Identify this brush to the system with
hBrush1
the handle of that brush

in delphi graphics you can use the TBrush  Handle property
Slick812Commented:
Oh, and I have also tried to convert a TButton to Owner Draw, and I could do this, However, the guys at Delphi have several code checks for a TButton, so if it's Style is changed it will change it back, so as soon as you click a converted TButton, it will go Back to being NON-owner Draw
dbettsAuthor Commented:
Okay.  Thanks for your help.  How should we do the points on this one?
Slick812Commented:
you can do what is convient for you, I did not help you to get the results that you wanted, (I only did this question because no one else did), but if my comments are helpful you can do a point adjustment. . .  OR if you is one of those whos got NO points, then go to community support at

http://www.experts-exchange.com/Community_Support/

and ask for a refund, delete, close question or you can read some of the stuff there to get an idea of how to

as I said, there are a ton of Color Button components, but if you are stuck with your component, then what you got is what you get
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.