TActionMainMenuBar和TActionToolbar丢失设置 [英] TActionMainMenuBar and TActionToolbar lose settings

查看:338
本文介绍了TActionMainMenuBar和TActionToolbar丢失设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近偶然发现了一个非常奇怪的行为。当我在程序中使用TActionMainMenuBar(或TActionToolBar)时,编译并运行,然后启动Photoshop CS5或Internet Explorer 9,ActionMainMenuBar(和ActionToolBar)将丢失其所有设置。分配的色彩映射中定义的颜色消失,字体设置也会丢失。有没有人看过这个解决方法?



D2007 Pro(所有更新应用),D2010 Pro(所有更新应用),Vista Home Premium 32位,NVidia GForce 8600 GT,最新的驱动程序安装。



重现步骤:


  1. 删除TActionManager和表单上的TActionMainMenuBar

  2. 创建具有某些菜单项的类别

  3. 将类别拖动到ActionMainMenuBar

  4. 将TwilightColorMap分配给ActionMainMenuBar

  5. 运行程序

  6. 启动IE9或Photoshop CS5

  7. 观看所有预定义设置消失(您必须再次关闭IE9才能看到效果)

如果您先启动Photoshop或IE,然后再启动Delphi程序, 。在IDE中的设计模式下,该错误也会出现。其他开发人员已经使用Win7 Pro 32bit和ATI Radeon 9800 Pro确认了他的系统描述的行为。



Thx用于任何评论/解决方案



Phil



PS:使用Photoshop CS3不会产生此错误

解决方案

这是一个复制问题的方式:




  • 完成步骤1到4,如问题(包括删除TwilightColorMap)。

  • 在代码 Perform(WM_SETTINGCHANGE,0,0); 在其点击处理程序中。

  • 运行应用程序并按按钮。



>所以现在我们知道一个 WM_SETTINGCHANGE 广播可能会导致问题,我们可能会想知道启动IE是否产生相同的方法:

  type 
TForm1 = class(TForm)
..
protected
procedure WMSettingChange(var Message:TWMSettingChange);
message WM_SETTINGCHANGE;
..

程序TForm1.WMSettingChange(var Message:TWMSettingChange);
begin
Memo1.Lines.Add(IntToHex(Message.Flag,4)+','+ Message.Section);
继承;
结束

在我们运行我们的应用程序然后启动IE后,几秒钟后,下面显示在备忘录中:


0000,Software\Microsoft\Internet Explorer\SearchScopes


我不知道IE在每次启动时对我们的表单(和所有其他顶级窗口)说的话,我不知道是否在每个Windows机箱上这样做或者只是你和我的,但显然地, ActionMainMenuBar 没有好处理。




A赢取控制(表单),收到 WM_WININICHANGE ,执行 CM_WININICHANGE ,并且收到后将其广播到所有控制。以下是菜单栏如何处理:

 程序TCustomActionMainMenuBar.CMWininichange(var Message:TWMWinIniChange); 
开始
继承;
RequestAlign;
Font.Assign(Screen.MenuFont);
结束想想系统菜单字体可能已经改变了(代码应该已经找到了一个WindowsThemeElement),或消息中的WindowMetrics部分,但无论如何..),它从刷新的 Screen.MenuFont 中重新分配。问题是,我们没有完全使用它。



另外,ColorMap通过重新设置它来响应一个 CM_WININICHANGE 颜色通过调用其 UpdateColors 方法。这甚至是记录的


当ActionBand组件收到CM_WININICHANGE消息时,将自动调用UpdateColors




所以解决方案将涉及到决定要做什么并且超越这两种行为,我试图评论以下解决方案,为什么我认为这将是正确的解决方案: p>

 键入
//导出您自己的ColorMap将重置自己的颜色。
//这是一个简单的插件。
TTwilightColorMap = class(actncolormaps.TTwilightColorMap)
public
procedure UpdateColors;覆盖
发布
属性颜色默认clGreen;
属性FontColor默认clYellow;
属性MenuColor默认$ 4488FF;
//重新引入尽可能多的财产,大概所有必要的。
end;

TForm1 = class(TForm)
..
private
FSaveMenuFont:TFont; //将保存初始主菜单栏的字体设置
protected
procedure WMSettingChange(var Message:TWMSettingChange);
message WM_SETTINGCHANGE;
结束

..

procedure TForm1.FormCreate(Sender:TObject);
begin
FSaveMenuFont:= TFont.Create;
FSaveMenuFont.Assign(ActionMainMenuBar1.Font);
结束

procedure TForm1.FormDestroy(Sender:TObject);
begin
FSaveMenuFont.Destroy;
结束

程序TForm1.WMSettingChange(var Message:TWMSettingChange);
开始
继承;
//以下是* section * s,真正改变系统设置
//会通知我知道,可能会有更多...
if(Message.Section <>'WindowsThemeElement')
或(MessageSection<>'WindowMetrics')然后
ActionMainMenuBar1.Font.Assign(FSaveMenuFont)
else
//开发你的逻辑在这里系统菜单字体可能真的已经
//更改。你可以从Screen.MenuFont获取它。但是,如果我们已经使用系统字体
//,则控件已经默认应用更改。

end;

程序TTwilightColorMap.UpdateColors;
开始
继承;
//重新设置颜色,请注意,系统颜色可能已经
//已更改或不更改。如果改变,它们应该被反映在cl ..常量中。
颜色:= clGreen;
FontColor:= clYellow;
MenuColor:= $ 4488FF;
结束


I stumbled across a really weird behavior recently. When I use a TActionMainMenuBar (or a TActionToolBar) in my program, compile and run, and then start Photoshop CS5 or Internet Explorer 9, the ActionMainMenuBar (and ActionToolBar) loses all its settings. The colors defined in the assigned colormap disappear and the font settings are also lost. Has anyone seen this before and knows a workaround?

D2007 Pro (all updates applied), D2010 Pro (all updates applied), Vista Home Premium 32 bit, NVidia GForce 8600 GT, latest driver installed.

Steps to reproduce:

  1. Drop a TActionManager and a TActionMainMenuBar on a form
  2. Create a category with some menu items
  3. Drag category onto ActionMainMenuBar
  4. Assign TwilightColorMap to the ActionMainMenuBar
  5. Run program
  6. Start IE9 or Photoshop CS5
  7. Watch all predefined settings disappear (you have to close IE9 again to see the effect)

If you start Photoshop or IE first and then the Delphi program, nothing happens. The bug is also present when in design mode in the IDE. A fellow developer has already confirmed the described behavior for his system with Win7 Pro 32bit and a ATI Radeon 9800 Pro.

Thx for any comments/ solutions

Phil

PS: Using Photoshop CS3 doesn't produce this bug

解决方案

Here's one other way of reproducing the problem:

  • Complete steps 1 to 4 as in the question (including dropping a TwilightColorMap).
  • Add a button to the form with the code  Perform(WM_SETTINGCHANGE, 0, 0); in its click handler.
  • Run the application and press the button.


So now we know that a WM_SETTINGCHANGE broadcast might be causing the problem, we might wonder if launching IE produces the same:

type
  TForm1 = class(TForm)
    ..
  protected
    procedure WMSettingChange(var Message: TWMSettingChange);
      message WM_SETTINGCHANGE;
    ..

procedure TForm1.WMSettingChange(var Message: TWMSettingChange);
begin
  Memo1.Lines.Add(IntToHex(Message.Flag, 4) + ', ' + Message.Section);
  inherited;
end;

After we run our application and then launch IE, a few seconds later the below appears in the memo:

0000, Software\Microsoft\Internet Explorer\SearchScopes

I have no idea what IE has to say to our form (and all other top-level windows) at every launch, and I don't know if it is doing this on every Windows box on earth or just yours and mine, but evidently the ActionMainMenuBaris no good at handling it.


A win control (the form), receiving a WM_WININICHANGE, performs a CM_WININICHANGE and upon receiving it broadcasts the same to all its controls. The below is how it is handled by the menu bar:

procedure TCustomActionMainMenuBar.CMWininichange(var Message: TWMWinIniChange);
begin
  inherited;
  RequestAlign;
  Font.Assign(Screen.MenuFont);
end;

Thinking that the system menu font could have been changed (the code should have looked for a 'WindowsThemeElement' or 'WindowMetrics' section in the message, but anyway..), it is reassigned from the refreshed Screen.MenuFont. The problem is, we weren't exactly using it.

Additionally the ColorMap responds to a CM_WININICHANGE by resetting its colors by calling its UpdateColors method. This is even documented:

UpdateColors is called automatically when an ActionBand component receives a CM_WININICHANGE message.


So the solution would involve deciding what to do and overriding both behavior, I tried to comment the below solution for why I believe that it would be the correct solution:

type
  // Derive your own ColorMap that would reset its own colors.
  // This is an interposer for simplicity..
  TTwilightColorMap = class(actncolormaps.TTwilightColorMap)
  public
    procedure UpdateColors; override;
  published
    property Color default clGreen;
    property FontColor default clYellow;
    property MenuColor default $4488FF;
    // reintroduce as many property as necessary, probably all is necessary..
  end;

  TForm1 = class(TForm)
    ..
  private
    FSaveMenuFont: TFont; // will hold initial main menu bar's font settings
  protected
    procedure WMSettingChange(var Message: TWMSettingChange);
      message WM_SETTINGCHANGE;
  end;

..

procedure TForm1.FormCreate(Sender: TObject);
begin
  FSaveMenuFont := TFont.Create;
  FSaveMenuFont.Assign(ActionMainMenuBar1.Font);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FSaveMenuFont.Destroy;
end;

procedure TForm1.WMSettingChange(var Message: TWMSettingChange);
begin
  inherited;
  // The below are the *section*s that really changing system settings
  // would notify that I'm aware of, there may be more...
  if (Message.Section <> 'WindowsThemeElement')
      or (Message.Section <> 'WindowMetrics') then
    ActionMainMenuBar1.Font.Assign(FSaveMenuFont)
  else
    // Develop your logic here. The system menu font might really have been
    // changed. You can get it from Screen.MenuFont. But then if we had been
    // using the system font, the control already applies the change by default.

end;

procedure TTwilightColorMap.UpdateColors;
begin
  inherited;
  // Reset your colors, note that system colors might have been
  // changed or not. If changed, they should be reflected in 'cl..' constants.
  Color := clGreen;
  FontColor := clYellow;
  MenuColor := $4488FF;
end;

这篇关于TActionMainMenuBar和TActionToolbar丢失设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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