How to minimize a window to the taskbar? (i.e. not iconify)

前端 未结 2 1770
滥情空心
滥情空心 2020-12-09 06:53

i have a window that i want to minimize (to the taskbar), so i call ShowWindow:

ShowWindow(Handle, SW_MINIMIZE);

Except that r

相关标签:
2条回答
  • 2020-12-09 07:01

    A super simple solution is to disable the minimize icon on the FORM
    [Object inspector]-[Form properties]-[Border icons]-[biMinimize]
    The application can still be minimized and restore by clicking on the APPLICATION icon at the taskbar

    0 讨论(0)
  • 2020-12-09 07:17

    That icon on the taskbar is the icon of the Application (Handle) rather than that of the MainForm.

    Use:

    Application.Minimize;
    

    Edit: But out of both your links, I understand you knew that already...duh ;)

    This works for the MainForm:

    TForm1 = class(TForm)
    private
      procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
    protected
      procedure CreateParams(var Params: TCreateParams); override;
    
    ...
    
    procedure TForm1.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      with Params do
      begin
        ExStyle := ExStyle or WS_EX_APPWINDOW;
        WndParent := GetDesktopWindow;
      end;
    end;
    
    procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
    begin
      if Msg.CmdType = SC_MINIMIZE then
        ShowWindow(Handle, SW_MINIMIZE)
      else
        inherited;
    end;
    

    And to hide Application.Handle from the taskbar (to only have a taskbar icon for the MainForm): set the Visible property of this Form to True and hide the Application in the project file:

    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    ShowWindow(Application.Handle, SW_HIDE);
    Application.Run;
    

    For this form, ShowWindow(Handle, SW_MINIMIZE); shóuld work. It also provides for the default zooming-feature of Windows when minimizing or restoring.

    (Tested with D5 & D7 on XP and W7)

    0 讨论(0)
提交回复
热议问题