有什么办法,可以知道,光标所在位置的窗口句柄?
解决方案 »
- 求dbgrideh for delphi2007
- 关于TChart缩放问题,急!高手请进.
- 向虚拟表添加记录出错 请大家来帮忙啊
- 本人从网上下了一个Delphi7,但没有找到Installsheld工具,我该到哪里去下载
- 一段分析torrent文件bencoding数据的代码,总是莫名其妙出错,请帮忙看一下什么原因
- form需要设置哪个属性,才能在分辨率变大的时候,不至于看起来特别小。
- 有关于指针的问题!
- 请问GetSystemMetrics的用法,是什么意思
- 计算表达式的值,挺麻烦的问题,请大家帮忙!!!
- 超级解霸为何出错????
- 怎样才能给别人分数
- DELPHI中执行如下的代码后,不能打开EXCEL文件,可能是内存管理的问题,解决????
The WindowFromPoint function retrieves a handle to the window that contains the specified point. HWND WindowFromPoint(
POINT Point // structure with point
);
Parameters
Point
Specifies aPOINT structure that defines the point to be checked.
Return Values
The return value is a handle to the window that contains the point. If no window exists at the given point, the return value is NULL. If the point is over a static text control, the return value is a handle to the window under the static text control. Res
The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search. QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
Import Library: Use user32.lib.See Also
Windows Overview, Window Functions, ChildWindowFromPoint,POINT,WindowFromDC
seconed xxx
var WndText: string; var WndOwner: hWnd);
var
winPos:TPoint;
begin
GetCursorPos(winpos);
Wnd:=WindowFromPoint(WinPos);
GetClassName(Wnd, pchar(ClassName), 255);
GetWindowText(Wnd, pchar(WndText), 255);
WndOwner:=GetWindow(Wnd,GW_Owner);
end;
pos: TPoint;
wnd: THandle;
begin
getcursorpos(pos);
wnd:=windowFromPoint(pos);
end;
给你一个程序,
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
handletext: TLabel;
classnametext: TLabel;
TitleText: TLabel;
shape: TPanel;
RGBColorText: TLabel;
DelphiColorText: TLabel;
HTMLColorText: TLabel;
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;
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;
end.
拖6个LABEL,1个TIMER,1个PANEL,再改下名字就可以了