zoukankan      html  css  js  c++  java
  • C#调用其他程序,比如控制别的程序上的按钮 分类: .NET 20120419 16:50 2216人阅读 评论(0) 收藏

            [DllImport ( "user32.dll", EntryPoint = "FindWindow", SetLastError = true )]
            private static extern IntPtr FindWindow( string lpClassName, string lpWindowName );
    
            [DllImport ( "user32.dll", EntryPoint = "FindWindowEx", SetLastError = true )]
            private static extern IntPtr FindWindowEx( IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow );
    
            [DllImport ( "user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto )]
            private static extern int SendMessage( IntPtr hwnd, uint wMsg, int wParam, int lParam );
    
            [DllImport ( "user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true )]
            private static extern void SetForegroundWindow( IntPtr hwnd );
    
            private void button2_Click(object sender, EventArgs e)
            {
                const uint BM_CLICK = 0xF5; //鼠标点击的消息,对于各种消息的数值,大家还是得去API手册
    
                IntPtr hwndPhoto = FindWindow(null, "UC580Demo"); //查找拍照程序的句柄【任务管理器中的应用程序名称】
                
    
                if (hwndPhoto != IntPtr.Zero)
                {
                    IntPtr hwndThree = FindWindowEx(hwndCalc, 0, null, "快照"); //获取按钮快照的句柄
    
                    SetForegroundWindow(hwndPhoto);    //将UcDemo程序设为当前活动窗口
    
                    System.Threading.Thread.Sleep(500);   //暂停500毫秒
                   
                    SendMessage(hwndThree, BM_CLICK, 0, 0);//模拟点击拍照按钮
                }
                else
                {
                    MessageBox.Show("没有启动 UcDemo");
                }
    
            }
    


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Linux三剑客之sed深度实践讲解(上)
    Linux第三阶段题型测试
    Linux正则表达式题型
    linux文本处理三剑客命令及用法
    SSH服务协议、部署ssh、scp、sftp服务
    NFS客户端挂载及永久生效
    SSH实现无密码登录
    NFS深度解析及搭建同步NFS服务
    NFS文件系统及搭建NFS共享服务
    Linux系统磁盘管理
  • 原文地址:https://www.cnblogs.com/configman/p/4657592.html
Copyright © 2011-2022 走看看