Delphi:如何响应WM_SettingChange/WM_WinIniChange? [英] Delphi: How to respond to WM_SettingChange/WM_WinIniChange?

查看:199
本文介绍了Delphi:如何响应WM_SettingChange/WM_WinIniChange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道我的应用程序何时收到 WM_SETTINGCHANGE 消息(以前称为 WM_WININICHANGE ).

i need to know when my application recieves a WM_SETTINGCHANGE message (formerly known as WM_WININICHANGE).

问题是 TApplication 中的消息泵将其发送到黑洞(默认处理程序)之前,我才有机会看到它:

Problem is that the message pump in TApplication sends it down a black hole (default handler) before i can get a chance to see it:

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;   <----------------------*poof* down the sink hole
         end;
      ...
      end;
      ...
end;

过程CheckIniChange()不会引发任何我可以处理的事件,Mouse.SettingChanged()也不会.

The procedure CheckIniChange() doesn't throw any event i can handle, neither does Mouse.SettingChanged().

并且一旦代码路径到达Default,它就会沿着DefWindowProc排水孔发送,再也不会被看到(因为WndProc所做的第一件事就是将Message.Result设置为零.

And once the code path reaches Default, it is sent down the DefWindowProc drain hole, never to be seen again (since the first thing the WndProc does is set the Message.Result to zero.

我希望将处理程序分配给TApplicationEvents.OnMessage事件:

i was hoping to assign a handler to a TApplicationEvents.OnMessage event:

procedure TdmGlobal.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
   case Msg.message of
   WM_SETTINGCHANGE:
      begin
         // Code
      end;
   end;
end;

但是仅对通过消息泵发送的消息引发OnMessage事件.由于WM_SETTINGCHANGE消息是已处理"的,因此它永远不会看到

But the OnMessage event is only thrown for messages that come through the message pump. Since the WM_SETTINGCHANGE message is "handled", it never sees the

PeekMessage
TranslateMessage
DispatchMessage

系统.

我该如何响应Windows广播WM_SETTINGCHANGE?

How can i respond to the windows broadcast WM_SETTINGCHANGE?

推荐答案

Edit2:对于较旧的版本,通常的消息拦截应起作用...

[...]
  private
    procedure WMSettingChange(var Message: TWMSettingChange); message WM_SETTINGCHANGE;
[...]
procedure TForm1.WMSettingChange(var Message: TWMSettingChange);
begin
  showMessage('SettingChange message intercept');
end;

糟糕!没有看到这是为D5. 以下是D2007 +版本.

Ooops! Did not see it was for D5. The following was in D2007+.

在应用程序中使用OnSettingChange:

Use an OnSettingChange in your Application:

procedure TApplication.SettingChange(var Message: TWMSettingChange);
begin
  if Assigned(FOnSettingChange) then
    with Message do
      FOnSettingChange(Self, Flag, Section, Result);
end;

您可以使用此代码进行测试.尝试更改任务栏的高度或对接面...

You can test with this code. Try and change the height or docking side of the TaskBar...

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnSettingChange := MySettingChange;
end;

procedure TForm1.MySettingChange(Sender: TObject; Flag: Integer;
  const Section: string; var Result: Integer);
begin
  showMessage('setting changed');
end;

这篇关于Delphi:如何响应WM_SettingChange/WM_WinIniChange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆