zoukankan      html  css  js  c++  java
  • delphi2010 向另一个窗口发送鼠标点击事件

    procedure TForm1.Button1Click(Sender: TObject);
    var
     szText: array[0..254] of char;
     hCurrentWindow :hwnd;
     r:trect ;
     point:tpoint;
    begin
       hCurrentWindow := GetWindow(Handle,GW_HWNDFIRST);
       memo1.Clear;
       while hCurrentWindow <> 0 do
       begin
        if GetWindowText(hCurrentWindow ,@szText,255) > 0 then
        if  pos('Form111', PChar(@szText))<>0 then  //这里指定某一窗口,可能有多个
        begin
        memo1.lines.Add(PChar(@szText));

        ShowWindow(hCurrentWindow,SW_SHOWNORMAL);//恢复最小化的窗口,如果窗口最小化,无法成功发送鼠标事件

       // 必要时还可以用到下面:
        //ShowWindow(hCurrentWindow,   SW_RESTORE);//恢复窗口
        // ShowWindow(hCurrentWindow,   SW_MINIMIZE);//最小化窗口
        SetForegroundWindow(hCurrentWindow);//设置窗口为当前窗口

        GetWindowRect(hCurrentWindow,r);//得到窗口的左上角坐标


         getcursorpos(point); //获取鼠标原来的位置
        setcursorpos(r.Left+120,r.Top+60);  //设置鼠标在窗口的位置 ,即需要点的地方
        mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);  //鼠标左键按下
        mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);   //鼠标左键按下
        setcursorpos(point.x,point.y); //恢复鼠标原来的位置

          end;

        hCurrentWindow := GetWindow(hCurrentWindow,GW_HWNDNEXT);
     end;
    end;

    http://cy03wqh.blog.163.com/blog/static/3678030220108551731926/

  • 相关阅读:
    Luogu P1596 [USACO10OCT]湖计数Lake Counting
    Luogu P1757 通天之分组背包
    数据建模笔记1
    单纯形算法 matlab
    有效集 matlab代码
    拟牛顿 DFP matlab
    FR共轭梯度法 matlab
    整数规划
    线性规划 Matlab
    远期、期货和互换(三)
  • 原文地址:https://www.cnblogs.com/sunsoft/p/1967560.html
Copyright © 2011-2022 走看看