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/

  • 相关阅读:
    170322操作系统定义、功能、位置与历史
    java 多线程
    java 网络编程TCP程序设计
    java 事件处理机制
    java GUI编程
    170321php3第4章 PHP5的基本语法+作业九九乘法表
    170320网络编程 udpclient udpGroupClient
    二叉树线索化
    哈希表
    二叉搜索树
  • 原文地址:https://www.cnblogs.com/sunsoft/p/1967560.html
Copyright © 2011-2022 走看看