2
votes

Minimizing an FMX form with the menu bar button and then restoring by clicking on the task bar icon will bring the form back to the foreground, but will not activate the window. The form is also minimized "directly" rather applying the animation that "shrinks" the window to the taskbar. The forms OnActivate event is not fired.

Curiously, if I patch the WindowProc and call ShowWindow with SW_RESTORE upon deactivation the form will get restored properly after clicking the taskbar icon. I'm not sure why. The minimize animation still does not get fired though.

procedure TForm1.WindowProc(var Msg: TMessage);
begin
  case Msg.Msg of
    WM_ACTIVATE: if (Msg.WParamLo = WA_INACTIVE) then ShowWindow(WindowHandleToPlatform(Handle).Wnd, SW_RESTORE);
  end;
  Msg.Result := CallWindowProc(OrgWndProc, WindowHandleToPlatform(Handle).Wnd, Msg.Msg, Msg.WParam, Msg.LParam);
end;

I can observe this behavior with a blank FMX HD form on Windows 8. This seems like an obvious bug to me, is there a better way to work around it ?

2
What version of FMX?rhody
It's XE5 update 2 if that's what you mean, I'm not aware of distinct versioning for FMX.DNR
Agreed, thats what I meant.rhody

2 Answers

1
votes

I think I got around this by modifying the FMX.Platform.Win.pas file. In the TPlatformWin.CreateAppHandle method you need to comment (or remove) those lines:

FApplicationHWND := CreateWindowEx(WS_EX_WINDOWEDGE or WS_EX_APPWINDOW, FMAppClass.lpszClassName,
  PChar(LApplicationTitle), WS_POPUP or WS_GROUP, 0, 0, 0, 0, GetDesktopWindow, 0, HInstance, nil);
Winapi.Windows.ShowWindow(FApplicationHWND, SW_SHOWNORMAL);

I think that solution came from the Embarcadero Discussion Forums. The message is gone, but I give you the link anyway in case it comes back: https://forums.codegear.com/thread.jspa?messageID=556541&#556541

-1
votes
procedure Tmainform.FormMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Single);
var
h:thandle;
  begin
  h:=FmxHandleToHWND(Handle);
      if getforegroundwindow <> h then
      begin
        SetForeGroundWindow(h);
        BringWindowToTop(h);
        SetCursorPos(Left + round(X), Top + round(Y));
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;