如何使表单像任务栏一样与屏幕边缘对齐? [英] How to make a form align to the edge of the screen like the taskbar?

查看:94
本文介绍了如何使表单像任务栏一样与屏幕边缘对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个仪表盘"应用程序,即使在其他应用程序已最大化的情况下,该应用程序也始终可以在任何给定监视器的任何边缘上看到.我不一定总是在最上面"需要它(尽管我会),但我需要使其成为屏幕的一部分,就像我自己的桌面工具栏一样,例如Windows任务栏.即使在最大化应用程序的情况下,窗口也位于该区域内,从而使该窗口始终可见(并且桌面区域较小).

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-我不需要所有额外的棘手处理,例如屏幕分辨率更改...我只需要知道如何首先将其对齐为屏幕的一部分"./p>

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.

推荐答案

您正在寻找 SHAppBarMessage .

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.

它可能会变得非常复杂,但是有一些免费的源组件可用(一个组件位于Torry DelphiPages 上的另一个具有基本外壳程序的网站让您开始.

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.

第二个链接的 AppBar.pas 单元中的一个示例(根据该链接的文本,它是带有源代码的免费软件-我已使用它来创建一个完整的应用启动器任务栏带有从 .lnk 文件中读取的带有应用程序图标和描述的按钮):

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;

这篇关于如何使表单像任务栏一样与屏幕边缘对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆