title: How do I detect the addition of a new monitor?
body: <p>I have a windowless program that handles some window management hotkeys.  I'd like to provide features such as the ability to move a window between monitors.  I've used <a href="http://msdn.microsoft.com/en-us/library/dd162610%28v=vs.85%29.aspx" rel="nofollow"><code>EnumDisplayMonitors</code></a> to enumerate all existing monitors in the system, and I've written code to handle <code>WM_DEVICECHANGE</code>, but I'm not actually receiving the message.</p>
  
  <p>Here's my message loop:</p>
  
  <pre><code>// I've tried GetMessage(&amp;msg, (HWND) NULL, 0, 0) here too
  while (GetMessage(&amp;msg, (HWND) -1, 0, 0) &gt; 0)
  {
      int key;
      int mod;
  
      MessageBox(NULL, (LPCWSTR) ((std::wostringstream&amp;) (std::wostringstream() &lt;&lt; L"You got a message: " &lt;&lt; msg.message)).str().c_str(), L"Got Message", MB_OK);
  
      switch (msg.message)
      {
      case WM_HOTKEY:
          key = HIWORD(msg.lParam);
          mod = LOWORD(msg.lParam);
  
          if (mod != MOD_WIN) continue;
          ProcessHotkey(key);
          break;
      case WM_DEVICECHANGE:
          InitMonitorInfo();
      }
  }
  </code></pre>
  
  <p>The program compiles and runs fine, and the hotkeys work.  Upon adding or removing a monitor though, nothing happens.  The message box to indicate a message has been received never appears.</p>
  
  <p>I suppose I could just poll the monitor configuration every 5 seconds, but that's not the right way to solve the problem.</p>
  
  <p>Do I need to actually create a window to receive <code>WM_DEVICECHANGE</code>?  Because I don't.  The hotkeys post their messages to <code>NULL</code> when they fire since they're not bound to a window, to be handled by the main thread.</p>