大家有没有用过八戒桌面软件,看了下,它好像可以程序来实现(100分)

  • 主题发起人 主题发起人 oliver99
  • 开始时间 开始时间
O

oliver99

Unregistered / Unconfirmed
GUEST, unregistred user!
大家有没有用过八戒桌面软件,看了下,它好像可以程序来实现
官方地址是:
http://www.8-jie.cn/
每个小工具,都是脚本的方式,里面还是delphi的代码,大家有没有实现过?
一起研究研究!
 
好像没有源码,做得确实漂亮。
 
虽然是广告贴,但软件的功能做得不错,值得学习,特别是界面搞得好。
 
TO:luoyanqing119,
晕,不是广告贴。
你试了没?在每个小工具上,点击右键,编辑,就会看到delphi的代码了,
在Widgets文件夹下的每个文件夹里,都有一个Script.xsf文件,打开看,里面是delphi的代码,如:Widgets/Dock/Script.xsf
大家有没有这文件的研究?
const
Section='Default';

var
//IconCount, //当前图标数
//IconMaxCount, //最大图标数
DefIconSize, //默认图标大小
MaxIconSize, //最大图标大小
CurrentMaxIconSize, //显示动画时的最大图标大小,实现处理使用的是这个变量
CurrentIconSize, //当前鼠标所在图标的大小
MouseLeft,MouseTop,MouseRight,MouseBottom, //应用鼠标效果的区域
bgLeft,bgTop,bgWidth,bgHeight, //背景图片的显示区域
do
ckLeft,dockTop, //DOCK图标的显示区域
SepTop,SepBottom,SepLeft,SepRight, //背景上下左右的空格
ZoomIconCount, //同时缩放的图标数量
DelaySpeed, //动画的速度
CurrentIconIndex //鼠标当前位置的图标索引
:integer;
rbg, rIcons:TRect;

Layout:string;
//DOCK的显示位置:上下左右等10个位置
MouseIn, //判断鼠标是否在区域内
isVert:boolean;
//纵向显示
ZoomIn,ZoomOut:boolean;
//Icons;
//图标数组
Icos:TStrings;
DelayTimes, //动画次数变量
mx,my:integer;
//鼠标位置
tmr:TTimer;
isIniting:boolean;
//判断是否正在初始化中
DataFileName,ShortcutIconPath:string;
//图标对话窗用到的控件
frm:TForm;
edtCaption,edtPath:TEdit;
cbbAction:TComboBox;
imgPreview:TxspImage;
SkinName:string;
AniStyle:integer;
sControlPanelGUID:string;
//--- PopMenu 相关函数 ----------------------------
//系统默认已经定义了__PopupMenu的组件,只需直接调用即可
function PopMenu_Add(aCaption:string;
aFunctionName:string;
aTag:integer):TMenuItem;
begin
result:=nil;
if trim(aCaption)='' then
exit;
result:=TMenuItem.Create(Widget);
result.caption:=aCaption;
result.OnClick:=aFunctionName;
result.Tag:=aTag;
__PopupMenu.items.Add(result);
end;

procedure PopMenu_AddChild(aParentMenu:TMenuItem;
aCaption:stirng;
aFunctionName:string;
aTag:integer);
var
mi:TMenuItem;
begin
if aParentMenu=nil then
exit;
mi:=TMenuItem.Create(Widget);
mi.caption:=aCaption;
mi.OnClick:=aFunctionName;
mi.Tag:=aTag;
aParentMenu.add(mi);
end;

procedure PopMenu_Clear;
begin
__PopupMenu.Items.Clear;
end;

procedure PopMenu_Popup;
//菜单弹出
begin
__PopupMenu.Popup(Mouse.CursorPos.x,Mouse.CursorPos.y);
end;

function GetRelativePath(value:string):string;
begin
result:=StrReplace(LowerCase(value),LowerCase(WidgetPath),'');
end;
//-------------------------------------------------
function NewIconImage:TxspImage;
var
i:integer;
begin
result:=TxspImage.Create(Widget);
result.parent:=Widget;
result.width:=DefIconSize;
result.height:=DefIconSize;
result.onclick:='ImgClick';
result.OnMouseMove:='WidgetMouseMove';
result.ImageStyle.Quality:=xqHigh;
result.ImageStyle.StretchStyle:=xsStretch;
//result.hint:='icon'+inttostr(i);
//result.visible:=true;
i:=icos.AddObject('',result);
result.Tag:=i;
end;

//获取指定文件的图标文件
function GetFileIcon(aFile:string):string;
var
sFileName,sExt,sFile,s:string;
begin
result:='';
if (length(aFile)=3) and (copy(aFile,2,2)=':/') then
sFileName:=aFile
else
sFileName:=ExtractFileName(aFile);
sFile:=ChangeFileExt(sFileName,'');
sExt:=LowerCase(ExtractFileExt(sFileName));
sExt:=copy(sExt,2,length(sExt)-1);
case sExt of
'wav','mid','rm': sExt:='mp3';
'html': sExt:='htm';
'lnk' : //如果是快捷方式就取出直接的文件名
begin
sFileName:=ExtractFileName(GetShortCutExeFile(aFile));
sFile:=ChangeFileExt(sFileName,'');
sExt:=LowerCase(ExtractFileExt(sFileName));
sExt:=copy(sExt,2,length(sExt)-1);
end;
end;
s:=WidgetPath+'images/soft/'+sExt+'.png';
//showtrayhint(sExt,sFile);
if FileExists(s) then
result:=s
else
begin
s:=WidgetPath+'images/soft/'+sFile+'.png';
if FileExists(s) then
result:=s
else
begin
//showmsg('disk:'+aFile);
if (length(aFile)=3) and (copy(aFile,2,2)=':/') then
result:=WidgetPath+'images/soft/disk.png'
else
if DirectoryExists(aFile) then
result:=WidgetPath+'images/soft/Documents.png';
end;
end;
end;

procedure RefreshShortcut;
var
ini:TIniFile;
FirstIndex:integer;
begin
ini:=TIniFile.create(DataFileName);
try
begin
for i:=0 to Icos.count-1do
begin
if i<Icos.count then
begin
TxspImage(icos.Objects).visible:=true;
TxspImage(icos.Objects).tag:=i;
TxspImage(icos.Objects).hint:=ini.ReadString(Section,inttostr(i)+'caption','');
s:=ini.ReadString(Section,inttostr(i)+'path','');
if FileExists(s) then
TxspImage(icos.Objects).FileName:=s
else
if FileExists(WidgetPath+s) then
TxspImage(icos.Objects).FileName:=WidgetPath+s
else
TxspImage(icos.Objects).FileName:=WidgetPath+'images/icon'+inttostr(i)+'.png';
end
else
begin
TxspImage(icos.Objects).FileName:='';
TxspImage(icos.Objects).visible:=false;
end;
end;
end;
finally
ini.free;
end;
end;

//添加快捷方式(名称/动作/图片路径)
procedure AddIco(caption:string;
Action:string;
IcoPath:string);
var
lst:TStrings;
i:integer;
sIndex,s1,s2:string;
sCaption,sAction,sIcoPath:string;
ini:TIniFile;
begin
if Action='' then
exit;
ini:=TIniFile.create(DataFileName);
try
sIndex:=inttostr(Icos.count);
sCaption:=Caption;
sAction:=Action;
if LowerCase(ExtractFileExt(sAction))='.lnk' then
//文件是快捷方式(lnk),则取回快捷方式的实际文件
sAction:=GetShortCutExeFile(sAction);

if not FileExists(IcoPath) then
sIcoPath:=WidgetPath+IcoPath
else
sIcoPath:=IcoPath;
if not FileExists(sIcoPath) then
sIcoPath:=WidgetPath+'images/default.png';
//如果是自定义好的快捷方式则直接保存
if (caption<>'') and (Action<>'') and (sIcoPath<>'') then
begin
ini.WriteString(Section,sIndex+'caption',sCaption);
ini.WriteString(Section,sIndex+'action',sAction);
ini.WriteString(Section,sIndex+'path',GetRelativePath(sIcoPath));
NewIconImage;
ini.WriteInteger(Section,'count',icos.count);
if FileExists(sIcoPath) then
TxspImage(icos.Objects[icos.count-1]).FileName:=sIcoPath
else
TxspImage(icos.Objects[icos.count-1]).FileName:=WidgetPath+sIcoPath;
exit;
end;
//如果不是则自动分析
if DirectoryExists(Action) or FileExists(Action) then
sAction:=sAction
else
if (length(Action)=3) and (copy(Action,2,2)=':/') then
sAction:=sAction
else
sAction:=ExtractFileName(Action);
if Caption = '' then
sCaption := ChangeFileExt(ExtractFileName(Action),'');
if sCaption = '' then
sCaption := Action;
ini.WriteString(Section,sIndex+'caption',sCaption);
ini.WriteString(Section,sIndex+'action',sAction);
//分析图标
s2:=GetFileIcon(Action);
if s2<>'' then
begin
//如果能取到默认图标,则直接保存
ini.WriteString(Section,sIndex+'path',GetRelativePath(s2));
//if ShortcutNums<imgCount then
end
else
//当没有默认的图标可以使用时,提取文件中的图标或使用默认图标
begin
s1:=ShortcutIconPath+ExtractFileName(ChangeFileExt(Action,''));
s2:=s1+'.png';
if FileExists(s1+'.png') then
//如果文件名存在,自动添加顺序号
for i:=1 to 100do
begin
s2:=s1+inttostr(i)+'.png';
if not FileExists(s2) then
break;
end;
if GetFileIconToPng(Action,s2) then
begin
ini.WriteString(Section,sIndex+'path',GetRelativePath(s2));
//if ShortcutNums<imgCount then
end
else
ini.WriteString(Section,sIndex+'path',WidgetPath+'images/default.png');
end;

NewIconImage;
s2:=ini.ReadString(Section,sIndex+'path','');
if FileExists(s2) then
TxspImage(icos.Objects[icos.count-1]).FileName:=s2
else
TxspImage(icos.Objects[icos.count-1]).FileName:=WidgetPath+s2;
ini.WriteInteger(Section,'count',icos.count);
finally
ini.free;
end;
end;

//添加单个文件到面板
procedure AddFileTofrm;
var
OpenDialog:TOpenDialog;
sFileName:string;
begin
Opendialog := Topendialog.Create(nil);
Opendialog.Filter := 'all Files|*.*';
Try
if Opendialog.Execute then

begin
sfilename:=Opendialog.Filename;
// Sfilename := Extractfilepath(Opendialog.Filename)+extractfilename(Opendialog.Filename);
if Fileexists(Sfilename) then
begin
Addico('',sfilename,'');
end
else
Showmsg('文件不存在!');
end;
Finally
Opendialog.Free;
end;
end;

//菜单中默认快捷的点击事件
procedure addIconMenuClick(sender: TObject);
var
OpenDialog:TOpenDialog;
sPathName:string;
i:integer;
p:pchar;
begin
bMenuPopUp:=False;
sPathName:='';
case TMenuItem(sender).tag of
0:AddFileTofrm;
1: if SelectDirectory('浏览文件夹',sPathName) then
Addico('',sPathName,'');
2: AddIco('我的电脑','::{20D04FE0-3AEA-1069-A2D8-08002B30309D}','images/soft/computer.png');
3: AddIco('我的文档','::{450D8FBA-AD25-11D0-98A8-0800361B1103}','images/soft/Documents.png');
4: AddIco('网上邻居','::{208D2C60-3AEA-1069-A2D7-08002B30309D}','images/soft/network.png');
5: AddIco('控制面板',sControlPanelGUID,'images/soft/controlpanel.png');
6: AddIco('IE浏览器','explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}','images/soft/IExplore.png');
7: AddIco('拨号上网','Rasphone.exe','images/soft/Rasphone.png');
8: AddIco('回收站','::{645FF040-5081-101B-9F08-00AA002F954E}','images/soft/Recycled.png');
9: AddIco('CMD','cmd','images/soft/cmd.png');
10: AddIco('运行','rundlg','images/soft/run.png');
11: AddIco('查找文件','findfiles','images/soft/findfiles.png');
12: AddIco('最小化','MinimizeAll','images/soft/MinimizeAll.png');
13: AddIco('任务管理器','TaskMgr','images/soft/TaskMgr.png');
14: AddIco('关机','shutdown','images/soft/shutdown.png');
15: AddIco('重启','restart','images/soft/restart.png');
16: AddIco('注销','logoff','images/soft/logoff.png');
17: AddIco('休眠/待机','standby','images/soft/standby.png');
18: AddIco('切换系统用户','switchuser','images/soft/switchuser.png');
19: AddIco('锁定系统','lock','images/soft/lock.png');
20: AddIco('Word','winword','images/soft/word.png');
21: AddIco('Excel','excel','images/soft/excel.png');
22: AddIco('Outlook','outlook','images/soft/outlook.png');
23: AddIco('Access','msaccess','images/soft/access.png');
24: AddIco('PowerPoint','powerpnt','images/soft/powerpoint.png');
25: AddIco('计算器','calc','images/soft/calc.png');
-2:
begin
for i:= 2 to 24do
begin
TComponent(sender).tag := i;
addIconMenuClick(sender);
end;
end;
-5:
begin
for i:= 2 to 8do
begin
TComponent(sender).tag := i;
addIconMenuClick(sender);
end;
end;
-6:
begin
for i:= 9 to 13do
begin
TComponent(sender).tag := i;
addIconMenuClick(sender);
end;
end;
-7:
begin
for i:= 14 to 19do
begin
TComponent(sender).tag := i;
addIconMenuClick(sender);
end;
end;
-8:
begin
for i:= 20 to 24do
begin
TComponent(sender).tag := i;
addIconMenuClick(sender);
end;
end;
end;
{RefreshPageInfo;}
RefreshShortcut;
end;

//初始化默认的快捷方式菜单
procedure InitShortcutMenu;
var
p:TMenuItem;
begin
bMenuPopUp:=true;
//function PopMenu_Add(aCaption:string;
aFunctionName:string;
aTag:integer):TMenuItem;
//procedure PopMenu_AddChild(aParentMenu:TMenuItem;
aCaption:stirng;
aFunctionName:string;
aTag:integer);
PopMenu_Clear;
PopMenu_Add('添加文件...','addIconMenuClick',0);
PopMenu_Add('添加文件夹...','addIconMenuClick',1);
PopMenu_Add('添加以下全部','addIconMenuClick',-2);
PopMenu_Add('-','',0);
p:=PopMenu_Add('添加系统图标类','',0);
PopMenu_AddChild(p,'添加此类全部','addIconMenuClick',-5);
PopMenu_AddChild(p,'-','',0);
PopMenu_AddChild(p,'添加 我的电脑','addIconMenuClick',2);
PopMenu_AddChild(p,'添加 我的文档','addIconMenuClick',3);
PopMenu_AddChild(p,'添加 网上邻居','addIconMenuClick',4);
PopMenu_AddChild(p,'添加 控制面板','addIconMenuClick',5);
PopMenu_AddChild(p,'添加 IE浏览器','addIconMenuClick',6);
PopMenu_AddChild(p,'添加 拨号上网','addIconMenuClick',7);
PopMenu_AddChild(p,'添加 回收站','addIconMenuClick',8);
p:=PopMenu_Add('添加常用操作类','',0);
PopMenu_AddChild(p,'添加此类全部','addIconMenuClick',-6);
PopMenu_AddChild(p,'-','',0);
PopMenu_AddChild(p,'添加 CMD命令行','addIconMenuClick',9);
PopMenu_AddChild(p,'添加 运行对话框','addIconMenuClick',10);
PopMenu_AddChild(p,'添加 查找文件对话框','addIconMenuClick',11);
PopMenu_AddChild(p,'添加 最小化所有窗口','addIconMenuClick',12);
PopMenu_AddChild(p,'添加 任务管理器','addIconMenuClick',13);
PopMenu_AddChild(p,'-','',0);
PopMenu_AddChild(p,'添加 计算器','addIconMenuClick',25);
p:=PopMenu_Add('添加关机操作类','',0);
PopMenu_AddChild(p,'添加此类全部','addIconMenuClick',-7);
PopMenu_AddChild(p,'-','',0);
PopMenu_AddChild(p,'添加 关机','addIconMenuClick',14);
PopMenu_AddChild(p,'添加 重启','addIconMenuClick',15);
PopMenu_AddChild(p,'添加 注销','addIconMenuClick',16);
PopMenu_AddChild(p,'添加 休眠/待机','addIconMenuClick',17);
PopMenu_AddChild(p,'添加 切换系统用户','addIconMenuClick',18);
PopMenu_AddChild(p,'添加 锁定系统','addIconMenuClick',19);
p:=PopMenu_Add('添加Office类','',0);
PopMenu_AddChild(p,'添加此类全部','addIconMenuClick',-8);
PopMenu_AddChild(p,'-','',0);
PopMenu_AddChild(p,'添加 Word','addIconMenuClick',20);
PopMenu_AddChild(p,'添加 Excel','addIconMenuClick',21);
PopMenu_AddChild(p,'添加 Outlook','addIconMenuClick',22);
PopMenu_AddChild(p,'添加 Access','addIconMenuClick',23);
PopMenu_AddChild(p,'添加 PowerPoint','addIconMenuClick',24);
PopMenu_Popup;
end;

//--- 属性窗口 ---
//显示快捷方式属性(动态创建属性窗口)
procedure ShowShortcutProperty(index:integer);
var
aIndex:integer;
ini:TIniFile;
s,sCaption,sAction,sPath:string;
btnOK,btnCancel,btnSelFile,btnSelPic:TButton;
lblNo:TLabel;
begin
aIndex:=index;
if (aIndex<0) or (aIndex>=icos.count) then
exit;
ini:=TIniFile.create(DataFileName);
try
s:=inttostr(aIndex);
sCaption:=ini.ReadString(Section,s+'caption','');
sAction:=ini.ReadString(Section,s+'action','');
sPath:=ini.ReadString(Section,s+'path','');
finally
ini.free;
end;

frm:=TForm.create(nil);
frm.width:=400;
frm.height:=230;
frm.Position:=poScreenCenter;
frm.caption:='快捷方式属性';
if screen.fonts.indexof('宋体')>=0 then
frm.font.name:='宋体';
frm.font.size:=9;
frm.ShowHint:=true;
frm.BorderStyle:=bsDialog;
try
//名称
lblCaption:=TLabel.create(frm);
lblCaption.left:=16;
lblCaption.top:=16;
lblCaption.parent:=frm;
lblCaption.caption:='快捷名称:';

edtCaption:=TEdit.create(frm);
edtCaption.left:=76;
edtCaption.top:=12;
edtCaption.width:=220;
edtCaption.parent:=frm;
edtCaption.text:=sCaption;

//图标
lblPath:=TLabel.create(frm);
lblPath.parent:=frm;
lblPath.Caption:='快捷图标:';
lblPath.left:=16;
lblPath.top:=48;

edtPath:=TEdit.create(frm);
edtPath.parent:=frm;
edtPath.left:=16;
edtPath.top:=64;
edtPath.width:=340;
edtPath.text:=sPath;

btnSelPic:=TButton.create(frm);
btnSelPic.caption:='...';
btnSelPic.left:=360;
btnSelPic.top:=62;
btnSelPic.width:=24;
btnSelPic.height:=24;
btnSelPic.parent:=frm;
btnSelPic.OnClick:='btnSelPicClick';
btnSelPic.hint:='选择快捷方式的显示图标';
imgPreview:=TxspImage.create(frm);
imgPreview.parent:=frm;
imgPreview.left:=350;
imgPreview.top:=12;
imgPreview.width:=32;
imgPreview.height:=32;
imgPreview.ImageStyle.Align:=xaCenter;
imgPreview.hint:='点击选择快捷方式的图标...';
if not FileExists(sPath) then
imgPreview.FileName:=WidgetPath+sPath
else
imgPreview.FileName:=sPath;
imgPreview.cursor:=-21;
imgPreview.OnClick:='btnSelPicClick';
//动作
lblAction:=TLabel.create(frm);
lblAction.parent:=frm;
lblAction.Caption:='打开动作:';
lblAction.left:=16;
lblAction.top:=96;
//48;

cbbAction:=TComboBox.create(frm);
cbbAction.parent:=frm;
cbbAction.left:=16;
cbbAction.top:=112;
//64;
cbbAction.width:=340;
cbbAction.text:=sAction;
cbbAction.Items.text:='我的电脑'+#13#10+'我的文档'+#13#10+'网上邻居'+#13#10+'IE浏览器'+#13#10+'控制面板'#13#10'回收站';
cbbAction.OnSelect:='cbbActionSelected';

btnSelFile:=TButton.create(frm);
btnSelFile.caption:='...';
btnSelFile.left:=360;
btnSelFile.top:=110;
//62;
btnSelFile.width:=24;
btnSelFile.height:=24;
btnSelFile.parent:=frm;
btnSelFile.OnClick:='btnSelFileClick';
btnSelFile.hint:='选择打开动作';
//确定/取消按钮
btnCancel:=TButton.create(frm);
btnCancel.caption:='取 消';
btnCancel.left:=300;
btnCancel.top:=160;
btnCancel.parent:=frm;
btnCancel.ModalResult:=2;
btnCancel.cancel:=true;

btnOK:=TButton.create(frm);
btnOK.caption:='确 定';
btnOK.left:=210;
btnOK.top:=160;
btnOK.parent:=frm;
btnOK.ModalResult:=1;
btnOk.OnClick:='btnOkClick';

if frm.ShowModal=1 then
begin
case cbbAction.text of
'我的电脑': sAction:='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';
'我的文档': sAction:='::{450D8FBA-AD25-11D0-98A8-0800361B1103}';
'网上邻居': sAction:='::{208D2C60-3AEA-1069-A2D7-08002B30309D}';
'IE浏览器': sAction:='explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}';
'控制面板': sAction:=sControlPanelGUID;
'回收站': sAction:='::{645FF040-5081-101B-9F08-00AA002F954E}';
else
sAction:=cbbAction.text;
end;
ini:=TIniFile.create(DataFileName);
try
ini.WriteString(Section,s+'caption',edtCaption.text);
ini.WriteString(Section,s+'action',sAction);
ini.WriteString(Section,s+'path',edtPath.text);
finally
ini.free;
end;
RefreshShortcut;
end;
finally
frm.free;
end;
end;

//属性窗口的确认按钮事件
procedure btnOkClick(sender);
var
s:string;
begin
if frm=nil then
exit;
if trim(edtCaption.text)='' then
begin
frm.ModalResult:=0;
showmsg('请输入快捷方式的名称!');
exit;
end;
if trim(cbbAction.text)='' then
begin
frm.ModalResult:=0;
showmsg('请选择或者输入快捷方式的动作!');
exit;
end;
if trim(edtPath.text)='' then
begin
frm.ModalResult:=0;
showmsg('请选择快捷方式的显示图标!');
exit;
end;
end;

procedure cbbActionSelected(sender);
begin
edtCaption.text:=cbbAction.text;
end;

//快捷方式
procedure btnSelFileClick(sender);
var
dlgOpen:TOpenDialog;
begin
if frm=nil then
exit;
dlgOpen:=TOpenDialog.Create(frm);
try
dlgOpen.FileName:=cbbAction.text;
if dlgOpen.Execute then
begin
cbbAction.text:=dlgOpen.FileName;
end;
finally
dlgOpen.free;
end;
end;

//图片选择按钮事件
procedure btnSelPicClick(sender);
var
dlgOpen:TOpenDialog;
begin
if frm=nil then
exit;
dlgOpen:=TOpenDialog.Create(frm);
try
if FileExists(WidgetPath+edtPath.text) then
dlgOpen.FileName:=WidgetPath+edtPath.text
else
dlgOpen.FileName:=edtPath.text;
dlgOpen.Filter:='图片文件|*.png;*.jpg;*.bmp';
if dlgOpen.Execute then
begin
imgPreview.FileName:=dlgOpen.FileName;
edtPath.text:=GetRelativePath(dlgOpen.FileName);
end;
finally
dlgOpen.free;
end;
end;

procedure InitShortcut;
var
lst:TStrings;
begin
lst:=TStringList.create;
try
lst.add('['+Section+']');
lst.add('count=6');
lst.add('0caption=我的电脑');
lst.add('0action=::{20D04FE0-3AEA-1069-A2D8-08002B30309D}');
lst.add('0path='+WidgetPath+'images/icon0.png');
lst.add('1caption=我的文档');
lst.add('1action=::{450D8FBA-AD25-11D0-98A8-0800361B1103}');
lst.add('1path='+WidgetPath+'images/icon1.png');
lst.add('2caption=网上邻居');
lst.add('2action=::{208D2C60-3AEA-1069-A2D7-08002B30309D}');
lst.add('2path='+WidgetPath+'images/icon2.png');
lst.add('3caption=IE浏览器');
lst.add('3action=explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}');
lst.add('3path='+WidgetPath+'images/icon3.png');
lst.add('4caption=控制面板');
lst.add('4action='+sControlPanelGUID);
lst.add('4path='+WidgetPath+'images/icon4.png');
lst.add('5caption=回收站');
lst.add('5action=::{645FF040-5081-101B-9F08-00AA002F954E}');
lst.add('5path='+WidgetPath+'images/Recycle.png');
lst.savetofile(DataFileName);
finally
lst.free;
end;
end;

//读取指定index和Name的快捷方式属性
function GetActionInfo(index:integer;
aValueName:string):string;
var
ini:TIniFile;
begin
result:='';
ini:=TIniFile.create(DataFileName);
try
result:=ini.ReadString(Section,inttostr(index)+aValueName,'');
finally
ini.free;
end;
end;

procedure AdjustIndex(index:integer;
value:integer);
var
ini:TIniFile;
i:integer;
s,sOld,sNew,
sCaption,sAction,sPath:string;
begin
if ((value>0) and (index>=icos.count-1)) or
((Value<0) and (index<=0)) then
exit;
ini:=TIniFile.Create(DataFileName);
try
sOld:=inttostr(index+value);
sNew:=inttostr(index);
sCaption:=ini.ReadString(Section,sOld+'caption','');
sAction:=ini.ReadString(Section,sOld+'action','');
sPath:=ini.ReadString(Section,sOld+'path','');
ini.WriteString(Section,sOld+'caption',ini.ReadString(Section,sNew+'caption',''));
ini.WriteString(Section,sOld+'action',ini.ReadString(Section,sNew+'action',''));
ini.WriteString(Section,sOld+'path',ini.ReadString(Section,sNew+'path',''));
ini.WriteString(Section,sNew+'caption',sCaption);
ini.WriteString(Section,sNew+'action',sAction);
ini.WriteString(Section,sNew+'path',sPath);
begin
Update;
//当前图标
TxspImage(icos.Objects[index]).hint:=sCaption;
s:=sPath;
if FileExists(s) then
TxspImage(icos.Objects[index]).FileName:=s
else
TxspImage(icos.Objects[index]).FileName:=WidgetPath+'images/icon'+sNew+'.png';
//目的图标
TxspImage(icos.Objects[index+value]).hint:=ini.ReadString(Section,sOld+'caption','');
s:=ini.ReadString(Section,sOld+'path','');
if FileExists(s) then
TxspImage(icos.Objects[index+value]).FileName:=s
else
TxspImage(icos.Objects[index+value]).FileName:=WidgetPath+'images/icon'+sOld+'.png';

EndUpdate;
finally
ini.free;
end;
//RefreshShortcut;
end;

//执行快捷方式
procedure RunAction(index:integer);
const
SW_SHOW=1;
ID_YES=6;
MB_YESNO=4;
var
aIndex:integer;
begin
aIndex:=index;
if (aIndex<0) or (aIndex>=icos.count) then
exit;
s:=LowerCase(GetActionInfo(aIndex,'action'));
{ if s='' then
ShellExecute(0,'open','explorer.exe','','',1)
//r.run('explorer.exe')
else
if FileExists(s) then
begin
if ExtractFileExt(s)='.lnk' then
s:=GetShortCutExeFile(s);
ShellExecute(0,'open',s,'','',1);
//showtrayhint('a',s);
end
//r.run('explorer.exe '+s)
else
begin
//ShellExecute(0,'open',s,'','',1);
r:=CreateOleObject('wscript.shell');
//r.run('explorer.exe '+s);
r.run(s);
end;
}

case s of
'':
begin
ShowTrayHint('桌面快捷方式','动作为空,请指定打开动作!');
ShowShortcutProperty(index);
end;
'shutdown':
if MessageBox(0,'确认要关机?','警告',MB_YESNO)=ID_YES then
ShellExecute(0,'open','shutdown','-p','',SW_SHOW);
'restart':
if MessageBox(0,'确认要重启?','警告',MB_YESNO)=ID_YES then
ShellExecute(0,'open','shutdown','-r -f -t 03','',SW_SHOW);
'logoff':
if MessageBox(0,'确认要注销?','警告',MB_YESNO)=ID_YES then
ShellExecute(0,'open','shutdown','-l','',SW_SHOW);
'standby':
if MessageBox(0,'确认要休眠/待机?','警告',MB_YESNO)=ID_YES then
ShellExecute(0,'open','rundll32.exe','powrprof.dll,SetSuspendState','',SW_SHOW);
'switchuser','lock': ShellExecute(0,'open','rundll32.exe','user32.dll,LockWorkStation','',SW_SHOW);
'shutdowndlg':
begin
r := CreateOleObject('Shell.Application');
r.ShutdownWindows;
r := Unassigned;
end
'rundlg':
begin
r := CreateOleObject('Shell.Application');
r.FileRun;
r := Unassigned;
end
'ejectpc':
begin
r := CreateOleObject('Shell.Application');
r.EjectPC;
r := Unassigned;
end
'minimizeall':
begin
r := CreateOleObject('Shell.Application');
r.MinimizeAll;
r := Unassigned;
end
'findfiles':
begin
r := CreateOleObject('Shell.Application');
r.FindFiles;
r := Unassigned;
end
else

if DirectoryExists(s) or (copy(s,1,7)='http://') then
ShellExecute(0,'open','Explorer', '"'+s+'"', '',SW_SHOW)
else
if fileExists(s) then
ShellExecute(0,'open', s,'','"'+ExtractFilePath(s)+'"',1)
else
begin
//showtrayhint('其它',s);
r := CreateOleObject('wscript.shell');
r.run(s);
r := Unassigned;
end;
end;
end;

//计算动画效果所在的鼠标区域
procedure CalMouseRect;
var
ilen:Integer;
begin
ilen:=icos.count*DefIconSize;
//所有图标的默认长度相加
MouseTop:=0;
MouseLeft:=0;
MouseRight:=0;
MouseBottom:=0;

bgLeft:=screen.WorkAreaRect.left;
bgTop:=screen.WorkAreaRect.top;
bgWidth:=screen.WorkAreaRect.right-screen.WorkAreaRect.left;
bgHeight:=screen.WorkAreaRect.Bottom-screen.WorkAreaRect.bottom;
case Layout of
'TopLeft','Top','TopRight'://Top
begin
Widget.Left:=screen.WorkAreaRect.Left;
Widget.Top:=screen.WorkAreaRect.Top;
Widget.Width:=screen.WorkAreaRect.Right-screen.WorkAreaRect.Left;
Widget.Height:=MaxIconSize+SepTop+SepBottom;
bgTop:=0;
bgHeight:=DefIconSize+SepTop+SepBottom;
imgbg.top:=bgTop;
imgbg.height:=bgHeight;
if MouseIn then
MouseBottom:=MouseTop+MaxIconSize
else
MouseBottom:=MouseTop+DefIconSize;
case Layout of
'TopLeft': MouseLeft:=0;
'Top': MouseLeft:=(Widget.Width-iLen) div 2;
'TopRight':MouseLeft:=Widget.Width-iLen;
end;
MouseRight:=MouseLeft+iLen;
end;
'BottomLeft','Bottom','BottomRight'://Bottom
begin
Widget.Left:=screen.WorkAreaRect.Left;
Widget.Height:=MaxIconSize+SepTop+SepBottom;
Widget.Top:=screen.WorkAreaRect.Bottom-Widget.Height;
Widget.Width:=screen.WorkAreaRect.Right-screen.WorkAreaRect.Left;
bgHeight:=DefIconSize+SepTop+SepBottom;
bgTop:=Widget.Height-bgHeight;
imgbg.top:=bgTop;
imgbg.height:=bgHeight;
if MouseIn then
begin
MouseTop:=SepTop;
MouseBottom:=MouseTop+MaxIconSize;
end
else
begin
MouseTop:=Widget.Height-DefIconSize;
MouseBottom:=MouseTop+DefIconSize;
end;
case Layout of
'BottomLeft': MouseLeft:=0;
'Bottom': MouseLeft:=(Widget.Width-iLen) div 2;
'BottomRight': MouseLeft:=Widget.Width-iLen;
end;
MouseRight:=MouseLeft+ilen;
end;
'LeftTop','Left','LeftBottom'://Left
begin
Widget.Left:=screen.WorkAreaRect.Left;
Widget.Width:=MaxIconSize+SepLeft+SepRight;
Widget.Top:=screen.WorkAreaRect.Top;
Widget.Height:=screen.WorkAreaRect.Bottom-screen.WorkAreaRect.Top;
bgLeft:=0;
bgWidth:=DefIconSize+SepLeft+SepRight;
imgbg.left:=bgLeft;
imgbg.width:=bgWidth;
case Layout of
'LeftTop': MouseTop:=0;
'Left': MouseTop:=(Widget.Height-iLen) div 2;
'LeftBottom': MouseTop:=Widget.Height-iLen;
end;
MouseLeft:=0;
MouseBottom:=MouseTop+ilen;
if MouseIn then
MouseRight:=MouseLeft+MaxIconSize
else
MouseRight:=MouseLeft+DefIconSize;
end;
'RightTop','Right','RightBottom'://Right
begin
Widget.Width:=MaxIconSize+SepLeft+SepRight;
Widget.Left:=screen.WorkAreaRect.Right-Widget.Width;
Widget.Top:=screen.WorkAreaRect.Top;
Widget.Height:=screen.WorkAreaRect.Bottom-screen.WorkAreaRect.Top;
bgWidth:=DefIconSize+SepLeft+SepRight;
bgLeft:=Widget.Width-bgWidth;
imgbg.left:=bgLeft;
imgbg.width:=bgWidth;
case Layout of
'RightTop': MouseTop:=0;
'Right': MouseTop:=(Widget.Height-iLen) div 2;
'RightBottom': MouseTop:=Widget.Height-iLen;
end;
if MouseIn then
begin
MouseLeft:=SepLeft;
MouseRight:=MouseLeft+MaxIconSize;
end
else
begin
MouseLeft:=Widget.Width-DefIconSize;
MouseRight:=MouseLeft+DefIconSize;
end;
MouseBottom:=MouseTop+ilen;
end;
end;
end;

//计算Dock背景的显示区域
procedure CalDockPosition;
begin
if (Layout='LeftTop') or (Layout='Left') or (Layout='LeftBottom') or (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
begin
//Left or Right
if icos.count>0 then
bgTop:=TxspImage(icos.Objects[0]).top-SepTop;
if icos.count>0 then

bgHeight:=TxspImage(icos.Objects[icos.count-1]).top+TxspImage(icos.Objects[icos.count-1]).height-bgTop+SepBottom
else
bgHeight:=TxspImage(icos.Objects[0]).top+TxspImage(icos.Objects[0]).height-bgTop+SepBottom;
imgbg.top:=bgTop;
imgbg.height:=bgHeight;
end
else
//Top or Bottom
begin
if icos.count>0 then
//当Dock在上或下时左右要多加MarginLeft和MarginRight
begin
bgLeft:=TxspImage(icos.Objects[0]).left-SepLeft;
bgWidth:=TxspImage(icos.Objects[icos.count-1]).left+TxspImage(icos.Objects[icos.count-1]).width-bgLeft+SepRight;
end
else
bgWidth:=TxspImage(icos.Objects[0]).left+TxspImage(icos.Objects[0]).width-bgLeft+SepRight;
imgbg.left:=bgLeft;
imgbg.width:=bgWidth;
end;
do
ckLeft:=bgleft+SepLeft;
do
ckTop:=bgtop+SepTop;
// showtrayhint('bg',format('l:%3d t:%3d w:%3d h:%3d',[bgleft,bgtop,bgwidth,bgheight]));
end;

procedure CalDockIconsSize;
var
aIndex,iInterval,iSize,CenterWidth,iFirstPos,iLastPos:integer;
begin
if isVert then
CurrentIconIndex:=my div DefIconSize
else
CurrentIconIndex:=mx div DefIconSize;
if (CurrentIconIndex<0) or (CurrentIconIndex>=icos.count) then
exit;
begin
Update;
aIndex:=CurrentIconIndex;
if isVert then
begin
iFirstPos:=round(TxspImage(icos.Objects[0]).Top);
iLastPos:=round(TxspImage(icos.Objects[icos.count-1]).Top);
end
else
begin
iFirstPos:=round(TxspImage(icos.Objects[0]).left);
iLastPos:=round(TxspImage(icos.Objects[icos.count-1]).left);
end;
if isVert then
iInterval:=(DefIconSize*(aIndex+0.5)-my) //与当前图标中间坐标的距离
else
iInterval:=(DefIconSize*(aIndex+0.5)-mx);//与当前图标中间坐标的距离
iSize:=round((CurrentMaxIconSize-DefIconSize)*(ZoomIconCount*DefIconSize-Abs(iInterval))/(ZoomIconCount*DefIconSize)+DefIconSize);
//图标的大小
if TxspImage(icos.Objects[aIndex]).width<>iSize then
begin
TxspImage(icos.Objects[aIndex]).width:=iSize;
TxspImage(icos.Objects[aIndex]).height:=iSize;
end;
if isVert then
begin
TxspImage(icos.Objects[aIndex]).top:=round(my-(my-DefIconSize*aIndex)*iSize/DefIconSize)+MouseTop;
if (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
TxspImage(icos.Objects[aIndex]).Left:=MaxIconSize-TxspImage(icos.Objects[aIndex]).width //+MouseLeft
else
TxspImage(icos.Objects[aIndex]).Left:=MouseLeft;
end
else
begin
TxspImage(icos.Objects[aIndex]).left:=round(mx-(mx-DefIconSize*aIndex)*iSize/DefIconSize)+MouseLeft;
if (Layout='BottomLeft') or (Layout='Bottom') or (Layout='BottomRight') then
TxspImage(icos.Objects[aIndex]).top:=MaxIconSize-TxspImage(icos.Objects[aIndex]).height //+MouseTop
else
TxspImage(icos.Objects[aIndex]).Top:=MouseTop;
end;

CenterWidth:=TxspImage(icos.Objects[aIndex]).width;
ChangeIconCount:=1;
//--- Prev Icon 计算当前图标前面的图标坐标和大小 ---
if aIndex>0 then
for k := aIndex-1do
wnto 0do
begin
if k<aIndex-ZoomIconCount then
begin
iSize:=DefIconSize;
TxspImage(icos.Objects[k]).width:=DefIconSize;
TxspImage(icos.Objects[k]).height:=DefIconSize;
end
else
begin
Inc(ChangeIconCount);
iDis:=(ZoomIconCount*DefIconSize+iInterval-(aIndex-k)*DefIconSize);
//与当前图标中间坐标的距离
iSize:=round(((CurrentMaxIconSize-DefIconSize)*iDis)/(ZoomIconCount*DefIconSize)+DefIconSize);
//图标的大小
if iSize<DefIconSize then
iSize:=DefIconSize;
TxspImage(icos.Objects[k]).width:=iSize;
TxspImage(icos.Objects[k]).height:=iSize;
CenterWidth:=CenterWidth+iSize;
end;
if isVert then
begin
TxspImage(icos.Objects[k]).Top:=round(TxspImage(icos.Objects[k+1]).Top-TxspImage(icos.Objects[k]).width);
if (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
TxspImage(icos.Objects[k]).Left:=MaxIconSize-TxspImage(icos.Objects[k]).width //+MouseLeft
else
TxspImage(icos.Objects[k]).left:=MouseLeft;
end
else
begin
if (Layout='BottomLeft') or (Layout='Bottom') or (Layout='BottomRight') then
TxspImage(icos.Objects[k]).Top:=MaxIconSize-TxspImage(icos.Objects[k]).height //+MouseTop
else
TxspImage(icos.Objects[k]).top:=MouseTop;
TxspImage(icos.Objects[k]).Left:=round(TxspImage(icos.Objects[k+1]).Left-TxspImage(icos.Objects[k]).width);
end;
end;

//--- Next Icon ---
if aIndex<icos.count-1 then
for k := aIndex+1 to icos.count-1do
begin
if k>aIndex+ZoomIconCount then
begin
iSize:=DefIconSize;
TxspImage(icos.Objects[k]).width:=DefIconSize;
TxspImage(icos.Objects[k]).height:=DefIconSize;
end
else
begin
Inc(ChangeIconCount);
iDis:=(ZoomIconCount*DefIconSize-iInterval-(k-aIndex)*DefIconSize);
iSize:=round(((CurrentMaxIconSize-DefIconSize)*iDis)/(ZoomIconCount*DefIconSize)+DefIconSize);
//图标的大小
if iSize<DefIconSize then
iSize:=DefIconSize;
TxspImage(icos.Objects[k]).width:=iSize;
TxspImage(icos.Objects[k]).height:=iSize;
CenterWidth:=CenterWidth+iSize;
end;
if isVert then
begin
if (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
TxspImage(icos.Objects[k]).Left:=MaxIconSize-TxspImage(icos.Objects[k]).width //+MouseLeft
else
TxspImage(icos.Objects[k]).Left:=MouseLeft;
TxspImage(icos.Objects[k]).Top:=round(TxspImage(icos.Objects[k-1]).Top+TxspImage(icos.Objects[k-1]).height);
end
else
begin
if (Layout='BottomLeft') or (Layout='Bottom') or (Layout='BottomRight') then
TxspImage(icos.Objects[k]).Top:=MaxIconSize-TxspImage(icos.Objects[k]).width //+MouseTop
else
TxspImage(icos.Objects[k]).Top:=MouseTop;
TxspImage(icos.Objects[k]).Left:=round(TxspImage(icos.Objects[k-1]).Left+TxspImage(icos.Objects[k-1]).width);
end;
end;

//Adjust Icon Position
if icos.count>=2*ZoomIconCount+1 then
begin
r:=(CenterWidth-ChangeIconCount*DefIconSize)/2;
if (aIndex>ZoomIconCount) and (aIndex<icos.count-ZoomIconCount) and (r<>0) then
begin
if isVert then
TxspImage(icos.Objects[0]).Top:=-r+MouseTop
else
TxspImage(icos.Objects[0]).Left:=-r+MouseLeft;
for k := 1 to icos.count-1do
begin
if isVert then
TxspImage(icos.Objects[k]).Top:=TxspImage(icos.Objects[k-1]).Top+TxspImage(icos.Objects[k-1]).width
else
TxspImage(icos.Objects[k]).Left:=TxspImage(icos.Objects[k-1]).Left+TxspImage(icos.Objects[k-1]).width;
end;
end;
end;

if (aIndex<icos.count-ZoomIconCount-1) then
begin
if isVert then
begin
if Abs(TxspImage(icos.Objects[icos.count-1]).Top-iLastPos)<=6 then
begin
TxspImage(icos.Objects[icos.count-1]).Top:=iLastPos;
for k := icos.count-2do
wnto 0do
begin
i:=round(TxspImage(icos.Objects[k+1]).Top-TxspImage(icos.Objects[k]).width);
if Abs(TxspImage(icos.Objects[k]).Top-i)<=6 then
TxspImage(icos.Objects[k]).Top:=i;
end;
end;
end
else
begin
if Abs(TxspImage(icos.Objects[icos.count-1]).left-iLastPos)<=6 then
begin
TxspImage(icos.Objects[icos.count-1]).left:=iLastPos;
for k := icos.count-2do
wnto 0do
begin
i:=round(TxspImage(icos.Objects[k+1]).Left-TxspImage(icos.Objects[k]).width);
if Abs(TxspImage(icos.Objects[k]).Left-i)<=6 then
TxspImage(icos.Objects[k]).Left:=i;
end;
end;
end;
end
else

begin
if isVert then
begin
if Abs(TxspImage(icos.Objects[0]).Top-iFirstPos)<=6 then
begin
TxspImage(icos.Objects[0]).Top:=iFirstPos;
for k := 1 to icos.count-1do
begin
i:=round(TxspImage(icos.Objects[k-1]).Top+TxspImage(icos.Objects[k-1]).width);
if Abs(TxspImage(icos.Objects[k]).Top-i)<=6 then
TxspImage(icos.Objects[k]).Top:=i;
end;
end;
end
else
begin
if Abs(TxspImage(icos.Objects[0]).Left-iFirstPos)<=6 then
begin
TxspImage(icos.Objects[0]).Left:=iFirstPos;
for k := 1 to icos.count-1do
begin
i:=round(TxspImage(icos.Objects[k-1]).Left+TxspImage(icos.Objects[k-1]).width);
if Abs(TxspImage(icos.Objects[k]).Left-i)<=6 then
TxspImage(icos.Objects[k]).Left:=i;
end;
end;
end;
end;
//imgbg.NeedRefresh:=true;
CalDockPosition;
// lbl.caption:=inttostr(mouseleft)+' / '+inttostr(TxspImage(icos.Objects[0]).left);
EndUpdateAll;

end;

procedure DrawDefault;
var
i:integer;
begin
if icos.count>0 then
for i := 0 to icos.count-1 do
begin
TxspImage(icos.Objects).width:=DefIconSize;
TxspImage(icos.Objects).height:=TxspImage(icos.Objects).width;
if (Layout='LeftTop') or (Layout='Left') or (Layout='LeftBottom') or (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
begin
TxspImage(icos.Objects).Left:=dockleft;
TxspImage(icos.Objects).Top:=docktop+i*DefIconSize;
end
else
begin
TxspImage(icos.Objects).Left:=dockleft+i*DefIconSize;
TxspImage(icos.Objects).Top:=docktop;
end;
end;
CalDockPosition;
end;

//读取Dock背景皮肤设置
procedure SetSkin(value:string);
var
ini:TIniFile;
begin
//if SkinName=value then
exit;
SkinName:=value;
fn:=WidgetPath+'images/bg/'+value+'/background.ini';
if not FileExists(fn) then
exit;
case Layout of
'LeftTop','Left','LeftBottom': sec:='BackgroundLeft';
'RightTop','Right','RightBottom':sec:='BackgroundRight';
'TopLeft','Top','TopRight': sec:='BackgroundTop';
'BottomLeft','Bottom','BottomRight':sec:='Background';
else
sec:='Background';
end;
ini:=TIniFile.create(fn);
try
s:=ini.readstring(sec,'Image','');
if not FileExists(WidgetPath+'images/bg/'+value+'/'+s) then
s:=ini.readstring('Background','Image','');
s:=WidgetPath+'images/bg/'+value+'/'+s;
if FileExists(s) then
imgbg.FileName:=s;
finally
ini.free;
end;
end;

//读取当前Widget的INI设置
procedure InitIni;
var
ini:TIniFile;
iCount:integer;
img:TxspImage;
begin
isIniting:=true;
//DefIconSize:=60;
//MaxIconSize:=128;
DefIconSize:=GetSettingInt('DefIconSize',60);
MaxIconSize:=GetSettingInt('MaxIconSize',128);
AniStyle:=GetSettingInt('AniStyle',1);
nAniStyle.checked:=AniStyle=1;

CurrentMaxIconSize:=MaxIconSize;
CurrentIconSize:=DefIconSize;
if not FileExists(DataFileName) then
InitShortcut;
ini:=TIniFile.create(DataFileName);
try
iCount:=ini.ReadInteger(Section,'count',0);
//if IconCount>IconMaxCount then
IconCount:=IconMaxCount;
finally
ini.free;
end;
if iCount>0 then
for i:=0 to iCount-1do
NewIconImage;
RefreshShortcut;
SepTop:=2;
SepBottom:=2;
SepLeft:=2;
SepRight:=2;
DelaySpeed:=GetSettingInt('DelaySpeed',7);
ZoomIconCount:=3;
{bgleft:=0;
bgtop:=0;
bgwidth:=icos.count*DefIconSize+SepLeft+SepRight;
bgheight:=Widget.height;}
do
ckLeft:=bgleft+SepLeft;
do
ckTop:=bgtop+SepTop;
MouseTop:=0;
MouseLeft:=0;
MouseRight:=0;
MouseBottom:=0;
//dockLeft:=00;
//dockTop:=0;
MouseIn:=false;
DelayTimes:=0;
Layout:=GetSetting('Layout','Bottom');
case Layout of
'TopLeft': npTopLeft.checked:=true;
'Top': npTop.checked:=true;
'TopRight': npTopRight.checked:=true;
'BottomLeft': npBottomLeft.checked:=true;
'Bottom': npBottom.checked:=true;
'BottomRight': npBottomRight.checked:=true;
'LeftTop': npLeftTop.checked:=true;
'Left': npLeft.checked:=true;
'LeftBottom': npLeftBottom.checked:=true;
'RightTop': npRightTop.checked:=true;
'Right': npRight.checked:=true;
'RightBottom': npRightBottom.checked:=true;
else
npBottom.checked:=true;
end;
s:=GetSetting('Skin','LongGlass');
SetSkin(s);
isVert:=(Layout='LeftTop') or (Layout='Left') or (Layout='LeftBottom') or (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom');
Widget.Height:=MaxIconSize;
//Widget.width:=(icos.count-ZoomIconCount)*DefIconSize+ZoomIconCount*MaxIconSize;
mx:=-1;
my:=0;
CurrentIconIndex:=-1;
CalMouseRect;
isIniting:=false;
//CalDockPosition;
CalDockIconsSize;
DrawDefault;
end;

//--- Widget初始化事件,当打开Widget时会触发此事件 ---
procedure OnWidgetInit;
begin
if isWinVista then
sControlPanelGUID:='::{21EC2020-3AEA-1069-A2DD-08002B30309D}'
else
sControlPanelGUID:='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}/::{21EC2020-3AEA-1069-A2DD-08002B30309D}';
Icos:=TStringList.create;
SkinName:='LongGlass';
DataFileName:=AppPath+'Data/'+WidgetName+'.dat';
ShortcutIconPath:=LowerCase(WidgetPath+'images/ShortcutIconPath/'+WidgetName+'/');
if not DirectoryExists(ShortcutIconPath) then
ForceDirectories(ShortcutIconPath);
ShowToolbar:=false;
LeaveTimes:=0;
AllowDock:=false;
ZoomIn:=false;
ZoomOut:=false;
AutoAdjustMem:=0;
//IconMaxCount:=16;
//IconCount:=IconMaxCount;
//Icons:=[img0,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15];
mx:=0;
my:=0;
begin
Update;
InitIni;
tmr:=TTimer.create(Widget);
tmr.Enabled:=false;
tmr.OnTimer:='tmrOnTimer';
tmr.Interval:=10;
imgbg.OnMouseMove:='WidgetMouseMove';
EndUpdateAll;
end;

//--- Widget关闭事件,当关闭Widget时会触发此事件 ---
procedure OnWidgetClose;
begin
Icos.free;
isIniting:=true;
tmr.free;
tmr:=nil;
end;

//--- Widget删除事件,当Widget被删除时触发此事件 ---
procedure OnWidgetDelete;
begin
if DirectoryExists(ShortcutIconPath) then
begin
DelTree(ShortcutIconPath);
DeleteFile(DataFileName);
//showmessage(ShortcutIconPath+'*.*');
//if DeleteFile(ShortcutIconPath+'*.*') then

// RemoveDir(ShortcutIconPath);
end;
end;

procedure WidgetMouseMove(Sender, Shift, X, Y);
var
img:TxspImage;
begin
if not MouseIn or isIniting or ZoomOut then
exit;
//if tmr.Enabled then
exit;
img:=sender;
mx:=img.left+x-MouseLeft;
my:=img.top+y-MouseTop;
if not (tmr.Enabled and ZoomIn) then
begin
if AniStyle=0 then
begin
if img.tag=CurrentIconIndex then
exit
else
begin
if isVert then
begin
mx:=round(DefIconSize/2);
my:=round(DefIconSize*(img.tag+0.5));
//showtrayhint('vert',inttostr(img.tag)+':'+inttostr(CurrentIconIndex));
end
else
begin
mx:=round(DefIconSize*(img.tag+0.5));
my:=round(DefIconSize/2);
//showtrayhint('horz',inttostr(img.tag)+':'+inttostr(CurrentIconIndex));
end;
CalDockIconsSize;
end;
end
else
if (mx>=0) and (mx<=MouseRight-MouseLeft) and (my>=0) and (my<=MouseBottom-MouseTop) then
begin
CalDockIconsSize;
//showtrayhint('','mouse in');
end;
end;
lbl.caption:=inttostr(mx)+' / '+inttostr(my)+' / '+inttostr(mouseleft);
end;

procedure OnWidgetMouseEnter;
begin
if isIniting then
exit;
if tmr.Enabled then
begin
if not MouseIn then
exit;
tmr.Enabled:=false;
CurrentMaxIconSize:=DefIconSize;
CalMouseRect;
CalDockIconsSize;
end;
CurrentIconSize:=MaxIconSize;
DelayTimes:=0;
MouseIn:=true;
CalMouseRect;
ZoomIn:=true;
if AniStyle=0 then
DelayTimes:=DelaySpeed+1;
tmr.Enabled:=true;
end;

procedure OnWidgetMouseLeave;
begin
if isIniting or ZoomOut then
exit;
//showtrayhint('','mouse leave');
if tmr.Enabled then
begin
tmr.Enabled:=false;
CurrentMaxIconSize:=MaxIconSize;
CalMouseRect;
CalDockIconsSize;
end;
CurrentIconSize:=MaxIconSize;
DelayTimes:=DelaySpeed;
MouseIn:=false;
//fMousePoint:=pt;
//if (Layout='LeftTop') or (Layout='Left') or (Layout='LeftBottom') or (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
if isVert then
i:=my div DefIconSize
else
//Top or Bottom
i:=mx div DefIconSize;

//if (Layout='LeftTop') or (Layout='Left') or (Layout='LeftBottom') or (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom') then
if isVert then
begin
//Left or Right
if (my>=MouseBottom-MouseTop-10) then
//Bottom out
begin
//CurrentIconSize:=round((MaxIconSize-DefIconSize)*(ZoomIconCount-1)/ZoomIconCount+DefIconSize);
my:=MouseBottom-MouseTop-1;
CurrentIconSize:=TxspImage(icos.Objects[icos.count-1]).width;
end
else
if (my<=10) then
//Top out
CurrentIconSize:=round((MaxIconSize-DefIconSize)*(ZoomIconCount-1)/ZoomIconCount+DefIconSize)
else
begin
//Right out
if (i>=0) and (i<icos.count) then
begin
mx:=MouseLeft+1;
CurrentIconSize:=TxspImage(icos.Objects).height;
end
else
begin
mx:=MouseRight-MouseLeft-1;
if icos.count<=0 then
CurrentIconSize:=DefIconSize
else
CurrentIconSize:=TxspImage(icos.Objects[icos.count-1]).height;
end;
//showtrayhint('right out:'+inttostr(MouseBottom),my);
end;
end
else
//Top or Bottom
begin
if (mx>=MouseRight-10) then
// right out
begin
//CurrentIconSize:=round((MaxIconSize-DefIconSize)*(ZoomIconCount-1)/ZoomIconCount+DefIconSize);
mx:=MouseRight-1;
CurrentIconSize:=TxspImage(icos.Objects[icos.count-1]).width;
end
else
if (mx<=10) then
// left out
CurrentIconSize:=round((MaxIconSize-DefIconSize)*(ZoomIconCount-1)/ZoomIconCount+DefIconSize)
else
//top or bottom out
begin
if (i>=0) and (i<icos.count) then
CurrentIconSize:=TxspImage(icos.Objects).width
else

begin
if i<0 then
begin
mx:=MouseLeft+1;
CurrentIconSize:=TxspImage(icos.Objects[0]).width;
end;
else
begin
mx:=MouseRight-MouseLeft-1;
if icos.count<=0 then
CurrentIconSize:=DefIconSize
else
CurrentIconSize:=TxspImage(icos.Objects[icos.count-1]).width;
end;
//showtrayhint('','error'+inttostr(i));
end;
end;
end;

ZoomOut:=true;
if AniStyle=0 then
DelayTimes:=-1;
tmr.Enabled:=true;
end;

procedure OnWidgetDeactivate;
begin
OnWidgetMouseLeave;
end;

//鼠标移入、移出效果
procedure tmrOnTimer(sender);
begin
if MouseIn then
//Zoom In
begin
Inc(DelayTimes);
if DelayTimes>DelaySpeed then
begin
tmr.Enabled:=false;
ZoomIn:=false;
CurrentMaxIconSize:=MaxIconSize;
CalMouseRect;
end
else
CurrentMaxIconSize:=round((CurrentIconSize-DefIconSize)*DelayTimes/DelaySpeed+DefIconSize);
CalDockIconsSize;
end
else
//Zoom out
begin
dec(DelayTimes);
if DelayTimes<=0 then
begin
tmr.Enabled:=false;
ZoomOut:=false;
CurrentMaxIconSize:=DefIconSize;
CalMouseRect;
DrawDefault;
end
else
CurrentMaxIconSize:=round((CurrentIconSize-DefIconSize)*DelayTimes/DelaySpeed+DefIconSize);
CalDockIconsSize;
end;
end;

procedure DelShortcut(index:integer);
var
aIndex:integer;
ini:TIniFile;
s1,s2:string;
begin
aIndex:=index;
if (aIndex<0) or (aIndex>=icos.count) then
exit;
if icos.count=1 then
begin
showtrayhint('警告','Dock小工具至少需要一个快捷方式!');
exit;
end;
ini:=TIniFile.create(DataFileName);
try
s1:=ini.ReadString(Section,inttostr(aIndex)+'path','');
//如果是自动生成的data目录下的png图片,则自动删除,以免产生垃圾
if LowerCase(ExtractFilePath(s1))=ShortcutIconPath then
DeleteFile(s1);
for i:=aIndex+1 to icos.count-1do
begin
s1:=inttostr(i-1);
s2:=inttostr(i);
ini.WriteString(Section,s1+'caption',ini.ReadString(Section,s2+'caption',''));
ini.WriteString(Section,s1+'action',ini.ReadString(Section,s2+'action',''));
ini.WriteString(Section,s1+'path',ini.ReadString(Section,s2+'path',''));
end;
//IconCount:=IconCount-1;
TxspImage(icos.Objects[aIndex]).free;
icos.Delete(aIndex);
s1:=inttostr(icos.count);
ini.DeleteKey(Section,s1+'caption');
ini.DeleteKey(Section,s1+'action');
ini.DeleteKey(Section,s1+'path');
ini.writeinteger(Section,'count',icos.count);
mx:=-1;
finally
ini.free;
end;
OnWidgetMouseLeave;
RefreshShortcut;
//begin
Update;
//EndUpdateAll;
end;

procedure ResetShortcut;
var
i:integer;
begin
MouseIn:=false;
if icos.count>0 then
begin
for i:=icos.count-1do
wnto 0do
TxspImage(icos.Objects).free;
icos.Clear;
end;
InitShortcut;
//OnWidgetMouseLeave;
begin
Update;
InitIni;
EndUpdateAll;
end;

//当点击图片时触发此函数
procedure ImgClick(sender);
begin

RunAction(sender.tag);
end;

procedure imgMouseEnter(sender);
begin
CurrentIconIndex:=sender.tag;
end;

procedure imgMouseLeave(sender);
begin
CurrentIconIndex:=-1;
end;

//--- 文件拖放到事件,当文件拖放到Widget中时会触发此事件 ---
//支持同时拖拽多个文件,并创建多个快捷方式
procedure OnWidgetDropFiles(Files:string);
var
lst:TStrings;
i:integer;
s,s1,s2:string;
ini:TIniFile;
begin
if Files<>'' then
begin
lst:=TStringList.create;
ini:=TIniFile.create(DataFileName);
try
lst.text:=Files;
if lst.count>0 then
begin
for i:=0 to lst.count-1do
begin
//showmsg(lst.strings);
//保存快捷方式名称
AddIco('',lst.strings,'');
{ s:=inttostr(icos.count);
if DirectoryExists(lst.strings) then
//目录
s2:=lst.strings
else
if (length(lst.strings)=3) and (copy(lst.strings,2,2)=':/') then
//盘符
s2:=lst.strings
else
//普通文件
s2:=ChangeFileExt(ExtractFileName(lst.strings),'');
ini.WriteString(Section,s+'caption',s2);
NewIconImage;
//保存快捷方式文件路径
if LowerCase(ExtractFileExt(lst.strings))='.lnk' then
begin
ini.WriteString(Section,s+'action',GetShortCutExeFile(lst.strings));
//showmessage(GetShortCutExeFile(lst.strings));
end
else
ini.WriteString(Section,s+'action',lst.strings);
//保存快捷方式图片,并设置图标的图片
s1:=WidgetPath+'images/icon'+s+'.png';
s1:=ShortcutIconPath+s2+'.png';
s2:=GetFileIcon(lst.strings);
if s2<>'' then
begin
ini.WriteString(Section,s+'path',s2);
TxspImage(icos.Objects[icos.count-1]).FileName:=s2;
end
else
begin
s2:=WidgetPath+'images/ico'+s+'.png';
if GetFileIconToPng(lst.strings,s1) then
begin
ini.WriteString(Section,s+'path',s1);
TxspImage(icos.Objects[icos.count-1]).FileName:=s1;
end
// else
// showtrayhint('failed',s1);
end;
ini.WriteInteger(Section,'count',icos.count);}
end;
RefreshShortcut;
end;
finally
ini.free;
lst.free;
end;
end;
end;

procedure SetDockPosition(value:string);
begin
begin
Update;
Layout:=value;
isVert:=(Layout='LeftTop') or (Layout='Left') or (Layout='LeftBottom') or (Layout='RightTop') or (Layout='Right') or (Layout='RightBottom');
SetSetting('Layout',Layout);
SetSkin(SkinName);
Widget.Height:=MaxIconSize;
mx:=-1;
my:=0;
CurrentIconIndex:=-1;
CalMouseRect;
CalDockIconsSize;
DrawDefault;
EndUpdate;
end;

procedure SwitchAniStyle;
begin
if AniStyle=1 then
AniStyle:=0
else
AniStyle:=1;
nAniStyle.checked:=AniStyle=1;
SetSetting('AniStyle',AniStyle);
end;
 
后退
顶部