How to properly restore an FMX form?

自古美人都是妖i 提交于 2019-12-11 03:57:23

问题


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 ?


回答1:


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




回答2:


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;


来源:https://stackoverflow.com/questions/26313956/how-to-properly-restore-an-fmx-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!