Reserve part of the desktop

后端 未结 1 856
醉话见心
醉话见心 2021-02-04 17:48

How can I reserve one edge of the desktop with Delphi? Something like the Vista Sidebar does.

1条回答
  •  有刺的猬
    2021-02-04 18:11

    What you want is called an application desktop toolbar

    You must use the TAppBarData Object declared in the ShellAPI unit and the SHAppBarMessage function.

    See this simple example.

    type
      TApplicationTaskBar = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        procedure CreateParams(var Params: TCreateParams); override;
      public
        { Public declarations }
      end;
    
    var
      ApplicationTaskBar: TApplicationTaskBar;
    
    implementation
    
    {$R *.dfm}
    
    Uses
    ShellAPI;
    
    procedure TApplicationTaskBar.CreateParams(var Params: TCreateParams);
    begin
      inherited;
      Params.ExStyle  := Params.ExStyle or WS_EX_TOOLWINDOW;
      Params.Style    := (Params.Style OR WS_POPUP) AND (NOT WS_DLGFRAME);  //Remove title Bar
    end;
    
    procedure TApplicationTaskBar.FormCreate(Sender: TObject);
    var
      MyTaskBar  : TAppBarData;
    begin
      GlassFrame.Enabled       :=True;//Activate Glass  , optional
      GlassFrame.SheetOfGlass  :=True;//optional
      Left:=0;
      Top :=0;
      Width := 300;
      Height:= Screen.Height;
      FillChar(MyTaskBar, SizeOf(TAppBarData), 0);
      MyTaskBar.cbSize := SizeOf(TAppBarData);
      MyTaskBar.hWnd   := Handle;
      MyTaskBar.uCallbackMessage := WM_USER+777;  //Define my own Mesaage
      MyTaskBar.uEdge  := ABE_LEFT;
      MyTaskBar.rc     := Rect(0, 0, Width, Height);
      SHAppBarMessage(ABM_NEW, MyTaskBar);
      SHAppBarMessage(ABM_ACTIVATE, MyTaskBar);
      SHAppBarMessage(ABM_SETPOS, MyTaskBar);
      Application.ProcessMessages;
    end;
    
    
    procedure TApplicationTaskBar.FormDestroy(Sender: TObject);
    var
      MyTaskBar : TAppBarData;
    begin
      FillChar(MyTaskBar, SizeOf(TAppBarData), 0);
      MyTaskBar.cbSize := SizeOf(TAppBarData);
      MyTaskBar.hWnd   := Self.Handle;
      SHAppBarMessage(ABM_Remove, MyTaskBar);
    end;
    

    Check this links

    • SHAppBarMessage
    • ABM_ACTIVATE
    • ABM_SETPOS
    • ABM_NEW

    Bye.

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