小弟已经获得某个控件句柄,问题如下:
1,如何判断是什么控件,我需要判断出(edit,label,button,dbedit,shape)
2,如何在知道是什么控件的基础上设置这个控件的一些属性。如dbedit的dataset,
1,如何判断是什么控件,我需要判断出(edit,label,button,dbedit,shape)
2,如何在知道是什么控件的基础上设置这个控件的一些属性。如dbedit的dataset,
int GetClassName(
HWND hWnd, // handle of window
LPTSTR lpClassName, // address of buffer for class name
int nMaxCount // size of buffer, in characters
);
LPTSTR lpClassName, // address of buffer for class name
int nMaxCount // size of buffer, in characters
);
var
Pos: TPoint;
Handle: HWND;
ScreenDC: HDC;
Buf: array[0..1024] of Char;
ScreenColor: COLORREF;
begin
GetCursorPos(Pos); // 得到当前光标位置
Handle := WindowFromPoint(Pos); // 返回当前位置的句柄
HandleText.Caption := IntToStr(Handle);
GetClassName(Handle, Buf, 1024); // 得到类名
ClassNameText.Caption := Buf;
SendMessage(Handle, WM_GETTEXT, 33, Integer(@Buf)); // 得到标题
TitleText.Caption := Buf;
{ 得到光标处点的颜色 }
ScreenDC := GetDC(0);
ScreenColor := GetPixel(ScreenDC, Pos.X, Pos.Y);
Shape.Brush.Color := TColor(ScreenColor);
RGBColorText.Caption := '红: ' + IntToStr(GetRValue(ScreenColor)) +
' 绿: ' + IntToStr(GetGValue(ScreenColor)) + ' 蓝: ' +
IntToStr(GetBValue(ScreenColor));
ReleaseDC(0, ScreenDC);
DelphiColorText.Caption := Format('Delphi 值:$00%2.2x%2.2x%2.2x', [GetBValue(ScreenColor),
GetGValue(ScreenColor), GetRValue(ScreenColor)]);
HTMLColorText.Caption := Format('HTML 值:#%2.2x%2.2x%2.2x', [GetRValue(ScreenColor),
GetGValue(ScreenColor), GetBValue(ScreenColor)]);
end;root3646 提供~放一个timer控件,读鼠标处的控件,知道他的父类,还有内容
还有颜色功能。
哈哈。。这段代码给我转了很多分啊~转发请注意完整
不要笑话小弟了,跟你比我这些只是毛毛雨了!
三个三角我费了我好大力气才弄到的。连哄在骗了!哈哈。。
con: TControl;
begin
con := FindControl('你的句柄');
if con is TEdit then
showmessage('TEdit')
else
if con is Tbutton then
showmessage('button')
...
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DBCtrls;type
TForm1 = class(TForm)
Shape: TShape;
Memo1: TMemo;
Button1: TButton;
Timer1: TTimer;
Edit1: TEdit;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
var
Pos: TPoint;
Handle: HWND;
Buf: array[0..1024] of Char;
con: TControl;
begin
GetCursorPos(Pos);
Handle := WindowFromPoint(Pos);
GetClassName(Handle, Buf, 1024);
con := FindControl(handle);
if con is TEdit then
begin
with con as TEdit do
begin
name := 'chjEdt';
Text := 'My Test Edit';
width := 89;
height := 20;
end;
end
else if con is Tbutton then
begin
with con as TButton do
begin
name := 'chjBtn';
Caption := 'OK';
Text := 'ok';
width := 40;
height := 20;
end;
end
else if con is TDBEdit then
begin
with Con as TDBEdit do
begin
//设置属性
end;
end;
end;end.