TPoint P;
char Buf[64];
AnsiString ClassName;GetCursorPos(&P);
GetClassName(WindowFromPoint(P),Buf,sizeof(64));
ClassName = AnsiString(Buf);
char Buf[64];
AnsiString ClassName;GetCursorPos(&P);
GetClassName(WindowFromPoint(P),Buf,sizeof(64));
ClassName = AnsiString(Buf);
解决方案 »
- 【自定义DTS任务问题】CustomTask接口中Get_Properties函数,详细问题请进!
- 怎知道BPL包含有哪些单元?
- 三层结构中:服务器(中间层)如何通知 所有客户端发生了什么事件,要求处理什么事了
- MSComm组件安装问题,急
- 如何删除ini文件中的所有内容?
- 找工作了,这有浙江的兄弟吗?
- SOS:特急 对Word中图片的操作:怎么让我刚刚插入的图片位于文字的中间或者浮动于文字的上方。
- 编译没错误..运行时出现错误:Runtime error 6 at 004050C8..请问什么问题?
- 简单问题,创建线程时,调用线程函数,提示"Variable required"错误
- 一个初学者关于发邮件的问题.
- Bookmark做什么用的,有什么功能?在线等侍!
- 怎么去掉delphi自身给菜单上加上的快捷键如:系统功能(U),业务管理(V).....?
ClassName: PChar;
ptCursor: TPoint;
hWndOver: HWND;
Text: PChar;
begin
GetCursorPos(ptCursor);
hWndOver := WindowFromPoint(ptCursor);
GetMem(ClassName, 100);
GetMem(Text, 255);
try
GetClassName(hWndOver, ClassName, 100);
SendMessage(hWndOver, WM_GETTEXT, 255, LongInt(Text));
Canvas.FillRect(Rect(5, 20 , PreClassLength + 20, 40));
Canvas.FillRect(Rect(5, 40 , PreTextLength + 20, 60));
PreClassLength := Canvas.TextWidth(ClassName);
PreTextLength := Canvas.TextWidth(Text);
if PreClassLength > PreTextLength then
Width := Canvas.TextWidth(ClassName) + 20
else
Width := Canvas.TextWidth(Text) + 20;
Canvas.TextOut(5, 20, string(ClassName));
Canvas.TextOut(5, 35, string(Text));
finally
FreeMem(ClassName);
FreeMem(Text);
end;
end;
把classname换成name就可以了。
var
I: Integer;
S: string;
vPoint: TPoint;
begin
S := '<没有找到>';
vPoint := ScreenToClient(Mouse.CursorPos);
for I := 0 to ComponentCount - 1 do
if (Components[I] is TControl) and
PtInRect(TControl(Components[I]).BoundsRect, vPoint) then begin
S := Components[I].Name;
Break;
end;
Caption := S;
end;
var
I: Integer;
S: string;
vPoint: TPoint;
begin
S := '<没有找到>';
vPoint := ScreenToClient(Mouse.CursorPos);
for I := 0 to ComponentCount - 1 do
if (Components[I] is TControl) and
PtInRect(TControl(Components[I]).BoundsRect, vPoint) then begin
S := Components[I].Name;
Break;
end;
Caption := S;
end;
var
I: Integer;
S: string;
vPoint: TPoint;
begin
S := '<没有找到>';
vPoint := ScreenToClient(Mouse.CursorPos);
for I := 0 to ComponentCount - 1 do
if (Components[I] is TControl) and
PtInRect(TControl(Components[I]).BoundsRect, vPoint) then begin
S := Components[I].Name;
Break;
end;
Caption := S;
end;
好像说The WindowFromPoint function does not retrieve the handle of a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search. 因此可以试试ChildWindowFromPoint函数了
你把它写在一个timer的ontimer事件中,然后用鼠标在屏幕中移动,
所有的窗口都能得到。
不用非要得到名称。
谢谢!
直接窗体上的是行的,但在panel里面的label就不行了。
能不能再改进一下。
不用非要得到名称。
不用非要得到名称。
var
I: Integer;
S: string;
begin
S := '<没有找到>';
for I := 0 to ComponentCount - 1 do
if (Components[I] is TControl) and
PtInRect(TControl(Components[I]).BoundsRect,
TControl(Components[I]).Parent.ScreenToClient(Mouse.CursorPos)) then
S := Components[I].Name;
Caption := S;
end;
var
I: Integer;
S: string;
begin
S := '<没有找到>';
for I := 0 to ComponentCount - 1 do
if (Components[I] is TControl) and
PtInRect(TControl(Components[I]).BoundsRect,
TControl(Components[I]).Parent.ScreenToClient(Mouse.CursorPos)) then
S := Components[I].Name;
Caption := S;
end;
var
I: Integer;
S: string;
begin
S := '<没有找到>';
for I := 0 to ComponentCount - 1 do
if (Components[I] is TControl) and
PtInRect(TControl(Components[I]).BoundsRect,
TControl(Components[I]).Parent.ScreenToClient(Mouse.CursorPos)) then
S := Components[I].Name;
Caption := S;
end;