如何得到系统中当前光标所在位置的窗口句柄?
就是用户正在输入东西的那个窗口

解决方案 »

  1.   

    windowfrompoint这个函数分太好得了,
      

  2.   

    windowfrompoint这个函数分太好得
      

  3.   

    HWND WindowFromPoint(    POINT Point  // structure with point
       );返回当前光标位置的控件句柄BOOL GetCursorPos(    LPPOINT lpPoint  // address of structure for cursor position  
       );这个函数返回前前光标位置,,
    把GetCursorPos返回值传入windowfrompoint参数即可
      

  4.   

    别急!!
    如何得到系统中当前光标所在位置?
    HWND WindowFromPoint(
      POINT Point  // point
    );
      

  5.   

    HWND WindowFromPoint(    POINT Point  // structure with point
       );返回当前光标位置的控件句柄BOOL GetCursorPos(    LPPOINT lpPoint  // address of structure for cursor position  
       );这个函数返回前前光标位置,,
    把GetCursorPos返回值传入windowfrompoint参数即可
      

  6.   

    获取当前鼠标位置的类名和句柄这有点像金山词霸的屏幕取词。要获取当前鼠标位置的类名和句柄,只须通过 WindowFromPoint
    和GetClassName 这两个Win32函数就可以完成任务,不过,如果要获取当前鼠标位置的字符,可能要复杂得多。
    下面是很简单的范例,大家应该都可以轻易弄清楚的。
    typeTForm1 = class(TForm)NameLB: TLabel;ClassLB: TLabel;Timer1: TTimer;procedure Timer1Timer(Sender: TObject);procedure FormCreate(Sender: TObject);privateprocedure GetMousePosHwndAndClassName(Sender : TPoint);public
    end;
    varForm1: TForm1;
    implementation
    {$R *.DFM}
    procedure TForm1.Timer1Timer(Sender: TObject);varrPos: TPoint;beginif boolean(GetCursorPos(rPos)) thenGetMousePosHwndAndClassName(rPos);end;
    procedure TForm1.GetMousePosHwndAndClassName(Sender: TPoint);varhWnd: THandle;aName: array [0..255] of char;beginhWnd := WindowFromPoint(Sender);NameLB.Caption := ’Handle : ’ + IntToStr(hWnd);
    if boolean(GetClassName(hWndaName256)) thenClassLB.Caption := ’ClassName : ’ + string(aName)else
    ClassLB.Caption := ’ClassName : not found’;end;
    procedure TForm1.FormCreate(Sender: TObject);beginForm1.FormStyle := fsStayOnTop;Timer1.Interval := 50;end;
      

  7.   

    我以前写的一个偷QQ的软件,
    必须得在TIMER中进行时时鼠标位置跟踪
    这样就能时时得到鼠标所在控件的句柄或类名了楼主不要做坏事喽~~
      

  8.   

    BOOL GetCursorPos(    LPPOINT lpPoint  // address of structure for cursor position  
       );只是返回当前鼠标位置,和用户输入数据的那个光标没有关系吧!我要得到当前激活的那个输入窗口的句柄
      

  9.   

    To:ghyghost(爱国人士)
    非坏事,是想研究一下
      

  10.   

    To:ghyghostII(著名关心CSDN结贴率爱国主义人士) 
    兄台,两个都是你啊?
      

  11.   

    TO  karl(多功能算术逻辑运算单元) 是啊:)
    继承下去的:)
      

  12.   

    只是返回当前鼠标位置,和用户输入数据的那个光标没有关系吧!我要得到当前激活的那个输入窗口的句柄你没明白那二个函数的意思,,,,
    GetCursorPos是返回当前鼠标光标所在的屏幕绝对位置。你的光标所在的控件也是有一个位置的吧
    那么使用GetCursorPos函数就能取得那个控件的位置坐标,
      

  13.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
    cursor_postion:tpoint;
    handle:hwnd;
    class_name:pchar;
    intResult:integer;
    strClassName:string;
    begin
    Timer1.Enabled :=false;
    getcursorpos(cursor_postion);
    handle:=windowfrompoint(cursor_postion);
    if handle<>0 then
       begin
       GetMem(class_name,256);
       intResult:=getclassname(handle,class_name,256);
       //showmessage(inttostr(intResult));//判断是否得到类型
       form1.Memo1.Lines.Add(Trim(string(class_name)));
       FreeMem(Class_Name);
       end;
    timer1.Enabled :=true;
    end;
      

  14.   

    呵呵unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Label1: TLabel;
        CheckBox1: TCheckBox;
        RadioButton1: TRadioButton;
        Timer1: TTimer;
        Memo1: TMemo;
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Timer1Timer(Sender: TObject);
    var
    cursor_postion:tpoint;
    handle:hwnd;
    class_name:pchar;
    intResult:integer;
    strClassName:string;
    begin
    Timer1.Enabled :=false;
    getcursorpos(cursor_postion);
    handle:=windowfrompoint(cursor_postion);
    if handle<>0 then
       begin
       GetMem(class_name,256);
       intResult:=getclassname(handle,class_name,256);
       //showmessage(inttostr(intResult));//判断是否得到类型
       form1.Memo1.Lines.Add(Trim(string(class_name)));
       FreeMem(Class_Name);
       end;
    timer1.Enabled :=true;
    end;end.
      

  15.   

    要么就是我理解错了,如果错了,那么就是要使用hook了,很简单的
      

  16.   

    得到光标的位置用GetCaretPos
    然后调用WindowFromPoint
    没必要使用hook,用个timer或者后台线程就足够了
      

  17.   

    function GetSursorPos(
                          lpPoint:LPPOINT  //指向鼠标位置的指针
                          );BOOL;stdcall;
    如果上面的函数执行成功,返回一个非零的值,并将鼠标位置存在lpPoint中,
    用上面的函数取得鼠标位置后,用WindowFromPoint函数通过鼠标坐标取得
    该点的窗口句柄:
    function WindowFromPoint(
                             Point:TPoint  //TPoint结构,存着鼠标坐标点
                             )HWND;stdcall; 
    如果WindowFromPoint执行成功,返回窗口句柄,否则返回NULL,注意此函数不能
    取得隐藏的或处于不活动状态的窗体,即使这个坐标点就处于其窗口内,要进行无限
    搜索,用ChlidWindowFromPoint函数:
    function ChlidWinfowFromPoint(
                                  hWndParent:HWND; //父窗口句柄 
                                  Point:TPoint;    //坐标点
                                  )HWND;stdcall
    举例:
    1.创建一个新的应用程序;
    2.往Form1中加入一个Memo1和一个Timer1;procedure TForm1.Timer1Timer(Sender:TObject);
    var
      aClassName,aWndText:array[0..254] of char;
      hWnd,hWndOwer:hWnd; //等于hWndOwer:THandle
      pos:TPoint;
    begin
    //取得鼠标位置
    GetCursorPos(pos);
    //根据鼠标位置得到它所在的窗体句柄 
    hWnd:=WindowFromPoint(pos);
    //由窗口句柄得到窗口类名和标题
    GetClassName(hWnd,@aClassName,255);
    GetWindowText(hWnd,@aWndText,255);
    //显示
    with Memo1.Lines do
         begin
           Clear;
           Add('窗体句柄:'+IntToStr(hWnd));
           Add('窗体类名:'+aClassName);
           Add('窗体标题:'+aWndText);
         end;
    //由窗口句柄得到父窗体
    hWndOwer:=GetWindow(hWnd,GW_OWNER);
    GetClassName(hWndOwer,@aClassName,255);
    GetWindowText(hWndOwer,@aWndText,255);
    with Memo1.Lines do
         begin
           Add('父窗口句柄:'+IntToStr(hWndOwer));
           Add('父窗口类名:'+aClassName);
           Add('父窗口标题:'+aWndText);
         end;
    end;3.往Form1中加入一个Button1;
    procedure TForm1.Button1Click(Sender:TObject);
    begin
      Timer1.Enable:=not Timer1.Enable;
      if Timer1.Enable then
         Button1.Caption:='停止'
      else
         Button1.Caption:='开始';
    end;
      

  18.   

    to楼上
    如果楼主的意思就是得到当前的活动窗口用哪个函数,可用GetForegroundWindow获得前台窗口句柄
      

  19.   

    To  doudouding()
        GetForegroundWindow函数只能返回当前应用程序的的句柄,我想要的是能不能得到当前控件的句柄,就是具体一个输入框,按钮等等控件
      

  20.   

    AttachThreadInput(GetcurrentThreadID,GetWindowThreadProcessID(GetForegroundWindow,nil),True)
    GetFocus;
    完成!!!