Solved

Change Color of an Object with API Functions

Posted on 2004-09-14
12
357 Views
Last Modified: 2013-11-23
How to change the color of an Object using API Functions ?
Like Delphi's Form Objects (Label , CheckBox , Button , ... ) which you can change the COLOR property of them. and in VB is like this , too.
I've tried the SetTextColor , CreatePen , SelectObject and some other GDI Functions but they had no result.
Can someone help me please ?
thx - SMA
0
Comment
Question by:sma_soft
  • 3
  • 2
  • 2
  • +2
12 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 12062535
TButton wraps the standard button windows control.
All the colors of these standard controls come from the registry. You change them in the Display Control Panel.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12062709
The WinControls have a canvas. For this canvas you can set the pen color and brush color. These values are used to draw these controls. Some controls have even more properties that contain other colors and font information. But in general there's no API call that can be used to change the color, because when the control redraws itself, it will revert to the previous color.
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12066988
TButton is just a wrapper for the Windows button control as robert said
so if you want to change the color of one specific button, your best option is just to use a third party component, there are MANY available, just look at Torrys for color button
0
 
LVL 33

Expert Comment

by:Slick812
ID: 12069291
hello sma_soft , , there is a large amount of information about the subject of  API functions and how to use them, , , Do you have a more specific  problem or question about something you want to do?  A certain control that you want to change color?  A TLable is NOT a windowed control, so it don't do API, also some controls do not respond to a color change (a system BUTTON does not want to do a change of Color, also a TCheckBox is a system BUTTON). . . And a different type of system Control will have different typs of methods for changing them. . .
What is it you are trying to do? Or are you wanting info about using API methods?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:sma_soft
ID: 12072404
BlackTigerX , I know about third-party Components , but I want to know how to this job with API Functions.
Because everything done in the Win32 Programs , are encapsulated of APIs.


Slick812 , First Thank you for your Guides.
Second , I've Created my Form using Pure-API. (CreateWindowEx , RegisterClassEx , etc.) I didn't use TForm.
and I also created a STATIC control using CreateWindowEx. (Against of Delphi's TLabel , it has a hWnd and can implement APIs.)
And I want to change the color of this Static Control using API. Because this is not a Delphi component and hasn't a COLOR property to set.
That's what I mean.
thx - SMA
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 12073064
The problem is that a Windows button simply does not react to any way to change its colors via Win32 API.
The only reaction is to a WM_SETTINGSCHANGE (aka WM_WININICHANGE) which is broadcast when the system colors in the Display Control Panel get changed.
0
 
LVL 2

Author Comment

by:sma_soft
ID: 12075095
robert_marquardt , I don't want to change the Windows's Colors. in Control Panel Display Settings. Because this will change colors of all objects. I want to change the color of one of my objects.
For Example in Delphi we write:
Edit1.Font.Color:=clRed;
I want to to this job with API Functions.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 12076318
Did i tell already that it is *impossible* with TButton?
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 125 total points
ID: 12077759
OK, I have more of an Idea of what you want for information, If you are doing an API program (without the Forms unit) then to change the color of a text "STATIC" control you will need to use the WM_CTLCOLORSTATIC in your Window Proc for the parent of the STATIC control, in the WM_CTLCOLORSTATIC message you will need to set the colors with  SetTextColor( ) and SetBkColor( ) , , also you can set the background  fill brush with the Window Proc Result as in the following code


WM_CTLCOLORSTATIC: if (LParam = hLabel1) then
{WM_CTLCOLORSTATIC is the pre Static Paint message to get
colors to paint the Label}
                     begin
                     SetTextColor(wParam,$00FFFFFF);
                     SetBkColor(wParam,$00FF0000);
                     {SetBkColor is only for the text drawing}
                     Result := Brush1;
                     {Result is the Brush Handle used to paint any
                     background not covered by text}
                     Exit;
                     {IMPORTENT
                       You MUST Exit so the DefWindowProc is NOT called
                       try it without Exit and the Static will NOT change colors}
                     end else
                     if (LParam = hIcon2) then
                     begin
                     Result := wClass.hbrBackground;
                     Exit;
                     end;

- - - - - - - - - - - - - - - - - - - - - - - -  - - - - - -  - - - - - -

you may can find some help for Delphi API  programming at
http://www.angelfire.com/hi5/delphizeus/index.html

there is information about WM_CTLCOLORSTATIC and other at
http://www.angelfire.com/hi5/delphizeus/brushpen.html

there is some API control change code at
http://www.angelfire.com/hi5/delphizeus/buttonedit.html

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

19 Experts available now in Live!

Get 1:1 Help Now