首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-01-13 
求这个C++ 的C#代码publicintMyHookProc(intcode,IntPtrwparam,IntPtrlparam){LPMSGlpMsg(LPMSG)lParami

求这个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;
}
}
}
}

热点排行