表单 – 如何检测WindowState更改?

表单 – 如何检测WindowState更改?,第1张

概述如何检测TCustomForm后代的WindowState更改?我希望在任何时候通过WindowState属性设置不同的值来通知我. 我已经检查了setter中是否有事件或虚拟方法,但我没有找到实现目标的任何内容. function ShowWindow; external user32 name 'ShowWindow';procedure TCustomForm.SetWindowStat 如何检测TCustomForm后代的windowstate更改?我希望在任何时候通过windowstate属性设置不同的值来通知我.

我已经检查了setter中是否有事件或虚拟方法,但我没有找到实现目标的任何内容.

function ShowWindow; external user32 name 'ShowWindow';procedure TCustomForm.Setwindowstate(Value: Twindowstate);const  ShowCommands: array[Twindowstate] of Integer =    (SW_SHOWnorMAL,SW_MINIMIZE,SW_SHOWMAXIMIZED);begin  if Fwindowstate <> Value then  begin    Fwindowstate := Value;    if not (csDesigning in ComponentState) and Showing then      ShowWindow(Handle,ShowCommands[Value]);  end;end;
解决方法 *** 作系统在状态发生变化时发送到窗口的通知是WM_SIZE消息.从你发布的代码报价中看不出来,但是VCL已经在TScrollingWinControl类(TCustomForm的上升)中监听WM_SIZE,并在处理消息时调用虚拟的Resizing过程.

因此,您可以覆盖表单的此方法以获得通知.

type  TForm1 = class(TForm)    ..  protected    procedure Resizing(State: Twindowstate); overrIDe;....procedure TForm1.Resizing(State: Twindowstate);begin  inherited;  case State of    Twindowstate.wsnormal: ;    Twindowstate.wsMinimized: ;    Twindowstate.wsMaximized: ;  end;end;

请注意,对于给定状态,可以多次发送通知,例如在调整窗口大小或可见性发生变化时.您可能需要跟踪先前的值以检测实际更改状态的时间.

根据您的要求,您还可以使用表单的OnResize事件.不同之处在于,在 *** 作系统通知窗口有关更改之前,会触发此事件.当TCustomForm正在处理WM_WINDOWPOSCHANGING时,VCL通过调用GetwindowPlacement来检索窗口状态信息.

下面是一个使用标志来跟踪先前窗口状态的示例.

TForm1 = class(TForm)    ..  private    FLastwindowstate: Twindowstate; // 0 -> wsnormal (initial value)...procedure TForm1.FormResize(Sender: TObject);begin  if windowstate <> FLastwindowstate then    case windowstate of      Twindowstate.wsnormal: ;      Twindowstate.wsMinimized: ;      Twindowstate.wsMaximized: ;    end;  FLastwindowstate := windowstate;end;
总结

以上是内存溢出为你收集整理的表单 – 如何检测WindowState更改?全部内容,希望文章能够帮你解决表单 – 如何检测WindowState更改?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1080581.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存