title: Delphi: How to respond to WM_SettingChange/WM_WinIniChange?
body: <p>i need to know when my application recieves a <a href="http://msdn.microsoft.com/en-us/library/ms725497(v=VS.85).aspx" rel="nofollow noreferrer"><code>WM_SETTINGCHANGE</code></a> message (formerly known as <a href="http://msdn.microsoft.com/en-us/library/ms725499(VS.85).aspx" rel="nofollow noreferrer"><code>WM_WININICHANGE</code></a>).</p>
  
  <p>Problem is that the message pump in <strong>TApplication</strong> sends it down a black hole (default handler) before i can get a chance to see it:</p>
  
  <pre><code>procedure TApplication.WndProc(var Message: TMessage);
  ...
  begin
     Message.Result := 0;
  
     for I := 0 to FWindowHooks.Count - 1 do
        if TWindowHook(FWindowHooks[I]^)(Message) then Exit;
  
     CheckIniChange(Message);
  
     with Message do
        case Msg of
        WM_SETTINGCHANGE:
           begin
              Mouse.SettingChanged(wParam);
              Default;   &lt;----------------------*poof* down the sink hole
           end;
        ...
        end;
        ...
  end;
  </code></pre>
  
  <p>The procedure <code>CheckIniChange()</code> doesn't throw any event i can handle, neither does <code>Mouse.SettingChanged()</code>.</p>
  
  <p>And once the code path reaches <code>Default</code>, it is sent down the <code>DefWindowProc</code> drain hole, never to be seen again (since the first thing the WndProc does is set the <code>Message.Result</code> to zero.</p>
  
  <p>i was hoping to assign a handler to a TApplicationEvents.OnMessage event:</p>
  
  <pre><code>procedure TdmGlobal.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
  begin
     case Msg.message of
     WM_SETTINGCHANGE:
        begin
           // Code
        end;
     end;
  end;
  </code></pre>
  
  <p>But the OnMessage event is only thrown for messages that come through the message pump. Since the <code>WM_SETTINGCHANGE</code> message is "handled", it never sees the</p>
  
  <pre><code>PeekMessage
  TranslateMessage
  DispatchMessage
  </code></pre>
  
  <p>system.</p>
  
  <p>How can i respond to the windows broadcast <code>WM_SETTINGCHANGE</code>?</p>