1,183
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
HTrayWnd, HReBar, HBtnStar, ReplaceBtnHwnd, HNotifyWnd: HWND;
TrayWndRct, ReBarTct, BtnStarTct, NotifyWndTct: TRect;
procedure SetPosition;
procedure GetTraySize;
procedure CreateButton;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
HTrayWnd := FindWindow('Shell_TrayWnd', nil);
HReBar := FindWindowEx(HTrayWnd, 0, 'ReBarWindow32', nil);
HNotifyWnd := FindWindowEx(HTrayWnd, 0, 'TrayNotifyWnd', nil);
if Win32MajorVersion < 6 then
begin
HBtnStar := FindWindowEx(HTrayWnd, 0, 'Button', nil);
end
else
begin
HBtnStar := FindWindow('Button', nil);
end;
CreateButton;
end;
procedure TForm1.GetTraySize;
begin
try
if (Windows.GetWindowRect(HReBar, ReBarTct) = false) or (Windows.GetWindowRect(HTrayWnd, TrayWndRct) = false)
or (Windows.GetWindowRect(HBtnStar, BtnStarTct) = false)
or (Windows.GetWindowRect(HNotifyWnd, NotifyWndTct) = false)
then
begin
Application.MessageBox('错误,初始化获取数据失败,程序退出。', Pchar(Application.Title), MB_OK + MB_ICONERROR);
Application.Terminate;
Application.ShowMainForm := False;
end;
except
end;
end;
procedure TForm1.SetPosition;
var
BisWidth: Boolean;
begin
try
GetTraySize;
if TrayWndRct.Right - TrayWndRct.Left > TrayWndRct.Bottom - TrayWndRct.Top then //判断人无论是横向还是纵向
BisWidth := True
else
BisWidth := False;
if BisWidth then
begin
MoveWindow(Self.Handle, BtnStarTct.Right + 5, (TrayWndRct.Bottom - TrayWndRct.Top - Self.Height) div 2, 75, 25, true);
MoveWindow(HReBar, 75 + 5 + BtnStarTct.Right + 5, 0, NotifyWndTct.Left - 75 - 10 - BtnStarTct.Right, ReBarTct.Bottom - ReBarTct.Top, True)
end
else
begin
MoveWindow(Self.Handle, (TrayWndRct.Right - TrayWndRct.Left - Self.Width) div 2, BtnStarTct.Bottom + 3, 75, 25, true);
MoveWindow(HReBar, 0, BtnStarTct.Bottom + 25 + 6, ReBarTct.Right - ReBarTct.Left, NotifyWndTct.Top - 6 - 25 - BtnStarTct.Bottom, True);
end;
except
end;
end;
procedure TForm1.CreateButton;
begin
try
Self.ParentWindow := HTrayWnd;
Self.Visible := true;
Self.Width := 75;
Self.Height := 25;
Self.Left := -100;
Self.Caption := '';
SetPosition;
except
end;
end;
end.