个人网站开发总结文档,企业建设电子商务网站的目的,seo搜索排名优化公司,电影网站建设多少钱问题来源
最近在写一个播放器#xff0c;想到以前其他平台的播放器#xff0c;在隐藏主界面后#xff0c;如最小化为MiniBox或隐藏到托盘后#xff0c;切换歌曲操作很麻烦#xff0c;快捷键经常被这个那个软件占有#xff0c;不方便#xff0c;而且MiniBox又在我本就不…问题来源
最近在写一个播放器想到以前其他平台的播放器在隐藏主界面后如最小化为MiniBox或隐藏到托盘后切换歌曲操作很麻烦快捷键经常被这个那个软件占有不方便而且MiniBox又在我本就不大的屏幕上晃来晃去碍眼于是有了这样的想法。
经过搜索一番发现实现起来很简单于是写了一些代码实现了这个功能以下为效果图
任务栏分析
本次要操作的是将包含了一些控件的窗体置入任务栏实际上任务栏分了很多区域包括时钟区窗口最小化的区托盘区等等这次计划置入的是窗口切换区。
任务栏最外层的壳A壳A包含了以上说的区域。 其下再有窗口切换区的壳B 壳B下再有一个区为窗口最小化存放的位置C就像俄罗斯套娃一样分为一层又一层 我们的窗口F就要放在和C平级的位置也就是说窗口是放在B上面的B是窗口F的承载容器。 这里注意B和C在我的截图里看起来差不多其实不一样因为B是C的容器而此时只有C一个子类因此看起来差不多但是我们可以把C的大小进行调整留出一些位置给我们的窗口F。
这样我们得到的结构就可以如下图一样 首先获取A,B,C三个层的句柄记为MainH, FirH, SecH类型为THandle。 然后获取A,B,C三个层的区域记为MainR, FirR, SecR类型为TRect。 然后使用MoveWindow函数调整层次C的宽度预留一部分位置放置窗口F。 然后将窗体置入并调整位置。 最后在程序退出时候将C层宽度调整回来恢复正常状态。
代码如下
unit Unit1;interfaceusesWinapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;typeTForm1 class(TForm)Button1: TButton;Button2: TButton;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varMainH, FirH, SecH: THandle;MainR, FirR, SecR: TRect;Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
beginMainH : FindWindow(PChar(Shell_TrayWnd), nil); //Shell_TaryWnd句柄A层FirH : FindWindowEX(MainH, 0, ReBarWindow32, nil); //ReBarWindow32句柄B层SecH : FindWindowEX(FirH, 0, MSTaskSwWClass, nil); //MSTaskSwWClass最小化窗口层句柄C层GetWindowRect(MainH, MainR);GetWindowRect(FirH, FirR);GetWindowRect(SecH, SecR);MoveWindow(SecH, 0, 0, SecR.Right - SecR.Left - Self.Width, SecR.Bottom - SecR.Top, True); //预留放置窗口的位置Self.ParentWindow : FirH;MoveWindow(Self.Handle, SecR.Right - SecR.Left - Self.Width 1, (FirR.Bottom - FirR.Top - Self.Height) div 2, Self.Width, Self.Height, True);Self.Visible : True;
end;procedure TForm1.Button2Click(Sender: TObject);
beginMoveWindow(SecH, 0, 0, SecR.Right - SecR.Left, SecR.Bottom - SecR.Top, True);Application.Terminate;
end;end.设计期界面如下 运行效果如下 为了让程序透明化显示用了窗体的穿透属性窗体配置如下
object Form1: TForm1Left 0Top 0BorderStyle bsNoneCaption Form1ClientHeight 30ClientWidth 100Color clFuchsiaTransparentColor TrueTransparentColorValue clFuchsiaFont.Charset DEFAULT_CHARSETFont.Color clWindowTextFont.Height -11Font.Name TahomaFont.Style []OldCreateOrder FalsePixelsPerInch 96TextHeight 13object Button1: TButtonLeft 4Top 5Width 40Height 20Caption DOTabOrder 0OnClick Button1Clickendobject Button2: TButtonLeft 56Top 5Width 40Height 20Caption CloseTabOrder 1OnClick Button2Clickend
end以上便是Delphi中对于置入窗体到任务栏的基本方法希望对后来者有用 【参考文章】 https://blog.csdn.net/Factor_/article/details/84799332 https://www.cnblogs.com/luoshupeng/archive/2011/08/23/2151081.html