使用AutoHotKey开发简单的GUI程序

使用AutoHotKey开发简单的GUI程序

虽然平时开发GUI程序都是WPF,但是WPF也有它自己的缺点:启动速度太慢(我没查找相关的方法)、占用内存过高等。而用AutoHotKey开发的GUI程序则规避了这些缺点,虽然界面很丑,但还是够用了!下面简单记录一下我在开发AutoHotKey GUI过程中遇到的需求已经相关解决解决方案:

1. 自定义窗体Icon

1
Menu, Tray, Icon, G:\收藏\图库\AHK图标\appIcon.ico

注:必须要绝对地址

2. 将资源文件编译进exe文件

1
FileInstall, source, dest, 1

3. 添加超链接

1
Gui, Add, Link,x93 y245, <a href="tencent://message/?uin=1404363070">联系作者</a>

4. 创建多个窗体

1
2
3
4
5
6
7
8
9
10
Gui, MainWindow:Font, s9, Microsoft Yahei
Gui, MainWindow:Add, Button, x63 y36 w70 h28 , 屏蔽
Gui, MainWindow:Add, Button, x143 y36 w70 h28 , 恢复
Gui, MainWindow:Font, s10, Microsoft Yahei
Gui, MainWindow:Add, Text, x40 y8 w161 h19 cPurple, 屏蔽资源管理器用户文件夹
Gui, MainWindow:Add, Text, x10 y41 w41 h19 cBlue, 未屏蔽
Gui, MainWindow:Add, Link,x93 y245, <a href="tencent://message/?uin=1404363070">联系作者</a>
Gui, MainWindow:Show, w240 h268, 美化工具箱

Gui, AnotherWindow:Show, x150 y260 w20 h28, 美化工具箱 ; 创建第2个窗体

说明:在创建Gui窗口时增加标签即可

5. 给控件添加事件

1
2
3
4
Gui, MainWindow:Add, Button, x63 y36 w70 h28 gTest, 屏蔽	; g标签
Test:
Gui, AnotherWindow:Show, x150 y260 w20 h28, 美化工具箱
return

6. 打开子窗体时禁用主窗体

1
Gui, MainWindow:+Disabled

7. 给窗体加标签

1
Gui, MainWindow:+LabelMainWindow

8.以管理员权限执行

1
2
3
4
5
6
7
8
9
10
11
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}