title: Detect external display being connected or removed under Windows 7
body: <p>Is there some event or notification I can receive or hook each time an external LCD monitor is plugged in or unplugged from a laptop running Windows 7?</p>
  
  <p>The laptop detects this and switches my display to the external screen and back with certain kinds of resizing or repositioning but is this exposed by the operating system so that applications can provide a handler, attach a script, etc?</p>
  
  <p>If not, is there a registry setting or API I could poll from time to time?</p>
  
  <p>(I prefer programming C + Win32 API)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Mike's answer below, <a href="http://msdn.microsoft.com/en-us/library/aa363480%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>WM_DEVICECHANGE</code></a> led me to <a href="http://msdn.microsoft.com/en-us/library/aa363431%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>RegisterDeviceNotification()</code></a>, but I'm struggling to implement it so far...</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>This question has been asked with different wording a couple of times, but not fully answered yet in my opinion:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1440285/how-to-detect-hot-plugging-of-monitor-in-a-win32-application">How to detect hot plugging of monitor in a win32 application?</a></li>
  <li><a href="https://stackoverflow.com/questions/3267722/getting-an-event-on-monitor-hotplug-for-windows">Getting an event on monitor hotplug for windows</a></li>
  </ul>