sendmessage函数重复发送消息

时间:2017-04-18 09:13:06

标签: c# sendmessage

代码

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

public Window SendKey(int key)
{
    SendKey(Message.WM_KEYDOWN, new IntPtr((Int32)key), new IntPtr(0))
    .SendKey(Message.WM_KEYUP, new IntPtr((Int32)key), new IntPtr(0));
    return this;
}

private Window SendKey(uint Msg, IntPtr wParam, IntPtr lParam)
{
    SendMessage(_windowHandler, Msg, wParam, lParam);
    Thread.Sleep(50);
    return this;
}
var wind = new Window(new IntPtr(0x000601f2));
wind.SendKey(Keys.VK_F5);

结果

F5键不会刷新Web浏览器,它会发送如下图所示的消息: enter image description here

有人对这个问题有任何想法吗?

0 个答案:

没有答案