简体   繁体   English

如何使表单像任务栏一样与屏幕边缘对齐?

[英]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.我不一定需要它“始终在最前面”(尽管我会),但我需要将它作为我自己的桌面工具栏作为屏幕的一部分,就像 Windows 任务栏一样。 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. PS - 我不需要对所有额外的坚韧不拔的处理(例如屏幕分辨率更改)的答案……我只需要首先知道如何使其作为“屏幕的一部分”对齐。

You're looking for Application Desktop Toolbars , which is what the Windows task bar uses internally.您正在寻找Application Desktop Toolbars ,这是 Windows 任务栏内部使用的。 It involves creating a window with specific styles, setting it up correctly, and then communicating with it using SHAppBarMessage .它涉及创建一个具有特定样式的窗口,正确设置它,然后使用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.它可能会变得非常复杂,但是有一些带有源代码的免费组件(一个在Torry 上,另一个在DelphiPages 上),它们具有基本的 shell 来帮助您入门。

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):来自第二个链接的AppBar.pas单元的一个示例(根据链接的文本,它是带有源代码的免费软件 - 我用它来创建一个应用程序启动器任务栏,其中包含带有应用程序图标的按钮和从.lnk文件):

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;

If nothing else, you can determine this information manually.如果不出意外,您可以手动确定此信息。 Have a look at the global Screen object in the Forms unit for information on the current resolution.查看Forms单元中的全局Screen对象以获取有关当前分辨率的信息。 (Make sure to check the MonitorCount and Monitors properties.) (确保检查MonitorCountMonitors属性。)

Between that and a bit of basic arithmetic, it shouldn't be too hard to set up the form to align to the edge of a monitor.在这和一些基本算术之间,设置表格以与显示器的边缘对齐应该不会太难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM