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");
                }
    
            }
    


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

  • 相关阅读:
    zimg
    ffmpeg P016 P010 YUV444P16LE 的打印的像素值
    zimg 使用
    P010LE P016LE YUV420P10LE
    如鹏网学习笔记(八)CSS
    对dui界面 组件 hook的通杀方案
    Python 中str 与 bytes 数据结构转换
    Tensorflow 老版本的安装
    Java string和各种格式互转 string转int int转string
    电脑黑屏
  • 原文地址:https://www.cnblogs.com/configman/p/4657592.html
Copyright © 2011-2022 走看看