zoukankan      html  css  js  c++  java
  • C#控制其它程序

      [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 button1_Click(object sender, EventArgs e)
            {
                var hwndPhoto = FindWindow(null, "XMind"); //查找拍照程序的句柄【任务管理器中的应用程序名称】  

                if (hwndPhoto != IntPtr.Zero)
                {
                    SetForegroundWindow(hwndPhoto);    //将UcDemo程序设为当前活动窗口  
                    SendKeys.Send("^o");
                    Clipboard.SetDataObject(@"D:思维导图文档基础数据改造.xmind");
                    System.Threading.Thread.Sleep(200);   //暂停500毫秒  
                    SendKeys.Send("^v");
                    System.Threading.Thread.Sleep(200);   //暂停500毫秒
                    SendKeys.Send("~");
                    System.Threading.Thread.Sleep(500);   //暂停500毫秒
                    SendKeys.Send("^p");
                    System.Threading.Thread.Sleep(200);   //暂停500毫秒
                    SendKeys.Send("~");
                }
                else
                {
                    MessageBox.Show("没有启动 XMind");
                }
            }

  • 相关阅读:
    网络世界中的图片以及相关的处理
    Ninject 2.x细说1.基本使用
    Orchard1.4新功能自动路由(AutoRouter)并附Orchard最新1.4版汉化包
    json的一点总结
    ASP.NET MVC路由扩展:路由映射
    厚积薄发,丰富的公用类库积累,助你高效进行系统开发(12) 网络相关操作辅助类
    IIS是如何处理ASP.NET请求的
    一周最新示例代码回顾 (3/19–3/25)
    .NET插件系统(三) 插件间通信问题——设计可自组织和注入的组装程序
    缓存总结
  • 原文地址:https://www.cnblogs.com/littlehb/p/5913668.html
Copyright © 2011-2022 走看看