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/

  • 相关阅读:
    HTML基础学习笔记
    CSS-精灵图片的使用(从一张图片中截图指定位置图标)
    侧边栏显示
    HTML <form> action 属性
    2018年寒假小记
    算法提高--接水问题
    基础练习--huffman
    ...
    基础算法
    枚举--最长单词--蓝桥杯
  • 原文地址:https://www.cnblogs.com/sunsoft/p/1967560.html
Copyright © 2011-2022 走看看