LRESULT CALLBACK KeyboardProc( int code,
    WPARAM wParam,
    LPARAM lParam
);
MSDN里面说如果code小于0的时候,返回值必须是callnexthookex的返回值,如果大于或者等于0的时候,建议使用callnexthookex,并且返回该返回值。这里的函数是由操作系统来调用的,参数code也是由操作系统来赋值的,那么我怎么知道code的值是多少呢?尽管这里的code对于大多数情况没有什么影响。
另外,我看到有很多由系统调用的函数如MFC里面的winmain,DLL里面的DllMain等,里面的参数是由操作系统来赋值的,我如果希望改变的话有什么办法呢?
我对这些概念不怎么清楚,各位请指教!!最好能够据个例子,,谢谢!!!!!

解决方案 »

  1.   

    LRESULT CALLBACK KeyboardProc( int code, 
        WPARAM wParam, 
        LPARAM lParam 
    )
    {
      ...
      if(code>=0)
        return CallNextHookEx(OldKBProc, code, wParam, lParam);
    }
      

  2.   

    KeyboardProc是系统来调用的,因此code由系统传入,你只要来判断大于小于0,并做相应的处理就行了。MSDN:
    code
    HC_ACTION
    The wParam and lParam parameters contain information about a keystroke message.
    HC_NOREMOVE
    The wParam and lParam parameters contain information about a keystroke message, and the keystroke message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)例子:LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) 
    {
    if (nCode == HC_ACTION)
    {//做处理,比如:
    KBDLLHOOKSTRUCT* pStruct = (KBDLLHOOKSTRUCT*)lParam;
    if (pStruct->vkCode == VK_LEFT)
    ShowWindow(glhWnd, SW_RESTORE);                  
    } else if (nCode == HC_NOREMOVE)
    {
    //do something
    }
    return CallNextHookEx(glhHook, nCode, wParam, lParam); 
    }
    winmain,DLL里面的DllMain等,里面的参数是由操作系统来赋值的,我如果希望改变的话有什么办法呢? 是操作系统传进来供你使用的,所以改变不改变完全取决于你自己