积极答复者
WPF中,用PeekMessage方法过滤微软拼音中文输入状态下的数字输入失效。

问题
答案
-
问题已解决。
PeekMessage有两种:
1.ITfMessagePump::PeekMessageA method
2.PeekMessageA function (Win32)
第一种PeekMessage可以阻止微软拼音中文输入状态下的所有键盘输入。
关键代码入下:
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("8f1b8ad8-0b6b-4874-90c5-bd76011e8f7c")]
internal interface ITfMessagePump
{
bool PeekMessage(out MSG msg, IntPtr hwnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
}[SecurityCritical, SuppressUnmanagedCodeSecurity, DllImport("msctf.dll")]
public static extern int TF_GetThreadMgr(out ITfMessagePump xMessagePump);//将PeekMessage进行封装,此时可直接调用
public static bool PeekMessage()
{
ITfMessagePump threadManager;
bool peekResult=false;
if (TSF_NativeAPI.TF_GetThreadMgr(out threadManager) == 0)
{
MSG msg;
peekResult=threadManager.PeekMessage(out msg, IntPtr.Zero, Win32Consts.WM_KEYDOWN, Win32Consts.WM_KEYUP, 1);
}
return peekResult;
}
- 已标记为答案 WUZYJOE 2019年11月20日 8:21
全部回复
-
问题已解决。
PeekMessage有两种:
1.ITfMessagePump::PeekMessageA method
2.PeekMessageA function (Win32)
第一种PeekMessage可以阻止微软拼音中文输入状态下的所有键盘输入。
关键代码入下:
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("8f1b8ad8-0b6b-4874-90c5-bd76011e8f7c")]
internal interface ITfMessagePump
{
bool PeekMessage(out MSG msg, IntPtr hwnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
}[SecurityCritical, SuppressUnmanagedCodeSecurity, DllImport("msctf.dll")]
public static extern int TF_GetThreadMgr(out ITfMessagePump xMessagePump);//将PeekMessage进行封装,此时可直接调用
public static bool PeekMessage()
{
ITfMessagePump threadManager;
bool peekResult=false;
if (TSF_NativeAPI.TF_GetThreadMgr(out threadManager) == 0)
{
MSG msg;
peekResult=threadManager.PeekMessage(out msg, IntPtr.Zero, Win32Consts.WM_KEYDOWN, Win32Consts.WM_KEYUP, 1);
}
return peekResult;
}
- 已标记为答案 WUZYJOE 2019年11月20日 8:21