读书人

求这个C++ 的C#代码解决方法

发布时间: 2012-01-13 22:43:29 作者: rapoo

求这个C++ 的C#代码
public int MyHookProc(int code, IntPtr wparam, IntPtr lparam)
{
LPMSG lpMsg = (LPMSG)lParam;
if (wparam.ToInt32() == PM_REMOVE)
{
// Don 't translate non-input events.
if (lpMsg-> message == WM_KEYDOWN)
{
if (IsDialogMessage(hDlg, lpMsg))
{
// The value returned from this hookproc is ignored,
// and it cannot be used to tell Windows the message has been handled.
// To avoid further processing, convert the message to WM_NULL
// before returning.

if (lpMsg-> wParam == VK_RETURN && GetKeyState(VK_CONTROL) & 0x80)
{
SendMessage(hDlg, WM_SEND_MESSAGE_SMS, NULL, NULL);
//return CallNextHookEx(m_hook, nCode, wParam, lParam);
/*lpMsg-> wParam = VK_BACK;


lpMsg-> lParam = 0;
lpMsg-> wParam = 0;*/

}

lpMsg-> message = WM_NULL;
lpMsg-> lParam = 0;
lpMsg-> wParam = 0;


}

}
}


[解决办法]
//你注释掉的语句我就不管啦,里面很多参数和函数不知道是不是你自定义的,没有改
public int MyHookProc(int code, IntPtr wparam, IntPtr lparam)
{
LPMSG lpMsg = new LPMSG();
lpMsg = (LPMSG)lParam;
if (wparam.ToInt32() == PM_REMOVE)
{
// Don 't translate non-input events.
if (lpMsg.message == WM_KEYDOWN)
{
if (IsDialogMessage(hDlg, lpMsg))
{
// The value returned from this hookproc is ignored,
// and it cannot be used to tell Windows the message has been handled.
// To avoid further processing, convert the message to WM_NULL
// before returning.
if (lpMsg.wParam == VK_RETURN && GetKeyState(VK_CONTROL) & 0x80)
{
//自定义函数?
SendMessage(hDlg, WM_SEND_MESSAGE_SMS, NULL, NULL);
//return CallNextHookEx(m_hook, nCode, wParam, lParam);
/*lpMsg-> wParam = VK_BACK;
lpMsg-> lParam = 0;
lpMsg-> wParam = 0;*/
}
lpMsg.message = WM_NULL;
lpMsg.lParam = 0;
lpMsg.wParam = 0;
}
}
}
}

读书人网 >C#

热点推荐