How to get enabled property of a control?

时间:2015-06-15 14:31:21

标签: delphi properties

In Delphi it is possible to get the process name and class name of any control which is clicked system wide via windows api.

process name:

GetWindowThreadProcessId(Hwnd, ProcessId) 

by process ID one can get to the process name

class name:

SetLength(ClassName, 255);
SetLength(ClassName, GetClassName(Hwnd, pchar(ClassName), 255));

Is there an easy way similar to the ones mentioned above to get a control's enabled property? (without using UIAutomation)

1 个答案:

答案 0 :(得分:2)

If you have the window handle for a control, then the IsWindowEnabled function will tell you whether it is enabled.

Keep in mind that that is acting on the window at the API level, not the Delphi VCL level. In Delphi, there can be controls that do not have window handles (anything that descends from TGraphicControl, which includes TLabel and TSpeedButton), so IsWindowEnabled obviously can't tell you anything about those controls.

Delphi does not provide any facility for querying information about arbitrary Delphi controls from other processes. If you need something like that, then you'll have to arrange for the external process to respond to commands of your choosing. That is, you will need to be in control of both programs so that you can put code in them both to cooperate.

If GetWindowThreadProcessId and GetClassName are already telling you the information you want, then IsWindowEnabled will work just fine because they all have the same limitation regarding Delphi VCL controls.