开发一个delphi写的桌面图标管理代码
参加工作了就很少有时间去玩delphi了,这个适合初学者看看,大神勿喷 工具 delhpi7.0 access数据库 原则win下有安装office就可用 当初不太熟悉sqlite所有没用这做数据库。
{***************************************************************************** * 版本信息: * 浅诺桌面管理工具v1.0 * 文件名称: * UseShortcutKey.pas * 内容摘要: * 桌面快捷方式管理(分类及运行) * 历史记录: * 2013.1.28 created by xzj * 大型修改: * 2013.2.5 modified by xzj * 快捷方式名称不显示快捷方式ID,相关功能做相应的修改,将ID存放在数组naID中 * * 程序为作者原创,修改请保留作者信息,改后程序可发至作者邮箱共同参考、共同进步, * 谢谢支持。 ******************************************************************************} unit UseShortcutKey; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, TntStdCtrls, jpeg, ExtCtrls, TntExtCtrls, TntForms, ComCtrls, TntComCtrls, ImgList, DB, ADODB, Menus, TntMenus, Buttons, RzTray, TntButtons, Spin, RzButton, Mask, RzEdit, RzBtnEdt, RzBmpBtn, RzCmboBx, RzTabs, RzTrkBar, WinSkinStore, WinSkinData; const WM_MouseEnter = $B013; WM_MouseLeave = $B014; type TFormUse = class(TForm) imglogo: TTntImage; lblName: TTntLabel; lbl1: TTntLabel; lbl2: TTntLabel; tntscrlbxType: TTntScrollBox; tntpmnType: TTntPopupMenu; tmr1: TTimer; con1: TADOConnection; qryCmd: TADOQuery; il1: TImageList; ImageTxt: TImage; ImageRAR: TImage; ImageFiles: TImage; ImageMDB: TImage; ImageXLS: TImage; ImageDOC: TImage; ImagePPT: TImage; Imagepsd: TImage; ImagePhoto: TImage; Imagepdf: TImage; ImageDPR: TImage; ImagePAS: TImage; Imagedfm: TImage; ImageDLL: TImage; ImageWZ: TImage; Image1: TImage; Image2: TImage; rztrycn1: TRzTrayIcon; tntmntmAdd: TTntMenuItem; tntpgcntrl1: TTntPageControl; pg1: TTntTabSheet; edtAdd: TTntEdit; pg2: TTntTabSheet; edtEdt: TTntEdit; tntmntmqx: TTntMenuItem; tntpmnPro: TTntPopupMenu; tntmntmEdtPro: TTntMenuItem; tntmntmDelPro: TTntMenuItem; tntmntmTail: TTntMenuItem; tntmntmList: TTntMenuItem; tntmntmdefault: TTntMenuItem; tntmntmN1: TTntMenuItem; tntmntmWc: TTntMenuItem; tntpmnOperbtn: TTntPopupMenu; tntmntmEdit: TTntMenuItem; tntmntmdelete: TTntMenuItem; lbl3: TTntLabel; edtnow: TTntEdit; lbl4: TTntLabel; tntmntmN2: TTntMenuItem; tntmntmhide: TTntMenuItem; N1: TTntMenuItem; tntmntmdelall: TTntMenuItem; Imagebat: TImage; tntmntmdelalltype: TTntMenuItem; tntmntmN3: TTntMenuItem; tntcntrlbr1: TTntControlBar; tntmntmSendLink: TTntMenuItem; tntmntmN4: TTntMenuItem; tntpmnPC: TTntPopupMenu; btnPC: TRzMenuButton; btn1: TRzShapeButton; tntpmnMN: TTntPopupMenu; tntmntmClose: TTntMenuItem; tmr2: TTimer; tntmntmAutoOpen: TTntMenuItem; tntmntmSendAll: TTntMenuItem; edtTime: TTntEdit; tmr3: TTimer; tmrRe: TTimer; edtKeyNow: TTntEdit; tmrsx: TTimer; pnl1: TPanel; grp1: TGroupBox; qrySet: TADOQuery; qryInit: TADOQuery; tntpgcntrl2: TRzPageControl; pg3: TRzTabSheet; lvPro: TTntListView; pg4: TRzTabSheet; mmo1: TTntMemo; pg5: TRzTabSheet; tntpnl1: TTntPanel; tntmntmN5: TTntMenuItem; tntmntmexit: TTntMenuItem; tntmntmHideZT: TTntMenuItem; tntmntmHideV: TTntMenuItem; grp2: TTntGroupBox; lbl5: TTntLabel; cbbFC: TRzColorComboBox; lbl6: TTntLabel; cbbFONTC: TRzColorComboBox; cbbGC: TRzColorComboBox; lbl7: TTntLabel; lbl9: TTntLabel; cbbEC: TRzColorComboBox; cbbFT: TRzComboBox; lbl8: TTntLabel; lbl11: TTntLabel; cbbHD: TRzComboBox; cbbSH: TRzComboBox; lbl10: TTntLabel; lbl12: TTntLabel; rztrckbr1: TRzTrackBar; dlgFont1: TFontDialog; lbl13: TTntLabel; btn2: TRzButtonEdit; skndt1: TSkinData; sknstr1: TSkinStore; procedure FormCreate(Sender: TObject); procedure BtnTypeClick (Sender: TObject); procedure LoadShortcutKey(Sender : TObject); procedure tmr1Timer(Sender: TObject); procedure edtAddKeyPress(Sender: TObject; var Key: Char); procedure tntmntmAddClick(Sender: TObject); procedure edtEdtKeyPress(Sender: TObject; var Key: Char); procedure Openqry(var qry1 : TADOQuery; sqltxt : string); procedure Execqry(var qry1 : TADOQuery; sqltxt : string); procedure tntmntmqxClick(Sender: TObject); procedure lvProDblClick(Sender: TObject); procedure tntmntmTailClick(Sender: TObject); procedure tntmntmListClick(Sender: TObject); procedure tntmntmdefaultClick(Sender: TObject); procedure tntmntmEdtProClick(Sender: TObject); procedure tntmntmWcClick(Sender: TObject); procedure LBWindowProc(var Message: TMessage); procedure WMDROPFILES_L(var Msg: TMessage); procedure tntmntmDelProClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure tntmntmEditClick(Sender: TObject); procedure tntmntmdeleteClick(Sender: TObject); procedure tntmntmhideClick(Sender: TObject); procedure lvProMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure tntmntmdelallClick(Sender: TObject); procedure lvProEdited(Sender: TObject; Item: TTntListItem; var S: WideString); procedure lvProKeyPress(Sender: TObject; var Key: Char); procedure tntmntmdelalltypeClick(Sender: TObject); procedure CreateLink(programPath,programArg,LinkPath,Descr : string); procedure tntmntmSendLinkClick(Sender: TObject); procedure GetSystemPath(); procedure MenuBtnOnClick(Sender : TObject); procedure btn1Click(Sender: TObject); procedure tntmntmCloseClick(Sender: TObject); //procedure tmr2Timer(Sender: TObject); procedure tntmntmAutoOpenClick(Sender: TObject); procedure tntmntmSendAllClick(Sender: TObject); procedure tmr3Timer(Sender: TObject); procedure tmrReTimer(Sender: TObject); procedure tmrsxTimer(Sender: TObject); procedure cbbFCChange(Sender: TObject); procedure cbbFONTCChange(Sender: TObject); procedure cbbGCChange(Sender: TObject); procedure cbbECChange(Sender: TObject); procedure cbbFTChange(Sender: TObject); procedure cbbHDChange(Sender: TObject); procedure cbbSHChange(Sender: TObject); procedure InitForm(); procedure AddInitForm(); procedure tntmntmexitClick(Sender: TObject); procedure tntmntmHideZTClick(Sender: TObject); procedure tntmntmHideVClick(Sender: TObject); procedure rztrckbr1Change(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure imglogoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure tntpnl1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure grp2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure tntpgcntrl2Change(Sender: TObject); procedure btn2ButtonClick(Sender: TObject); private { Private declarations } abtnType: array[1..50] of TRzBitBtn; //分组按钮 anID : array[0..500] of Integer; sActiveBtn : string; //当前活动的按钮 SYS_COLOR : TColor; //窗体颜色 FONT_COLOR : TColor; //字体颜色 GROUP_COLOR : TColor; //被选中的分组字体颜色 EDITING_COLOR : TColor; //修改时界面颜色 HIDE_DIRECTION : string; //窗体隐藏方向 sTypeLoadFlag : string; //类型加载标识(用于不重复加载) procedure WMMouseEnter(var Msg: TMessage); message WM_MouseEnter; procedure QNLoadType(); public { Public declarations } end; var FormUse: TFormUse; sPath: string; sType: string; hInNow : HKL; //当前输入法 keyValue : string; //按键查询 isEditing : Boolean; //是否是编辑状态 RWindowProc: TWndMethod; LWindowProc: TWndMethod; OldBtn : TRzBitBtn; implementation uses registry, shlobj, ActiveX, ComObj, ShellAPI; {$R *.dfm} {**************************************************************** * 过程名称: Openqry * 功能描述: 数据库查询 * 参数说明: TADOQuery,string * 返 回 值: 无 * 历史记录: 2013.1.28 created by xzj *****************************************************************} procedure TFormUse.Openqry(var qry1 : TADOQuery; sqltxt : string); begin with qry1 do begin Close; sql.clear; sql.add(sqltxt); Open; end; end; {**************************************************************** * 过程名称: Execqry * 功能描述: 数据库操作 * 参数说明: TADOQuery,string * 返 回 值: 无 * 历史记录: 2013.1.28 created by xzj *****************************************************************} procedure TFormUse.Execqry(var qry1 : TADOQuery; sqltxt : string); begin with qry1 do begin Close; sql.clear; sql.add(sqltxt); ExecSQL; end; end; {**************************************************************** * 过程名称: WMMouseEnter * 功能描述: 鼠标碰到隐藏的窗体,窗体下拉 * 参数说明: TMessage * 返 回 值: 无 * 历史记录: 2013.1.28 created by xzj *****************************************************************} procedure TFormUse.WMMouseEnter(var Msg: TMessage); var iIndex : Integer; begin if (Top < 0) and (HIDE_DIRECTION = \'向上隐藏\') then begin //while(Top < 0) do //begin // iIndex := 10; // Top := Top + 2; // while(iIndex > 0) do // begin // iIndex := iIndex - 1; // end; //end; Top := 0; //为保证下拉窗体后呈现在最前面 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //将窗体推到最前 //发现不取消效果更好 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //然后取消窗体最前 end else if (Left < 0) and (HIDE_DIRECTION = \'向左隐藏\') then begin Left := 0; //为保证下拉窗体后呈现在最前面 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //将窗体推到最前 //发现不取消效果更好 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //然后取消窗体最前 end else if ((Left + Self.Width) > screen.Width) and (HIDE_DIRECTION = \'向右隐藏\') then begin Left := Screen.Width - Self.Width; //为保证下拉窗体后呈现在最前面 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //将窗体推到最前 //发现不取消效果更好 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //然后取消窗体最前 end else if ((Top + Self.Height) > Screen.Height) and (HIDE_DIRECTION = \'向下隐藏\') then begin Top := Screen.Height - Self.Height; //为保证下拉窗体后呈现在最前面 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //将窗体推到最前 //发现不取消效果更好 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); //然后取消窗体最前 end; Tmr1.Enabled := True; end; {**************************************************************** * 过程名称: GetTempDirectory * 功能描述: 取系统临时路径 * 参数说明: 无 * 返 回 值: string 路径 * 历史记录: 2013.1.28 created by xzj *****************************************************************} function GetTempDirectory: string; var TempDir: array[0..255] of Char; begin GetTempPath(255, @TempDir); Result := StrPas(TempDir); end; {**************************************************************** * 过程名称: QNLoadType * 功能描述: 加载类型选择按钮 * 参数说明: 无 * 返 回 值: 无 * 历史记录: 2013.1.28 created by xzj *****************************************************************} procedure TFormUse.QNLoadType(); var i, j,k,nRand : Integer; bmpName : string; begin Randomize; with qryCmd do begin Close; SQL.Clear; SQL.Add(\'select * from PRO_TYPE\'); Open; end; //加载前释放所有内存,防止内存冲突 for k := 1 to 49 do begin if abtnType[k] <> nil then begin abtnType[k].Destroy; abtnType[k] := nil; end; end; nRand := Random(97) + 1; qryCmd.First; //默认让第一个按钮为‘所有程序’ abtnType[1] := TRzBitBtn.Create(Self); abtnType[1].Height := 30; abtnType[1].Width := tntscrlbxType.Width - 5; abtnType[1].Top := 1; abtnType[1].Left := tntscrlbxType.Left; abtnType[1].Name := \'btn_0\'; abtnType[1].Parent := tntscrlbxType; abtnType[1].Caption := \'所有程序\'; abtnType[1].ParentColor := True; abtnType[1].ParentFont := True; bmpName := \'emotions\\' + IntToStr(nRand) + \'fixed.bmp\'; abtnType[1].Glyph.LoadFromFile(bmpName); abtnType[1].OnClick := BtnTypeClick; abtnType[1].Visible := True; OldBtn := abtnType[1]; for i := 1 to qryCmd.RecordCount do begin nRand := Random(95) + 1; abtnType[i + 1] := TRzBitBtn.Create(Self); abtnType[i + 1].Height := 30; abtnType[i + 1].Width := tntscrlbxType.Width - 5; j := trunc(i / 1); abtnType[i + 1].Top := 1 + (abtnType[i + 1].Height + 1) * j; j := i mod 1; abtnType[i + 1].Left := abtnType[i + 1].Width * (j); abtnType[i + 1].Name := \'btn_\' + inttostr(i + 1); abtnType[i + 1].Parent := tntscrlbxType; abtnType[i + 1].Caption := qryCmd.FieldByName(\'PRO_TYPE\').Value; abtnType[i + 1].ParentColor := True; abtnType[i + 1].ParentFont := True; abtnType[i + 1].PopupMenu := tntpmnOperbtn; bmpName := \'emotions\\' + IntToStr(nRand + 1) + \'fixed.bmp\'; abtnType[i + 1].Glyph.LoadFromFile(bmpName); abtnType[i + 1].OnClick := BtnTypeClick; abtnType[i + 1].Visible := True; //nNewTop := abtnType[i + 1].Top + 31; qryCmd.next; end; tntpgcntrl1.Visible := False; end; {**************************************************************** * 过程名称: LoadShortcutKey * 功能描述: 加载快捷方式 * 参数说明: Sender : TObject * 返 回 值: 无 * 历史记录: 2013.1.28 created by xzj *****************************************************************} procedure TFormUse.LoadShortcutKey(Sender : TObject); var i : Integer; lListItem: TListItem; bmp: TBitmap; sFilePath: string; begin qryCmd.First; il1.Clear; lvPro.Clear; for i := 0 to qryCmd.RecordCount - 1 do begin lListItem := lvPro.Items.Add; lListItem.Caption := Trim(qryCmd.fieldbyname(\'PRO_NAME\').value); lListItem.ImageIndex := i; anID[lListItem.ImageIndex] := qryCmd.fieldbyname(\'ID\').value; //读取程序图标 sFilePath := qryCmd.FieldByName(\'PRO_PATH\').Value; if (LowerCase(ExtractFileExt(sFilePath))) = \'\' then image1.Picture := ImageFiles.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.txt\' then image1.Picture := ImageTxt.Picture else if ((LowerCase(ExtractFileExt(sFilePath))) = \'.rar\') or ((LowerCase(ExtractFileExt(sFilePath))) = \'.zip\') then image1.Picture := ImageRAR.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.mdb\' then image1.Picture := ImageMDB.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.xls\' then image1.Picture := Imagexls.Picture else if ((LowerCase(ExtractFileExt(sFilePath))) = \'.doc\') or ((LowerCase(ExtractFileExt(sFilePath))) = \'.docx\') then image1.Picture := Imagedoc.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.ppt\' then image1.Picture := Imageppt.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.pdf\' then image1.Picture := Imagepdf.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.psd\' then image1.Picture := Imagepsd.Picture else if ((LowerCase(ExtractFileExt(sFilePath))) = \'.jpg\') or ((LowerCase(ExtractFileExt(sFilePath))) = \'.bmp\') or ((LowerCase(ExtractFileExt(sFilePath))) = \'.jpeg\') or ((LowerCase(ExtractFileExt(sFilePath))) = \'.gif\') or ((LowerCase(ExtractFileExt(sFilePath))) = \'.cdr\') then image1.Picture := ImagePhoto.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.dpr\' then image1.Picture := Imagedpr.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.dfm\' then image1.Picture := Imagedfm.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.pas\' then image1.Picture := Imagepas.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.dll\' then image1.Picture := Imagedll.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.bat\' then image1.Picture := Imagebat.Picture else if (LowerCase(ExtractFileExt(sFilePath))) = \'.exe\' then image1.Picture.Icon.handle := ExtractIcon(hInstance, pchar(sFilePath), 0) else image1.Picture := Imagewz.Picture; bmp := TBitmap.Create; bmp.width := image1.Picture.Width; bmp.height := image1.Picture.Height; bmp.canvas.Draw(0, 0, image1.Picture.Graphic); bmp.SaveToFile(GetTempDirectory + \'QNsystem.bmp\'); image2.Picture.LoadFromFile(GetTempDirectory + \'QNsystem.bmp\'); il1.Add(image2.Picture.Bitmap, image2.Picture.bitmap); qryCmd.Next; end; qryCmd.Close; end; {**************************************************************** * 过程名称: BtnTypeClick * 功能描述: 类型按钮响应 * 参数说明: Sender : TObject * 返 回 值: 无 * 历史记录: 2013.1.28 created by xzj * 修改描述: 2013.2.3 modified by xzj * 添加按钮颜色改变功能,当前分组变为绿色 * 2013.2.17 modified by xzj * 如果类型选择与先前一样则不重复加载快捷方式 * 2013.2.18 modified by xzj * 修改2.17所修改的不重复加载,编辑后刷新问题 *****************************************************************} procedure TFormUse.BtnTypeClick(Sender : TObject); var sqltxt : string; begin keyValue := \'\'; //按钮直接查询要用的初始化 if ActiveControl.ClassType <> TRzBitBtn then Exit; if Copy(ActiveControl.Name,1,4) <> \'btn_\' then Exit; sType := TRzBitBtn(Sender).Caption; if (sTypeLoadFlag = sType) and (isEditing = false) then begin tntpgcntrl2.ActivePage := pg3; Exit; end; //按钮颜色改变 sTypeLoadFlag := sType; OldBtn.Font.Color := FONT_COLOR; OldBtn.ParentFont := True; TRzBitBtn(Sender).Font.Color := GROUP_COLOR; OldBtn := TRzBitBtn(Sender); if TRzBitBtn(Sender).Name = \'btn_0\' then begin sqltxt := \'select * from PRO_LIST order by PRO_NAME\'; end else begin sqltxt := \'select * from PRO_LIST where PRO_TYPE = \'\'\' + sType + \'\'\' order by PRO_NAME\'; end; with qryCmd do begin Close; SQL.Clear; SQL.Add(sqltxt); Open; end; sActiveBtn := sType; edtnow.Text := sActiveBtn; pg3.Caption := sActiveBtn; LoadShortcutKey(Sender); tntpgcntrl2.ActivePage := pg3; end; {**************************************************************** * 过程名称: FormCreate * 功能描述: 数据库连接,加载分组 * 参数说明: Sender : TObject * 返 回 值: 无 * 历史记录: 2013.1.29 created by xzj *****************************************************************} procedure TFormUse.FormCreate(Sender: TObject); var sDir, connTmp: string; begin getdir(0, sPath); sDir := ExtractFilePath(Application.ExeName); chDir(sDir); // 设置工作目录为程序目录。 SetCurrentDir(sDir); connTmp := \'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\' + sDir + \'\LIST.accdb;Persist Security Info=False\'; con1.ConnectionString := connTmp; con1.Open; TOP := 0; LEFT := 0; FormUse.Width := screen.Width div 2 - 20; FormUse.Height := screen.Height - 32; tntpgcntrl2.Align := alclient; lvPro.Align := alclient; InitForm(); QNLoadType; //加载类型按钮 end; {**************************************************************** * 过程名称: tmr1Timer * 功能描述: 鼠标不在软件界面时自动隐藏界面 * 参数说明: Sender : TObject * 返 回 值: 无 * 历史记录: 2013.1.29 created by xzj * 修改描述: 2013.2.1 modified by xzj * 添加发送桌面快捷方式控制 *****************************************************************} procedure TFormUse.tmr1Timer(Sender: TObject); var rc: TRECT; pt: TPOINT; begin if isEditing = True then begin Exit; end; GetWindowRect(self.Handle, rc); //取窗体的矩形区域 GetCursorPos(pt); //取得当前鼠标所在位置 if (not PtInRect(rc, pt)) then //如果鼠标不在窗体范围内 begin if (HIDE_DIRECTION = \'向上隐藏\') then //如果目前窗体正吸附在屏幕上
请发表评论