在Windows c#

时间:2016-03-15 12:58:03

标签: c# .net windows powershell winapi

我花了3天的时间试图在网上和自己找到解决方案。找到了很多相关材料,但没有什么能适合我的情景。 我已经通过以下代码启动了一个新进程,它是windows语音识别应用程序,我想以编程方式调用其右键菜单中的一个选项。

我已经测试过了 Postmessage,Sendmessage和sendClick事件,它们都不起作用。

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("User32.dll")]
        public static extern int SetForegroundWindow(IntPtr point);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr FindWindow(string lpClass, string lpW);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        public static extern void PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);

        public Form1()
        {
            //InitializeComponent();

            const int WM_COMMAND = 0x0111; 
            Process proc = new Process();

            proc.StartInfo.FileName = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessibility\Speech Recognition.lnk";

            proc.Start(); 
            Thread.Sleep(200);   
            IntPtr Window = FindWindow(null, "Speech Recognition");

            SetForegroundWindow(Window);

            SendKeys.SendWait("{Move 200,200}");
        }
    }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

假设你想要Open the Speech Dicitonary,你可以通过

来实现