Link to home
Start Free TrialLog in
Avatar of dbetts
dbetts

asked on

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
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

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
Avatar of dbetts
dbetts

ASKER

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.
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
Avatar of dbetts

ASKER

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!
Avatar of dbetts

ASKER

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.
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
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
should be
Msg.Result := GetStockObject(WHITE_BRUSH);
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
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
Avatar of dbetts

ASKER

Okay.  Thanks for your help.  How should we do the points on this one?
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

https://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