有什么办法,可以知道,光标所在位置的窗口句柄?

解决方案 »

  1.   

    WindowFromPoint
    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  
      

  2.   

    first setcapture.
    seconed xxx
      

  3.   

    WindowFromPoint得到某位置的句丙
      

  4.   

    procedure TForm1.GetAWnd(var Wnd: hWnd; var WClassName: string;
      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;
      

  5.   

    Var
      pos: TPoint;      
      wnd: THandle;
    begin
      getcursorpos(pos);
      wnd:=windowFromPoint(pos);
    end;
      

  6.   

    结帖吧!
    给你一个程序,
    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,再改下名字就可以了