title: How can I set up a CBT hook on a Win32 console window?
body: <p>I've been trying to set up a CBT hook for my C++ Console application with the following code:</p>
  
  <pre><code> ...includes...
  
   typedef struct _HOOKDATA
   {
      int type;
      HOOKPROC hookproc;
      HHOOK hhook;
   }_HOOKDATA;
  
   _HOOKDATA hookdata;
  
   //CBT
   LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
   { 
      //do not proccess message
      if(code &lt; 0)
      {
         cout&lt;&lt;"code less than 0"&lt;&lt;endl;
         return CallNextHookEx(hookdata.hhook,code,wParam,lParam);
      }
  
      switch(code)
     {
        case HCBT_ACTIVATE:
             break;
        case HCBT_CREATEWND:
             cout&lt;&lt;"CREATEWND"&lt;&lt;endl;
             break;
        case HCBT_MINMAX:
             cout&lt;&lt;"MINMAX"&lt;&lt;endl;
             break;
        default: //unknown
             cout&lt;&lt;"DEFAULT"&lt;&lt;endl;
             break;
     }
  
     return CallNextHookEx(hookdata.hhook, code, wParam, lParam);
  }
  
  int main()
  {
     hookdata.type = WH_CBT; 
     hookdata.hookproc = CBTProc; 
     hookdata.hhook = ::SetWindowsHookEx(hookdata.type, CBTProc, 
                                      GetModuleHandle( 0 ), GetCurrentThreadId());
  
     if(hookdata.hhook == NULL)
     {
       cout&lt;&lt;"FAIL"&lt;&lt;endl;
       system("pause");
     }
  
     system("pause");
     return 0;
  }
  </code></pre>
  
  <p>The program seems to be working because there is not compile errors nor run time errors. Also I do not get a 'FAIL' message stated in the main() function meaning SetWindowHookEx is working OK. However, I don't get any of the messages stated in the CBTProc function; not even the 'DEFAULT' message. Can anyone pin-point what is the logic error in the code?</p>
  
  <p>Thanks.</p>