title: How to register WndProc in console app
body: <p>When I create a new Win32 application, I notice the function:</p>
  
  <pre><code>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  </code></pre>
  
  <p>would receive message when somewhere call the function <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms644944(v=vs.85).aspx" rel="noreferrer">PostMessage</a> or SendMessage, and I notice that the function WndProc can receive message because there is a function that register it:</p>
  
  <pre><code>ATOM MyRegisterClass(HINSTANCE hInstance)
  {
      WNDCLASSEX wcex;
  
      wcex.cbSize = sizeof(WNDCLASSEX);
  
      wcex.style          = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc    = WndProc;
      wcex.cbClsExtra     = 0;
      wcex.cbWndExtra     = 0;
      wcex.hInstance      = hInstance;
      wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SCREENCAPTURE));
      wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
      wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_SCREENCAPTURE);
      wcex.lpszClassName  = szWindowClass;
      wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  
      return RegisterClassEx(&amp;wcex);
  }
  </code></pre>
  
  <p>Notice: <code>wcex.lpfnWndProc    = WndProc;</code></p>
  
  <p>I want to understand the mechanism of PostMessage() and how to receive it, so I created a C++ Console app to see if I can register the function WndProc, here is my attempting code:</p>
  
  <pre><code>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  {
      int a = 1;//Break point here to see if it's call
      return 0;
  }
  
  ATOM MyRegisterClass(HINSTANCE hInstance)
  {
      WNDCLASSEX wcex;
  
      wcex.lpfnWndProc = WndProc;
      wcex.hInstance = hInstance;
  
  
      return RegisterClassEx(&amp;wcex);
  }
  
  void main()
  {
      MyRegisterClass(GetModuleHandle(NULL));//(HINSTANCE)GetConsoleWindow()
  
      PostMessage(GetConsoleWindow(), 132, 0, 0);
  
      SYSTEMTIME st;
  
      while (true)
      {
          GetSystemTime(&amp;st);
          printf("I'm wanting and waiting and waiting :(, The time is %I64u \n", st.wMilliseconds);
      }
  
  }
  </code></pre>