const
  ImgCount=9; //块的数量

var
  Imgs;
  DataFileName,ShortcutIconPath:string;
  ShortcutNums,PageIndex,PageCount,SelIndex:integer;
  Section:string;
  pmenu:TPopupMenu;
  miOpen,miInterval,miDel,miProperty:TMenuItem;
  frm:TForm;
  edtCaption,edtPath:TEdit;
  cbbAction:TComboBox;
  imgPreview:TxspImage;
  btndefine:TButton;
  iOnMouseInOut:Byte;
  bMenuPopUp:Boolean;
  sControlPanelGuid:String;
  g_iDirectionIndex:Integer;
  g_lstImage:TStrings;
  g_lstMenu:TStrings;

//--- 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;
//-------------------------------------------------

//显示或隐藏工具条
procedure ShowHideBar(flag:Boolean;IndexOfDirection:Integer);
var 
  Speed,TemLeft,TemTop:Integer;
	TabWidth:Integer;
begin
  Speed:=5;
	TabWidth:=30;
	TemLeft:=Widget.left;
  TemTop:=Widget.Top;
  case IndexOfDirection of
  0://向左侧缩进
  begin
    if flag then  //若left<0
    begin
  		//if Widget.left=0 then exit;
  		while True do
  		begin
  			if (TemLeft>=0) then
  			begin
  				Widget.left:=0;
  				Break;
  			end;
  			TemLeft:=TemLeft+Speed;
  			WidGet.left:=TemLeft;
  			// Sleep(5);
  		end;
    end else  //若Left>=0
  	begin
  		while True do
  		begin
  		  if (TabWidth-TemLeft)>=Widget.width then
  			begin
  				Widget.left:=TabWidth-Widget.Width;
  				Break;
  			end;
  			TemLeft:=TemLeft-Speed;
  			Widget.left:=TemLeft;
  		end;
  	end;
  end;
  1:  //向右侧缩进
  begin
    if flag then //left>1024-widget.width    弹出
    begin
      while True do
      begin
        if(screen.DesktopRect.right-Temleft)>=Widget.Width then
        begin
          Widget.left:=screen.DeskTopRect.right-Widget.Width;
          Break;
        end;  
        TemLeft:=TemLeft-Speed;
        widget.left:=TemLeft;
      end;
    end else  //缩进
    begin
      while True do
      begin
        if(screen.DesktopRect.right-Temleft)<=TabWidth then
        begin
          Widget.left:=Screen.DeskTopRect.right-TabWidth;
          Break;
        end;
        TemLeft:=TemLeft+Speed;
        widget.left:=TemLeft;
      end;
    end;
  end;
  2:  //向上缩进
  begin
    if flag then  //Top<0   弹出
    begin
  		while True do
  		begin
  			if (TemTop>=0) then
  			begin
  				Widget.Top:=0;
  				Break;
  			end;
  			TemTop:=TemTop+Speed;
  			WidGet.Top:=TemTop;
  			// Sleep(5);
  		end;
    end else  //若Top>=0  缩进
  	begin
  		while True do
  		begin
  		  if (TabWidth-TemTop)>=Widget.Height then
  			begin
  				Widget.Top:=TabWidth-Widget.height;
  				Break;
  			end;
  			TemTop:=TemTop-Speed;
  			Widget.Top:=TemTop;
  		end;
  	end;
  end;
  3:  //向下缩进
  begin
    if flag then   //弹出
    begin      
      while True do
      begin
        if widget.Top<=screen.DesktopRect.Bottom-widget.height then
        begin
          widget.Top:=screen.DesktopRect.Bottom-widget.height;
          Break;
        end;
        TemTop:=TemTop-Speed;
        widget.Top:=TemTop;
      end;
    end else   //缩入
    begin    
      while True do
      begin
        if widget.Top>=screen.DesktopRect.Bottom-TabWidth then
        begin
          widget.Top:=screen.DeskTopRect.Bottom-TabWidth;
          Break;
        end;
        TemTop:=TemTop+Speed;
        widget.Top:=TemTop;
      end;
    end;
  end;
  end;
end;

procedure lblInOutBarClick(Sender:TObject);
begin
  if iOnMouseInOut=0 then
  begin
    case g_iDirectionIndex of
    0:ShowHideBar(Widget.left<0,g_iDirectionIndex);
		1:ShowHideBar(Widget.left>=screen.DesktopRect.right-Widget.width,g_iDirectionIndex);
    2:ShowHideBar(Widget.Top<0,g_iDirectionIndex);
    3:ShowHideBar(Widget.Top>=screen.DesktopRect.Bottom-30,g_iDirectionIndex);
    end;
  end;
end;

procedure nCheckMouseInClick(Sender:TObject);
begin
	case iOnMouseInOut of
		0:iOnMouseInOut:=1;
		1:iOnMouseInOut:=0;
	end; 
	SetSettingInt('OnOffCheckMouse',iOnMouseInOut);//保存菜单设置
end;


procedure RefreshPageInfo;
begin
  if ShortcutNums mod imgCount=0 then
    PageCount:=ShortcutNums div imgCount
  else
    PageCount:=(ShortcutNums div imgCount)+1;
  if PageCount=0 then PageCount:=1;
  lblPage.caption:=format('%d / %d',[PageIndex,PageCount]);  
  imgNext.Enabled:=PageIndex<PageCount;
  imgPrev.Enabled:=PageIndex>1;
end;

//刷新当前页面的快捷方式
procedure RefreshShortcut;
var
  ini:TIniFile;
  FirstIndex:integer;
begin
  ini:=TIniFile.create(DataFileName);
  try
    FirstIndex:=(PageIndex-1)*imgCount;
    //if ShortcutNums>0 then
    begin
      for i:=0 to imgCount-1 do
      begin
        if FirstIndex+i<ShortcutNums then
        begin
          imgs[i].visible:=true;
          imgs[i].hint:=ini.ReadString(Section,inttostr(FirstIndex+i)+'caption','');
          s:=ini.ReadString(Section,inttostr(FirstIndex+i)+'path','');
          try
            if not FileExists(s) then s:=WidgetPath+s;
            if FileExists(s) then
            begin
              //showmessage('exists:'+s);
              imgs[i].FileName:=s;
            end
            else
            begin
              //showmessage('no exists:'+s);
              imgs[i].FileName:=WidgetPath+'images\icon'+inttostr(i)+'.png';
            end;
          except
              imgs[i].FileName:=WidgetPath+'images\icon'+inttostr(i)+'.png';
          end
        end
        else
        begin
          imgs[i].FileName:='';
          imgs[i].visible:=false;
        end;
      end;
    end;
  finally
    ini.free;
  end;
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 AddIco(caption:string; Action:string; IcoPath:string);
var
  lst:TStrings;
  i:integer;
  s,s1,s2:string;
  sCaption,sAction,sIcoPath:string;
  ini:TIniFile;
begin
  if Action='' then exit;
  ini:=TIniFile.create(DataFileName);
  try
    s:=inttostr(ShortcutNums);
    sCaption:=Caption;
    sAction:=Action;
    if LowerCase(ExtractFileExt(sAction))='.lnk' then
      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,s+'caption',sCaption);
      ini.WriteString(Section,s+'action',sAction);
      ini.WriteString(Section,s+'path',GetRelativePath(sIcoPath));
      ShortcutNums:=ShortcutNums+1;
      ini.WriteInteger(Section,'count',ShortcutNums);
      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,s+'caption',sCaption);
    ini.WriteString(Section,s+'action',sAction);

//    s1:=ShortcutIconPath+sCaption+'.png';
//    showmsg('l');
    s2:=GetFileIcon(Action);
    if s2<>'' then
    begin
      ini.WriteString(Section,s+'path',GetRelativePath(s2));
      if ShortcutNums<imgCount then
        imgs[ShortcutNums].FileName:=s2;
    end
    else//当没有默认的图标可以使用时，提取文件中的图标或使用默认图标
    begin
      //s1:=WidgetPath+'images\icon'+s+'.png';
      //s2:=WidgetPath+'images\custom\ico'+s+'.png';
      s1:=ShortcutIconPath+ExtractFileName(ChangeFileExt(Action,''));
      s2:=s1+'.png';
      if FileExists(s1+'.png') then
      for i:=1 to 100 do
      begin
        s2:=s1+inttostr(i)+'.png';
        if not FileExists(s2) then break;
      end;
      if GetFileIconToPng(Action,s2) then
      begin
        ini.WriteString(Section,s+'path',GetRelativePath(s2));
        if ShortcutNums<imgCount then
          imgs[ShortcutNums].FileName:=s1;
      end
      else
        ini.WriteString(Section,s+'path',WidgetPath+'images\default.png');
        //showtrayhint('failed',s1);
    end;
    
    ShortcutNums:=ShortcutNums+1;
    ini.WriteInteger(Section,'count',ShortcutNums);
  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 24 do
      	begin
      	  TComponent(sender).tag := i;
      	  addIconMenuClick(sender);
      	end;
      end;
    -5:
      begin
        for i:= 2 to 8 do
      	begin
      	  TComponent(sender).tag := i;
      	  addIconMenuClick(sender);
      	end;
      end;
    -6:
      begin
        for i:= 9 to 13 do
      	begin
      	  TComponent(sender).tag := i;
      	  addIconMenuClick(sender);
      	end;
      end;
    -7:
      begin
        for i:= 14 to 19 do
       	begin
       	  TComponent(sender).tag := i;
       	  addIconMenuClick(sender);
       	end;
      end;
    -8:
      begin
        for i:= 20 to 24 do
      	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:=(PageIndex-1)*imgCount+index;
  if (aIndex<0) or (aIndex>=ShortcutNums) 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('[default]');
    lst.add('count=5');
    lst.add('0caption=我的电脑');
    lst.add('0action=::{20D04FE0-3AEA-1069-A2D8-08002B30309D}');
    lst.add('0path='+'images\soft\computer.png');
    lst.add('1caption=我的文档');
    lst.add('1action=::{450D8FBA-AD25-11D0-98A8-0800361B1103}');
    lst.add('1path='+'images\soft\Documents.png');
    lst.add('2caption=网上邻居');
    lst.add('2action=::{208D2C60-3AEA-1069-A2D7-08002B30309D}');
    lst.add('2path='+'images\soft\network.png');
    lst.add('3caption=IE浏览器');
    lst.add('3action=explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}');
    lst.add('3path='+'images\soft\IExplore.png');
    lst.add('4caption=控制面板');
    lst.add('4action='+sControlPanelGuid);
    lst.add('4path='+'images\soft\controlpanel.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 RunAction(index:integer);
const
  SW_SHOW=1;
  ID_YES=6;
  MB_YESNO=4;
var
  aIndex:integer;
begin
  aIndex:=(PageIndex-1)*imgCount+index;
  s:=LowerCase(GetActionInfo(aIndex,'action'));
  
  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)
      ShellExecute(0,'open', s,'',ExtractFilePath(s),1)
    else
    begin
      //showtrayhint('其它',s);
      r := CreateOleObject('wscript.shell');
      r.run(s);
      r := Unassigned;
    end;
  end;
end;

//删除指定index的快捷方式
procedure DelShortcut(index:integer);
var
  aIndex:integer;
  ini:TIniFile;
  s1,s2:string;
begin
  aIndex:=(PageIndex-1)*imgCount+index;
  if (aIndex<0) or (aIndex>=ShortcutNums) then exit;
  ini:=TIniFile.create(DataFileName);
  try
    //showmessage(aindex);
    s1:=ini.ReadString(Section,inttostr(aIndex)+'path','');
    //如果是自动生成的data目录下的png图片，则自动删除，以免产生垃圾
    if LowerCase(ExtractFilePath(s1))=ShortcutIconPath then
      DeleteFile(s1);
      for i:=aIndex+1 to ShortcutNums-1 do
      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;
    ShortcutNums:=ShortcutNums-1;
    s1:=inttostr(Shortcutnums);
    ini.DeleteKey(Section,s1+'caption');
    ini.DeleteKey(Section,s1+'action');
    ini.DeleteKey(Section,s1+'path');
    ini.writeinteger(Section,'count',ShortcutNums);
  finally
    ini.free;
  end;
  RefreshPageInfo;
  RefreshShortcut;
end;

//清空所有快捷方式
procedure nClearAllClick(Sender:TObject);
var
  ini:TIniFile;
begin
  ini:=TIniFile.create(DataFileName);
  try
    ini.EraseSection(Section);
  finally
    ini.free;
  end;
  //DeleteFile(DataFileName);
  ShortcutNums:=0;
  RefreshPageInfo;
  RefreshShortcut;
end;

//上一页
procedure imgPrevClick(Sender:TObject);
begin
  BeginUpdate;
  PageIndex:=PageIndex-1;
  RefreshShortcut;
  RefreshPageInfo;
  EndUpdate;
end;

//下一页
procedure imgNextClick(Sender:TObject);
begin
  BeginUpdate;
  PageIndex:=PageIndex+1;
  RefreshShortcut;
  RefreshPageInfo;
  EndUpdate;
end;

//初始化小工具的显示位置
Procedure InitLookingByDircetion(aIndex:Integer);
var
  i:Integer;
begin
  BeginUpdate;
  if Widget.left<0 then widget.left:=0;
  if widget.Top<0 then widget.Top:=0;  //防止改变伸缩方向后不可见
  TMenuItem(g_lstMenu.Objects[g_iDirectionIndex]).checked:=True;
  case aIndex of
  0:Begin //向左缩进
      imgbg.Filename:=AppPath+'Widgets\DeskTabShortcut\images\bg_Trans.png';
      imgPrev.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnPrev.png';
      imgNext.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnNext.png';      
      Widget.width:=430;
      Widget.height:=66;
      imgbg.width:=424;
      imgbg.height:=66;
      lblInOutBar.top:=12;
      lblInOutBar.left:=400;
      lblInOutBar.width:=16;
      lblInOutBar.height:=40; 
      lblPage.Top:=25;
      lblPage.left:=315;
      lblPage.width:=60;
      lblPage.height:=12;
      imgPrev.Left:=6;
      imgPrev.Top:=23;
      imgNext.left:=380;
      imgNext.Top:=23;
      imgAdd.Left:=8;
      for i:=0 to g_lstImage.count-1 do
      begin
        TXspImage(g_lstImage.objects[i]).left:=35+(i*35);
        TXspImage(g_lstImage.objects[i]).top:=15;
      end; 
    end;
  1:begin  //向右缩进
      imgbg.Filename:=AppPath+'Widgets\DeskTabShortcut\images\bg_Trans_Right.png';
      imgPrev.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnPrev.png';
      imgNext.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnNext.png';
      Widget.width:=420;
      Widget.height:=66;
      imgbg.width:=424;
      imgbg.height:=66;
      lblInOutBar.top:=12;
      lblInOutBar.left:=8;
      lblInOutBar.width:=16;
      lblInOutBar.height:=40;
      for i:=0 to g_lstImage.count-1 do
      begin
        TXspImage(g_lstImage.objects[i]).left:=70+(i*35);
        TXspImage(g_lstImage.objects[i]).top:=18;
      end;        
      lblPage.width:=32;
      lblPage.Left:=35;
      lblPage.Top:=28;
      imgPrev.Left:=25;
      imgPrev.Top:=23;
      imgNext.left:=380;
      imgNext.Top:=23;
      imgAdd.Left:=385;
    end;
  2:begin  //向上缩进
      Widget.width:=66;
      Widget.height:=430;
      imgbg.FileName:=AppPath+'Widgets\DeskTabShortcut\images\bg_Trans_Top.png';
      imgPrev.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnPrev_Top.png';
      imgNext.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnNext_Top.png';      
      imgbg.width:=66;
      imgbg.height:=424;
      for i:=0 to g_lstImage.count-1 do
      begin
        TXspImage(g_lstImage.objects[i]).top:=35+(i*35);
        TXspImage(g_lstImage.objects[i]).Left:=18;
      end;  
      imgAdd.Top:=8;
      imgAdd.Left:=8;
      lblPage.Top:=370;
      imgPrev.Top:=18;
      imgNext.Top:=380;
      lblInOutBar.Top:=400;
      lblInOutBar.width:=40;
      lblInOutBar.Height:=16;
      lblInOutBar.Left:=12;
      lblPage.width:=40;
      lblPage.Left:=8;
      imgPrev.Left:=25;
      imgNext.Left:=25;
    end;
  3:begin //向下缩进
      imgbg.Filename:=AppPath+'Widgets\DeskTabShortcut\images\bg_Trans_Bottom.png';
      imgPrev.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnPrev_Top.png';
      imgNext.FileName:=AppPath+'Widgets\DeskTabShortcut\images\btnNext_Top.png';      
      Widget.width:=66;
      Widget.height:=430; 
      imgbg.width:=66;
      imgbg.height:=424;
      for i:=0 to g_lstImage.count-1 do
      begin
        TXspImage(g_lstImage.objects[i]).top:=45+(i*35);
        TXspImage(g_lstImage.objects[i]).Left:=16;
      end;
      imgPrev.Left:=25;
      imgNext.Left:=25;
      imgPrev.Top:=25;
      imgNext.Top:=390;
      imgAdd.Top:=395;
      lblPage.Top:=375;
      lblPage.width:=40;
      lblPage.Left:=6;
      lblInOutBar.Top:=8;
      lblInOutBar.width:=40;
      lblInOutBar.Height:=16;
      lblInOutBar.Left:=12;
    end;
  end;
  EndUpdateAll;
  ShowHideBar(False,g_iDirectionIndex); //初始化为缩入状态
end;

procedure SelectDirClicked(sender:TMenuItem);
var
  i:integer;
begin
  TMenuItem(g_lstMenu.Objects[g_iDirectionIndex]).checked:=False;
  g_iDirectionIndex:=sender.tag;
  SetSettingInt('DirctionIndex',g_iDirectionIndex);
  InitLookingByDircetion(sender.tag);
end;

procedure MoveNextShortcut(index:integer);
var
  aIndex:integer;
  ini:TIniFile;
  s1,s2:string;
  varcaption,varaction,varpath:string;
begin
  aIndex:=(PageIndex-1)*imgCount+index;
  if (aIndex<0) or (aIndex>=ShortcutNums-1) then exit;
  ini:=TIniFile.create(DataFileName);
  try
    if aIndex+1<ShortCutNums then
    begin
      s1:=inttostr(aIndex);
      s2:=inttostr(aIndex+1);
      
      varcaption:=ini.ReadString(Section,s1+'caption','');
      varaption:=ini.ReadString(Section,s1+'action','');
      varpath:=ini.ReadString(Section,s1+'path','');
      
      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',''));
      
      ini.WriteString(Section,s2+'caption',varcaption);
      ini.WriteString(Section,s2+'action',varaption);
      ini.WriteString(Section,s2+'path',varpath);    
    
    end;  
  finally
    ini.free;
  end;
  RefreshPageInfo;
  RefreshShortcut;
end;

procedure MovePriorShortcut(index:integer);
var
  aIndex:integer;
  ini:TIniFile;
  s1,s2:string;
  varcaption,varaction,varpath:string;
begin
  aIndex:=(PageIndex-1)*imgCount+index;
 // showmessage(inttostr(ShortcutNums) + inttostr(aindex));
  if (aIndex<=0) or (aIndex>=ShortcutNums) then exit;
  ini:=TIniFile.create(DataFileName);
  try
    if aIndex+1<=ShortCutNums then
    begin
      s1:=inttostr(aIndex-1);
      s2:=inttostr(aIndex);
      
      varcaption:=ini.ReadString(Section,s1+'caption','');
      varaption:=ini.ReadString(Section,s1+'action','');
      varpath:=ini.ReadString(Section,s1+'path','');
      
      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',''));
      
      ini.WriteString(Section,s2+'caption',varcaption);
      ini.WriteString(Section,s2+'action',varaption);
      ini.WriteString(Section,s2+'path',varpath);    
    
    end;  
  finally
    ini.free;
  end;
  RefreshPageInfo;
  RefreshShortcut;
end;


procedure miOpenOnClick(sender);
begin
  if (SelIndex>=0) and (SelIndex<imgCount) then
    RunAction(SelIndex)
//  else
//    showmessage('no');
end;

procedure miDelOnClick(sender);
begin
//  showmessage('tag:'+inttostr(SelIndex));
  if (SelIndex>=0) and (SelIndex<imgCount) then
    DelShortcut(SelIndex);
end;

procedure miPropertyOnClick(sender);
begin
  if (SelIndex>=0) and (SelIndex<imgCount) then
    ShowShortcutProperty(SelIndex);
end;


procedure miMovePriorOnClick(sender);
begin
  if (SelIndex>=0) and (SelIndex<imgCount) then
   // showmessage('prior'); 
   MovePriorShortcut(SelIndex)
end;

procedure miMoveNextOnClick(sender);
begin
  if (SelIndex>=0) and (SelIndex<imgCount) then
    MoveNextShortcut(SelIndex); 
end;

//初始化快捷方式的右键菜单
procedure InitMenu;
begin
  pmenu:=TPopupMenu.Create(Widget);
  pmenu.AutoHotkeys:=maManual;
  
  miMoveNext:=TMenuItem.Create(Widget);
  miMoveNext.Caption:='向后移';
  miMoveNext.onclick:='miMoveNextOnClick';
  pmenu.Items.Insert(0,miMoveNext);
  
  miMovePrior:=TMenuItem.Create(Widget);
  miMovePrior.Caption:='向前移';
  miMovePrior.onclick:='miMovePriorOnClick';
  pmenu.Items.Insert(0,miMovePrior); 
  
  miInterval:=TMenuItem.Create(Widget);
  miInterval.Caption:='-';
  pmenu.Items.Insert(0,miInterval);  

  miProperty:=TMenuItem.Create(Widget);
  miProperty.Caption:='快捷方式属性';
  miProperty.onclick:='miPropertyOnClick';
  pmenu.Items.Insert(0,miProperty);

  miDel:=TMenuItem.Create(Widget);
  miDel.Caption:='删除快捷方式';
  miDel.onclick:='miDelOnClick';
  pmenu.Items.Insert(0,miDel);

  miInterval:=TMenuItem.Create(Widget);
  miInterval.Caption:='-';
  pmenu.Items.Insert(0,miInterval);

  miOpen:=TMenuItem.Create(Widget);
  miOpen.Caption:='打开';
  miOpen.onclick:='miOpenOnClick';
  miOpen.default:=true;
  pmenu.Items.Insert(0,miOpen);
end;

//读取当前Widget的INI设置
procedure InitIni;
var
  ini:TIniFile;
begin
  ini:=TIniFile.create(DataFileName);
  try
    ShortcutNums:=ini.ReadInteger(Section,'count',0);
    PageIndex:=1;
      //showtrayhint(ShortcutNums,inttostr(ShortcutNums mod imgCount));
    RefreshPageInfo;
    RefreshShortcut;
  finally
    ini.free;
  end;
end;

//--- Widget移入边栏事件，当Widget被移到边栏上时会触发此事件 ---
procedure OnWidgetDock;
begin
{ BeginUpdate;
  Widget.Width:=136;
  EndUpdateall;}
end;

//--- Widget移出边栏事件，当Widget被移出边栏时会触发此事件 ---
procedure OnWidgetUnDock;
begin
  BeginUpdate;
  Widget.Width:=424;
  EndUpdate;
end;

//--- Widget初始化事件，当打开Widget时会触发此事件 ---
procedure OnWidgetInit;
var
  i:integer;
begin
  g_lstImage:=TStringList.Create;
  g_lstMenu:=TStringList.Create;
  g_lstImage.AddObject('',img0);
  g_lstImage.AddObject('',img1);
  g_lstImage.AddObject('',img2);
  g_lstImage.AddObject('',img3);
  g_lstImage.AddObject('',img4);
  g_lstImage.AddObject('',img5);
  g_lstImage.AddObject('',img6);
  g_lstImage.AddObject('',img7);
  g_lstImage.AddObject('',img8);
  g_lstMenu.AddObject('',nDir0);
  g_lstMenu.AddObject('',nDir1);
  g_lstMenu.AddObject('',nDir2);
  g_lstMenu.AddObject('',nDir3);
  for i:=0 to g_lstMenu.count-1 do
  begin
    TMenuItem(g_lstMenu.Objects[i]).OnClick:='SelectDirClicked';
    TMenuItem(g_lstMenu.Objects[i]).tag:=i;
  end;
  g_iDirectionIndex:=GetSettingInt('DirctionIndex','0');  //读取用户设置的方向
  if isWinVista then
    sControlPanelGUID:='::{21EC2020-3AEA-1069-A2DD-08002B30309D}' 
  else
    sControlPanelGUID:='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}';
  frm:=nil;
  DataFileName:=AppPath+'Data\'+WidgetName+'.dat';
  ShortcutIconPath:=LowerCase(WidgetPath+'images\ShortcutIconPath\'+WidgetName+'\');
  Section:='default';
  if not FileExists(DataFileName) then
    //CopyFile(WidgetPath+'default.dat',DataFileName);
    InitShortcut;
  if not DirectoryExists(ShortcutIconPath) then
    ForceDirectories(ShortcutIconPath);
  Imgs:=[img0,img1,img2,img3,img4,img5,img6,img7,img8];
  BeginUpdate;
  InitIni;
  InitMenu;
	lblInOutBar.caption:=GetSetting('TabCaption','工具');
  InitLookingByDircetion(g_iDirectionIndex);

  for i:=0 to ImgCount-1 do
  begin
    imgs[i].tag:=i;
    imgs[i].onclick:='ImgClick';
    imgs[i].OnMouseEnter:='imgMouseEnter';
    imgs[i].OnMouseLeave:='imgMouseLeave';
    imgs[i].PopupMenu:=pmenu;
    //imgs[i].Width:=24;
    //imgs[i].Height:=24;
  end;
	iOnMouseInOut:=GetSettingInt('OnOffCheckMouse',0);//读取菜单设置
	case iOnMouseInOut of
		0:nCheckMouseIn.checked:=False;
		1:nCheckMouseIn.checked:=True;
	end;
	bMenuPopUp:=False;
	SetAllowMoveWidget(lblInOutBar,true);
  EndUpdate;
end;

//--- Widget关闭事件，当关闭Widget时会触发此事件 ---
procedure OnWidgetClose;
begin
  miProperty.free;
  miDel.free;
  miOpen.free;
  miInterval.free;
  pmenu.free;
  g_lstImage.free;
  g_lstMenu.free;
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 ImgClick(sender);
begin 
  RunAction(sender.tag);
end;

procedure imgMouseEnter(sender);
begin
  img:=imgs[sender.tag];
  BeginUpdate;
  imgHover.left:=img.left-2;
  imgHover.top :=img.top-2;
  imgHover.visible:=true;
  EndUpdate;
  SelIndex:=sender.tag;
end;

procedure imgMouseLeave(sender);
begin
  BeginUpdate;
  imgHover.visible:=false;
  imgHover.NeedRefresh:=true;
  imgs[sender.tag].NeedRefresh:=true;
  EndUpdate;
  //SelIndex:=-1;
end;

Procedure OnWidgetDeactivate;//小工具失去焦点，缩进
begin
	if iOnMouseInOut=0 then
  begin
    ShowHideBar(False,g_iDirectionIndex);
  end;
end;

procedure OnApplicationDeactivate;//应用程序失去焦点,缩进
begin
 bMenuPopUp:=False;
  if iOnMouseInOut=0 then
		ShowHideBar(False,g_iDirectionIndex);
end;

procedure OnWidgetMouseEnter;//当鼠标移入小工具
begin
	if iOnMouseInOut=1 then
	begin
		ShowHideBar(True,g_iDirectionIndex);
	end;
end;

procedure OnWidgetMouseLeave;//当鼠标移出小工具
begin
	if (iOnMouseInOut=1) And (not bMenuPopUp) then
	begin
		ShowHideBar(False,g_iDirectionIndex);
	end;
  bMenuPopUp:=false;
end;

//--- 文件拖放到事件，当文件拖放到Widget中时会触发此事件 ---
procedure OnWidgetDropFiles(Files:string);
var
  lst:TStrings;
  i:integer;
  s,s1,s2:string;
begin
  if Files<>'' then
  begin
    lst:=TStringList.create;
    try
      lst.text:=Files;
      if lst.count>0 then
      begin
        for i:=0 to lst.count-1 do
        begin
          //showmsg(lst.strings[i]);
          AddIco('',lst.strings[i],'');
        end;
        RefreshPageInfo;
        RefreshShortcut;
        //InitIni;
      end;
    finally
      lst.free;
    end;
  end;
end;

procedure imgAddClick(Sender:TObject);
begin
  InitShortcutMenu;
end;