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

  • 相关阅读:
    [换根dp] Codeforces Round 67 (Rated for Div. 2) E
    [思维]Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A B1 B2 C D
    [Comet OJ
    关于Winform中的消息框MessageBox
    C#截取字符串的几种方式
    C#中的时间格式大全
    winform中dev的TreeList基本使用方式
    拉取项目时error setting certificate verify locations解决方式
    如何在GridView中新增按钮列
    使用GitHub/码云/Git个性化设置
  • 原文地址:https://www.cnblogs.com/littlehb/p/5913668.html
Copyright © 2011-2022 走看看