0

我想将密钥发送到背景窗口。在这种情况下,前景。我有这个代码

[DllImport("user32.dll")]
    public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    private void button1_Click(object sender, EventArgs e)
    {
        const uint WM_KEYDOWN = 0x100;
        const uint WM_KEYUP = 0x0101;
        string processName = "outlook";
        Process[] processList = Process.GetProcesses();

        foreach (Process P in processList)
        {
            if (P.ProcessName.Equals(processName))
            {
                IntPtr edit = P.MainWindowHandle;
                PostMessage(edit, WM_KEYDOWN, (IntPtr)(Keys.LControlKey), IntPtr.Zero);
                PostMessage(edit, WM_KEYDOWN, (IntPtr)(Keys.R), IntPtr.Zero);
                PostMessage(edit, WM_KEYUP, (IntPtr)(Keys.R), IntPtr.Zero);
                PostMessage(edit, WM_KEYUP, (IntPtr)(Keys.LControlKey), IntPtr.Zero);
            }
        }                         
    }

这有什么问题?它应该在 Outlook 中打开一个回复窗口,但它没有。另外,请不要回答与 Outlook 相关的问题,因为我想使用这种方法来做。

4

0 回答 0