Reserve part of the desktop

好久不见. 提交于 2019-12-20 10:46:36

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/1553088/reserve-part-of-the-desktop

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