简体   繁体   中英

Delphi 6 - TApplicationEvents.OnMinimize is not triggered by “Show Desktop”

I have a Delphi 6 Pro application that does certain things when the application is minimized. I do my work in the OnMinimize() event that belongs to a TApplicationEvents component. It works great when the Minimize button on the main window's control box is used, however, when the Windows XP Show Desktop button is used to minimize all active applications the OnMinimize() event is not triggered. Is there a way to fix this or am I going to have to do something messy in the main WndProc()?

-- roschler

Add

protected
  { Private declarations }
  procedure WMSize(var Message: TWMSize); message WM_SIZE;

where

procedure TForm1.WMSize(var Message: TWMSize);
begin
  if Message.SizeType = SIZE_MINIMIZED then
    beep;
end;

Alternatively, of course, you can just do

protected
  { Private declarations }
  procedure WndProc(var Message: TMessage); override;

where

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited;
  case Message.Msg of
    WM_SIZE:
      if Message.WParam = SIZE_MINIMIZED then
        beep;
  end;
end;

If I remember correctly, the problem with Delphi applications is that the main message handler doesn't belong to the "main" window, but to TApplication. At any rate, use something like WinSight to know which messages are being delivered to what when Show Desktop is triggered.

Apart from the answers which hopefully resolve your problem, I found this description on the Microsoft site:

By default, the Quick Launch toolbar also contains two special buttons. Click the Show Desktop button Picture of the Show Desktop icon to temporarily hide all open windows and show the desktop; click the button again to show all windows again.

From this I gather the Show Desktop doesn't actually minimize the windows at all; merely makes them invisible (by making the Z-order of the desktop topmost). In that case, it is correct your application doesn't receive the Minimize message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM