FIX: Access violation when restoring main window from tray.

This commit is contained in:
cobines 2009-09-15 13:00:11 +00:00
commit 3fffec93b8

View file

@ -422,6 +422,7 @@ type
DrivesList : TList;
MainSplitterHintWnd: THintWindow;
HiddenToTray: Boolean;
HidingTrayIcon: Boolean; // @true if the icon is in the process of hiding
nbLeft, nbRight: TFileViewNotebook;
// frost_asm begin
@ -437,6 +438,7 @@ type
procedure HideToTray;
procedure RestoreFromTray;
procedure ShowTrayIcon(bShow: Boolean);
procedure HideTrayIconDelayed(Data: PtrInt);
procedure OperationFinishedEvent(Operation: TFileSourceOperation; Event: TOperationManagerEvent);
@ -550,6 +552,7 @@ begin
nbRight := CreateNotebook(pnlRight, fpRight);
HiddenToTray := False;
HidingTrayIcon := False;
inherited;
// frost_asm begin
@ -973,14 +976,18 @@ end;
procedure TfrmMain.MainTrayIconClick(Sender: TObject);
begin
if WindowState = wsMinimized then
// Only react to clicks if the icon is not scheduled to be hidden.
if not HidingTrayIcon then
begin
RestoreFromTray;
end
else
begin
MinimizeWindow;
HideToTray;
if WindowState = wsMinimized then
begin
RestoreFromTray;
end
else
begin
MinimizeWindow;
HideToTray;
end;
end;
end;
@ -3241,12 +3248,30 @@ end;
procedure TfrmMain.ShowTrayIcon(bShow: Boolean);
begin
if bShow <> MainTrayIcon.Visible then
if (bShow <> MainTrayIcon.Visible) and (HidingTrayIcon = False) then
begin
MainTrayIcon.Visible := bShow;
if bShow then
begin
MainTrayIcon.Visible := True;
end
else
begin
// ShowTrayIcon might be called from within OnClick event of the icon
// (MainTrayIconClick->RestoreFromTray->ShowTrayIcon), so the MainTrayIcon
// cannot be hidden here, because it would be destroyed causing A/V.
// Hiding it must be delayed until after the mouse click handler of the icon is finished.
HidingTrayIcon := True;
Application.QueueAsyncCall(@HideTrayIconDelayed, 0);
end;
end;
end;
procedure TfrmMain.HideTrayIconDelayed(Data: PtrInt);
begin
MainTrayIcon.Visible := False;
HidingTrayIcon := False;
end;
procedure TfrmMain.EnableHotkeys(Enable: Boolean);
begin
// KeyPreview should be always enabled.