INNO SETUP卸载程序中加入自定义窗体
原文:INNO SETUP卸载程序中加入自定义窗体

[Setup] AppName=My Program AppVerName=My Program v.1.2 DefaultDirName={pf}/My Program [Files] Source: Files/*; DestDir: {app} [Code] const bidDelAll = 1; bidSkipAll = 2; var Form: TSetupForm; CheckListBox: TNewCheckListBox; AllButton, UnAllButton: TButton; CancelButton, DelButton: TButton; StaticText: TNewStaticText; MsgForm: TSetupForm; MsgAllButton, MsgSkipAllButton: TButton; MsgCancelButton, MsgDelButton: TButton; DelAllReadOnly: Boolean; SkipAllReadOnly: Boolean; CheckDirs, CheckFiles: Boolean; function Size64(Hi, Lo: integer): Extended; var i: integer; begin Result:= Lo; if Lo < 0 then Result:= Result + 2147483647 + 2147483647 + 2; i:= Hi; while i > 0 do begin Result:= Result + 2147483647 + 2147483647 + 2; i:= i - 1; end; end; procedure FillListBox(const fromDir, fileMask: string; Level: Byte); var FSR, DSR: TFindRec; FindResult: Boolean; APath: string; i: integer; begin APath := AddBackslash(fromDir); FindResult := FindFirst(APath + fileMask, FSR); try while FindResult and CheckFiles do begin if FSR.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then begin {files} i:= CheckListBox.AddCheckBox(FSR.Name, FloatToStr(Size64(FSR.SizeHigh, FSR.SizeLow)) + ' byte', Level, True, True, False, True, TStringList.Create); TStrings(CheckListBox.ItemObject[i]).Text:= APath + FSR.Name; end; FindResult := FindNext(FSR); end; FindResult := FindFirst(APath + '*.*', DSR); while FindResult and CheckDirs do begin CheckFiles:= True; if ((DSR.Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) and not ((DSR.Name = '.') or (DSR.Name = '..')) then begin {dir} i:= CheckListBox.AddCheckBox(DSR.Name,'DIR', Level, True, True, False, True, TStringList.Create); TStrings(CheckListBox.ItemObject[i]).Text:= APath + DSR.Name; {Recursion} FillListBox(APath + DSR.Name, fileMask, Level+1); end; FindResult := FindNext(DSR); end; finally FindClose(FSR); FindClose(DSR); end; end; procedure ButtonOnClick(Sender: TObject); begin if TButton(Sender).Tag = 0 then CheckListBox.CheckItem(0, coCheckWithChildren) else CheckListBox.CheckItem(0, coUnCheck); end; procedure MsgButtonOnClick(Sender: TObject); begin Case TButton(Sender).Tag of bidDelAll : DelAllReadOnly:= True; bidSkipAll: SkipAllReadOnly:= True; end; MsgForm.Close; end; function DelMsgBox(FileName: string): Boolean; var MsgLabel: TLabel; begin MsgForm:= CreateCustomForm; MsgForm.ClientWidth := ScaleX(400); MsgForm.ClientHeight := ScaleY(120); MsgForm.Caption := 'Files to delete'; MsgForm.Center; MsgLabel := TLabel.Create(MsgForm); MsgLabel.Left := ScaleX(20); MsgLabel.Top := ScaleY(20); MsgLabel.Caption:= FileName + ' is protected file or directory!' + #10#10#13 + 'Do you want to delete the file with READONLY attribute?'; MsgLabel.Parent := MsgForm; MsgAllButton := TButton.Create(MsgForm); MsgAllButton.Parent := MsgForm; MsgAllButton.Width := ScaleX(75); MsgAllButton.Height := ScaleY(23); MsgAllButton.Left := ScaleX(20); MsgAllButton.Top := MsgForm.ClientHeight - ScaleY(23 + 10); MsgAllButton.Caption := 'Delete All'; MsgAllButton.Tag:= bidDelAll; MsgAllButton.OnClick := @MsgButtonOnClick; MsgSkipAllButton := TButton.Create(MsgForm); MsgSkipAllButton.Parent := MsgForm; MsgSkipAllButton.Width := ScaleX(75); MsgSkipAllButton.Height := ScaleY(23); MsgSkipAllButton.Left := MsgAllButton.Left + MsgAllButton.Width + ScaleX(10); MsgSkipAllButton.Top := MsgForm.ClientHeight - ScaleY(23 + 10); MsgSkipAllButton.Caption := 'Skip All'; MsgSkipAllButton.Tag:= bidSkipAll; MsgSkipAllButton.OnClick := @MsgButtonOnClick; MsgCancelButton := TButton.Create(MsgForm); MsgCancelButton.Parent := MsgForm; MsgCancelButton.Width := ScaleX(75); MsgCancelButton.Height := ScaleY(23); MsgCancelButton.Left := MsgForm.ClientWidth - MsgCancelButton.Width - ScaleX(20); MsgCancelButton.Top := MsgForm.ClientHeight - ScaleY(23 + 10); MsgCancelButton.Caption := 'Skip'; MsgCancelButton.ModalResult := mrCancel; MsgDelButton := TButton.Create(MsgForm); MsgDelButton.Parent := MsgForm; MsgDelButton.Width := ScaleX(75); MsgDelButton.Height := ScaleY(23); MsgDelButton.Left := MsgCancelButton.Left - MsgDelButton.Width - ScaleX(10); MsgDelButton.Top := MsgForm.ClientHeight - ScaleY(23 + 10); MsgDelButton.Caption := 'Delete'; MsgDelButton.ModalResult := mrOk; MsgForm.ActiveControl:= MsgCancelButton; if MsgForm.ShowModal() = mrOk then Result:= True else Result:= False; end; procedure DeleteFiles(); var SR: TFindRec; i: integer; str: string; ResultCode: Integer; begin DelAllReadOnly:= False; SkipAllReadOnly:= False; for i:= CheckListBox.Items.Count - 1 downto 0 do begin if CheckListBox.State[i] = cbChecked then begin str:= Trim(TStrings(CheckListBox.ItemObject[i]).Text); FindFirst(str, SR); if ((SR.Attributes and FILE_ATTRIBUTE_READONLY) = FILE_ATTRIBUTE_READONLY) then if Not (DelAllReadOnly or SkipAllReadOnly) then if DelMsgBox(SR.Name) then Exec('attrib', ' -h -s -r ' + '"' + str + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); if DelAllReadOnly then Exec('attrib', ' -h -s -r ' + '"' + str + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); FindClose(SR); DeleteFile(str); RemoveDir(str); end; end; end; procedure BrowseRemainedFiles(); begin Form:= CreateCustomForm; Form.ClientWidth := ScaleX(400); Form.ClientHeight := ScaleY(400); Form.Caption := 'Files to delete'; Form.Center; StaticText := TNewStaticText.Create(Form); StaticText.Left:= ScaleX(20); StaticText.Top := ScaleY(8); StaticText.Caption := 'Some elements could not be removed.' + #10#13 + 'These can be removed manually.' + #10#13#13 + 'Choose which are necessary to delete' + #10#13 + 'or press Cancel button.'; StaticText.Font.Color:= clBlue; StaticText.Font.Style:= [fsBold]; StaticText.AutoSize := True; StaticText.Parent := Form; CheckListBox := TNewCheckListBox.Create(Form); CheckListBox.Left:= ScaleX(20); CheckListBox.Top:= ScaleY(20); CheckListBox.Width:= Form.ClientWidth - ScaleX(20*2); CheckListBox.Height:= Form.ClientHeight - ScaleY(23*2 + 20); // CheckListBox.Offset:= 0; CheckListBox.Parent:= Form; AllButton := TButton.Create(Form); AllButton.Parent := Form; AllButton.Width := ScaleX(75); AllButton.Height := ScaleY(23); AllButton.Left := ScaleX(20); AllButton.Top := Form.ClientHeight - ScaleY(23 + 10); AllButton.Caption := 'Select All'; AllButton.Tag:= 0; AllButton.OnClick := @ButtonOnClick; UnAllButton := TButton.Create(Form); UnAllButton.Parent := Form; UnAllButton.Width := ScaleX(75); UnAllButton.Height := ScaleY(23); UnAllButton.Left := AllButton.Left + AllButton.Width + ScaleX(10); UnAllButton.Top := Form.ClientHeight - ScaleY(23 + 10); UnAllButton.Caption := 'Clear All'; UnAllButton.Tag:= 1; UnAllButton.OnClick := @ButtonOnClick; CancelButton := TButton.Create(Form); CancelButton.Parent := Form; CancelButton.Width := ScaleX(75); CancelButton.Height := ScaleY(23); CancelButton.Left := Form.ClientWidth - CancelButton.Width - ScaleX(20); CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10); CancelButton.Caption := 'Cancel'; CancelButton.ModalResult := mrCancel; CancelButton.Cancel := True; DelButton := TButton.Create(Form); DelButton.Parent := Form; DelButton.Width := ScaleX(75); DelButton.Height := ScaleY(23); DelButton.Left := CancelButton.Left - DelButton.Width - ScaleX(10); DelButton.Top := Form.ClientHeight - ScaleY(23 + 10); DelButton.Caption := 'Delete'; DelButton.ModalResult := mrOk; Form.ActiveControl:= CancelButton; CheckListBox.AddCheckBox(ExpandConstant('{app}'), '', 0, True, True, False, True, TStringList.Create); TStrings(CheckListBox.ItemObject[0]).Text:= ExpandConstant('{app}'); CheckDirs:= True; FillListBox(ExpandConstant('{app}'), '*', 1); CheckDirs:= False; FillListBox(ExpandConstant('{app}'), '*', 1); if Form.ShowModal() = mrOk then DeleteFiles(); end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if DirExists(ExpandConstant('{app}')) and (CurUninstallStep = usPostUninstall) then BrowseRemainedFiles(); end;

posted on 2014-11-23 11:58 NET未来之路 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/4116320.html

INNO SETUP卸载程序中加入自定义窗体相关推荐

  1. inno setup 卸载程序

    inno setup在卸载程序的时候删除改程序的所有文件 将一下代码复制到.iss最后面 [code] procedure CurUninstallStepChanged(CurUninstallSt ...

  2. 手把手教你实现小程序中的自定义组件

    之前做小程序开发的时候,对于开发来说比较头疼的莫过于自定义组件了,当时官方对这方面的文档也只是寥寥几句,一笔带过而已,所以写起来真的是非常非常痛苦!! 好在微信小程序的库从 1.6.3 开始,官方对于 ...

  3. inno setup 卸载注册表_inno setup 自定义生成的卸载程序

    缘由:使用inno setup 生成的现有自动生成的卸载程序不能清理守护进程.更新进程.注册表等相关信息,造成信息残留,一定程度上影响安全性. inno setup 生成的现有自动生成的卸载程序: W ...

  4. 使用inno setup打包程序完整脚本(.net框架检测,重复安装检测)

    ; 脚本由 Inno Setup 脚本向导 生成!; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "小小鸟软件"#def ...

  5. inno setup 卸载注册表_inno setup 修改卸载文件名称

    ; Inno Setup 脚本 ; 该示例脚本显示如何自定义卸载文件的名称(默认为 unins000.exe,unins001.exe 等等). [Setup] AppName=自定义卸载文件名示例程 ...

  6. inno setup 卸载注册表_Inno Setup 注册表启动项 修改注册表

    //注册表启动项 [Registry] Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; V ...

  7. 在winform程序中启动wpf窗体

    有时候需要在winform程序中利用wpf的许多优良特性,如何在其中启动wpf窗体呢? 前提:MainWindow.xaml是从别的地方copy到这个项目的,值得注意的是,除了MainWindow.x ...

  8. MQL5:在EA和脚本程序中引用自定义指标

    MQL5:在EA和脚本程序中引用指标 第一步 声明 第二步 使用 iCustom 函数 第三步 使用CopyBuffer复制引用指标中的指定数组 最近刚对MQL5语言有一点了解. 在写指标.EA的时候 ...

  9. inno setup打包程序安装出现CreateProcess failed;code 740

    问题: 使用inno setup打包我们发布的程序test.exe,在安装结束后,勾选了Launch xxx运行程序,然后出现如下报错: Unable to execute file:xxx Crea ...

  10. 《九》微信小程序中的自定义组件

    开发者可以将页面内的功能模块抽象成自定义组件,以便在不同的页面中重复使用:也可以将复杂的页面拆分成多个低耦合的模块,有助于代码维护. 自定义组件:可复用的 WXML.WXSS.JS.JSON. beh ...

最新文章

  1. CSS Sprite的应用
  2. CUDA程序编写具体参数设置
  3. solver.prototxt文件里面参数含义及其设置
  4. 转:AMS之dumpsys篇
  5. python操作access数据库未发现数据源名称_ASP连接ACCESS数据库失败,提示“未发现数据源名称并且未指定默认驱动程序”...
  6. Serializing Lua objects into Lua Code
  7. 使用HTML5开发手机离线应用
  8. 物联网专科专业必修课程_江西自考专科物联网技术专业的考试课程/科目
  9. LIB BFD, the Binary File Descriptor Library
  10. 处理动态SQL语句的参数
  11. AWK 高端大气上档次
  12. 云计算设计模式(二十四)——仆人键模式
  13. C#winform可视化(当主窗体不能拖动时)
  14. 云运维管家服务器,云平台随身管理-我的“运维管家”
  15. 软件定义无线电的实时频谱分析仪相关原理介绍(二)——射频,中频和基带信号
  16. Android之不须要自己定义View(ViewfindView.java)最简单的二维码扫描
  17. 对比汇新云和猪八戒?
  18. jq 数字转中文数字_Jquery 字符串转数字
  19. Linux监控服务之zabbix
  20. 并发和并行以及线程安全

热门文章

  1. VS2010+OpenCV2.4.9配置
  2. Mad Libs 游戏
  3. MFC操作读取excel文件
  4. 顺序右移数组元素(内测第0届第5题)
  5. Android vs iOS vs BlackBerry: Which is the most secure holiday gift?
  6. Windows服务开发相关文章收集
  7. 轻轻松松的记住Linux系统目录结构
  8. Azure Services Bus(服务总线)中的工作流(workflow)
  9. GNOME 3.20 两大新特性说明
  10. drivers/mfd/Mfd-core.c