找回密码
 加入
搜索
查看: 4315|回复: 7

[系统综合] [已解决]:求助,au3如何编写只允许运行一个窗口

  [复制链接]
发表于 2014-1-7 21:21:26 | 显示全部楼层 |阅读模式
本帖最后由 QQ386263723 于 2014-1-8 13:13 编辑

$hGui = GUICreate("自由人制作Windows 系统优化工具 ", 528, 363, 289, 207)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\ziyouren.jpg", 0, 0, 545, 65)
$Group1 = GUICtrlCreateGroup("     优化网络工具", 8, 72, 145, 297)
$Button1 = GUICtrlCreateButton("Button1", 40, 120, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("     优化内存工具", 193, 71, 145, 297)
$Button2 = GUICtrlCreateButton("Button1", 226, 114, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("     运行磁盘工具", 378, 72, 145, 297)
$Button3 = GUICtrlCreateButton("Button1", 411, 116, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x40010)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit

        EndSwitch
WEnd
发表于 2014-1-7 21:48:45 | 显示全部楼层
怎么理解“只允许运行一个窗口”
发表于 2014-1-7 21:52:31 | 显示全部楼层
不太明白,说的是不让程序重复运行吗?
 楼主| 发表于 2014-1-7 22:21:26 | 显示全部楼层
是的,就是不让程序重复运行。
发表于 2014-1-7 22:33:34 | 显示全部楼层
论坛有不少方法,早几天就有此提问帖
http://www.autoitx.com/forum.php?mod=viewthread&tid=43196
 楼主| 发表于 2014-1-8 07:49:20 | 显示全部楼层
老师:这样编译完还是能运行,多个脚本,错在哪里。
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_outfile=C:\Users\Administrator\Desktop\00.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <Misc.au3>

$hGui = GUICreate("自由人制作Windows 系统优化工具 ", 528, 363, -1, -1)
If _Singleton($hGui, 1) = 0 Then

        MsgBox(4096, "出错了", "本程序已经运行了一个实例!")

        Exit

EndIf
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\ziyouren.jpg", 0, 0, 545, 65)
$Group1 = GUICtrlCreateGroup("     优化网络工具", 8, 72, 145, 297)
$Button1 = GUICtrlCreateButton("网络加速器", 40, 120, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("     优化内存工具", 193, 71, 145, 297)
$Button2 = GUICtrlCreateButton("内存管理", 226, 114, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("     运行磁盘工具", 378, 72, 145, 297)
$Button3 = GUICtrlCreateButton("diskgenius", 411, 116, 81, 33)
GUICtrlCreateLabel("                     特别鸣谢:afan  poiu  xiehuahere …… 等好友", 10, 350, 520, 360)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x40010)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1
                        Run(@ScriptDir & "\UltraISO.exe")
                Case $Button1
                        Run(@ScriptDir & "\UltraISO.exe")
                Case $Button1
                        Run(@ScriptDir & "\UltraISO.exe")

        EndSwitch
WEnd
发表于 2014-1-8 10:12:13 | 显示全部楼层
回复 6# QQ386263723


    $hGui 是句柄,每次运行都会不同。因此不能作为 _Singleton() 识别的方式。
你可以用标题名来作为识别,同一标题名的程序再次运行即会被 _Singleton() 识别而处理。
#include <Misc.au3>
Global $sTitle = '自由人制作Windows 系统优化工具'
If _Singleton($sTitle, 1) = 0 Then
        MsgBox(4096, "出错了", "本程序已经运行了一个实例!")
        WinActivate($sTitle)
        Exit
EndIf
$hGui = GUICreate($sTitle, 528, 363, -1, -1)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\ziyouren.jpg", 0, 0, 545, 65)
$Group1 = GUICtrlCreateGroup("     优化网络工具", 8, 72, 145, 297)
$Button1 = GUICtrlCreateButton("网络加速器", 40, 120, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("     优化内存工具", 193, 71, 145, 297)
$Button2 = GUICtrlCreateButton("内存管理", 226, 114, 81, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("     运行磁盘工具", 378, 72, 145, 297)
$Button3 = GUICtrlCreateButton("diskgenius", 411, 116, 81, 33)
GUICtrlCreateLabel("                     特别鸣谢:afan  poiu  xiehuahere …… 等好友", 10, 350, 520, 360)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x40010)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1
                        Run(@ScriptDir & "\UltraISO.exe")
                Case $Button1
                        Run(@ScriptDir & "\UltraISO.exe")
                Case $Button1
                        Run(@ScriptDir & "\UltraISO.exe")

        EndSwitch
WEnd
 楼主| 发表于 2014-1-8 13:12:28 | 显示全部楼层
太谢谢了,每次我遇到困难都您耐心的帮我回答。忠心感谢!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 15:24 , Processed in 0.087804 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表