Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

delphi - How to make a form align to the edge of the screen like the taskbar?

I'm building a "dashboard" application which is always visible along any edge of any given monitor, even when other applications are maximized. I don't necessarily need it "always on top" (although I will) but I need to make it a part of the screen as my own desktop toolbar, like the Windows Taskbar is. Even when applications are maximized, the windows are inside of this area, making this window always visible (and the desktop area smaller).

How can I make my application's main form align to the edge of a screen like this?

PS - I don't need an answer to all the extra gritty handling, such as screen resolution changes... I just need to know how to make it aligned as "part of the screen" in the first place.

question from:https://stackoverflow.com/questions/65947906/in-delphi-how-do-you-make-a-form-stay-above-all-other-applications

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're looking for Application Desktop Toolbars, which is what the Windows task bar uses internally. It involves creating a window with specific styles, setting it up correctly, and then communicating with it using SHAppBarMessage.

It can get pretty complex, but there are some free components available with source (one at Torry, or another at DelphiPages) that have the basic shell to get you started.

An example from the AppBar.pas unit of the second link (which, according to the link's text, is freeware with source - I've used it to create an app launcher task bar, complete with buttons with application icons and descriptions read from .lnk files):

type
  TAppBarMessage = (abmNew, abmRemove, abmQueryPos, abmSetPos, abmGetState, 
                    abmGetTaskBarPos, abmActivate, abmGetAutoHideBar, 
                    abmSetAutoHideBar, abmWindowPosChanged);

  TAppBarEdge = (abeLeft, abeTop, abeRight, abeBottom, abeUnknown, abeFloat);

...

function TAppBar.AppBarMessage(abMessage: TAppBarMessage; 
  abEdge: TAppBarEdge; lParam: LPARAM; bRect: Boolean; var rc: TRect): UINT;
var
  abd: TAppBarData;
begin
  // Initialize an APPBARDATA structure
  abd.cbSize := sizeof(abd);
  abd.hWnd := Handle;
  abd.uCallbackMessage := WM_APPBARNOTIFY;
  abd.uEdge := Ord(abEdge);

  if bRect then
    abd.rc := rc
  else
    abd.rc := Rect(0, 0, 0, 0);

  abd.lParam := lParam;
  Result := SHAppBarMessage(Ord(abMessage), abd);

  // If the caller passed a rectangle, return the updated rectangle
  if bRect then
    rc := abd.rc;
end;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...