我想使用PostMessage发送一个制表键。PostMessage似乎并没有工作
这里是我的代码:
// This class allows us to send a tab key when the the enter key
// is pressed for the mooseworks mask control.
public class MaskKeyControl : MaskedEdit
{
// [DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
// static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
[return: MarshalAs(UnmanagedType.Bool)]
// I am calling this on a Windows Mobile device so the dll is coredll.dll
[DllImport("coredll.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, Int32 wParam, Int32 lParam);
public const Int32 VK_TAB = 0x09;
public const Int32 WM_KEYDOWN = 0x100;
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
PostMessage(this.Handle, WM_KEYDOWN, VK_TAB, 0);
return;
}
base.OnKeyDown(e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
e.Handled = true;
base.OnKeyPress(e);
}
}
当我按下输入代码被调用,但没有任何反应。然后我按Tab键,它工作正常。 (所以我发送Tab消息时出了点问题。)
我添加了compact-framework标签,你有一些答案不是针对紧凑框架。 – 2010-05-18 19:45:35
@克里斯泰勒 - 谢谢。我应该补充说,当我问它。 – Vaccano 2010-05-18 20:13:33