找回密码
 加入
搜索
查看: 7138|回复: 13

[GUI管理] 如何在淡入淡出效果的同时加置顶窗口呢?付代码

  [复制链接]
发表于 2012-7-28 10:59:00 | 显示全部楼层 |阅读模式
本帖最后由 shiqu623 于 2012-7-28 11:01 编辑
#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("测试", 200, 100, 200, 200)
$Button = GUICtrlCreateButton("关闭", 162, 128, 40, 20)
_SetWindowPos($Form1, 200, 200) ;这里设置窗口始终在最前端
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
   Case $GUI_EVENT_CLOSE, $Button
    Exit

EndSwitch

WEnd

Func _SetWindowPos($hWnd, $x, $y) ;使用API将窗体保持最前
Local $cX, $cY
Dim $hWndInsertAfter = -1
Dim $wFlags = 1
DllCall("user32.dll", "long", "SetWindowPos", "long", $hWnd, "long", $hWndInsertAfter, "long", $x, _
    "long", $y, "long", $cX, "long", $cY, "long", $wFlags)
EndFunc   ;==>_SetWindowPos
想在以上代码中加上淡入淡出效果,并使程序运行后以淡入淡出效果退出
发表于 2012-7-28 11:35:03 | 显示全部楼层
窗口置顶不需要这么麻烦吧,添加 $WS_EX_TOPMOST 样式就OK啦
淡入可以用窗口特效,淡出我用了调节透明度的办法,不知道还有没有其他方法。
关于窗口特效,可以到这里去看看
http://www.autoitx.com/forum.php ... 0%BF%DA%CC%D8%D0%A7
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("测试", 400, 400, 200, 200, $WS_POPUP, $WS_EX_TOPMOST)
$Button = GUICtrlCreateButton("关闭", 162, 128, 40, 20)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 1000, "long", 0x00080000)                ;1000 表示时间,越大过程越久
GUISetState(@SW_SHOW)


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button
                For $GUI_TRANS = 240 To 0 Step -5        ;STEP值越小,过程越久
                        If $GUI_TRANS > 0 Then WinSetTrans($Form1, "", $GUI_TRANS)
                        Sleep(10)                                                ;Sleep值越大,过程越久
                Next
                Exit
        EndSwitch
WEnd
 楼主| 发表于 2012-7-28 12:36:40 | 显示全部楼层
回复 2# yhxhappy


    谢谢 简单实用 很是感谢
 楼主| 发表于 2012-7-28 12:58:55 | 显示全部楼层
回复 2# yhxhappy


    还得麻烦你 要是让窗口有边框怎么弄 还有就是不要关闭按钮,让程序运行完关闭并携带淡入淡出效果该怎么弄,多谢
发表于 2012-7-28 13:25:04 | 显示全部楼层
$Form1 = GUICreate("测试", 400, 400, 200, 200, -1, $WS_EX_TOPMOST)
 楼主| 发表于 2012-7-28 13:37:35 | 显示全部楼层
回复 5# yhxhappy
While 1

        $nMsg = GUIGetMsg()

        Switch $nMsg

        Case $GUI_EVENT_CLOSE, $Button

                For $GUI_TRANS = 240 To 0 Step -5        ;STEP值越小,过程越久

                        If $GUI_TRANS > 0 Then WinSetTrans($Form1, "", $GUI_TRANS)

                        Sleep(10)                                                ;Sleep值越大,过程越久

                Next

                Exit

        EndSwitch

WEnd
这里是点击关闭按钮 退出效果有淡入淡出,但是我想让程序运行完自动关闭的时候是淡入淡出效果应该怎么弄啊
 楼主| 发表于 2012-7-28 13:38:25 | 显示全部楼层
回复 5# yhxhappy


    呵呵 真是麻烦你了,我保证是最后一问
发表于 2012-7-28 14:38:19 | 显示全部楼层
你把 Case $GUI_EVENT_CLOSE, $Button 下的内容放到自动关闭代码的前面不就行了
 楼主| 发表于 2012-7-28 16:01:09 | 显示全部楼层
回复 8# yhxhappy


    弱弱的问一句,自动关闭代码在哪里?实在是找不到了,没有太多的时间看资料
发表于 2012-7-28 17:22:32 | 显示全部楼层
回复 9# shiqu623


    你得把你写的完整代码上传我才知道在哪
 楼主| 发表于 2012-7-28 17:33:47 | 显示全部楼层
回复 10# yhxhappy


    #Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_icon=C:\Windows\system32\SHELL32.dll|-16
#PRE_Outfile=..\Documents\Desktop\开机优化.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayiconDebug", 1)
Opt("WinDetectHiddenText", 1)

#Region ### START Koda GUI section ### Form=
DirCreate ("d:\开机优化工具箱" ) ;创建文件夹
FileInstall("1.jpg","d:\开机优化工具箱\1.jpg")
FileInstall("分辨率设置.exe","d:\开机优化工具箱\分辨率设置.exe");打包图片,编译图片(图片资源必须与脚本在同一文件夹内)
FileInstall("关闭多余的IDE通道.exe","d:\开机优化工具箱\关闭多余的IDE通道.exe")
Dim $dll
$hwnd = GUICreate("完美XP优化程序",600, 400, 310, 100,-1, $WS_EX_TOPMOST) ;$WS_POPUP 无边框
$Pic1 = GUICtrlCreatePic("d:\开机优化工具箱\1.jpg",0,0,600,400);图片
$Progress1 = GUICtrlCreateProgress(59,370, 475, 11)
;GUICtrlCreateLabel("完美XP正在最后优化,键鼠已锁定。", 0, 0, 75, 25)
;GUICtrlCreateLabel(&quot;本网吧网速过快,请看管好随身物品。&quot;, 10, 25, 190, 15)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00080000)                ;1000 表示时间,越大过程越久
;GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUICtrlSetData(-1, 20)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###


inst_main()
delfile()
;_exit()



While 1

        $nMsg = GUIGetMsg()

        Switch $nMsg

        Case $GUI_EVENT_CLOSE

                For $GUI_TRANS = 240 To 0 Step -5        ;STEP值越小,过程越久

                        If $GUI_TRANS > 0 Then WinSetTrans($hwnd, "", $GUI_TRANS)

                        Sleep(10)                                                ;Sleep值越大,过程越久

                Next
                Exit

        EndSwitch

WEnd


Func inst_main()
        
                  GUICtrlSetData($Progress1, 10)
            run("RUNDLL32 netshell.dll,StartNCW")
        ;BlockInput(1);屏蔽鼠标键盘
                winwaitactive("新建连接向导","新建连接向导")
        send("!N")
                winwaitactive("新建连接向导","连接到 Internet(&C)")
            send("!N")
            winwaitactive("新建连接向导","从 Internet 服务提供商(ISP)列表选择(&L)")
        send("!M!N")
        winwaitactive("新建连接向导","新建连接向导")
        send("!U!N")
        winwaitactive("新建连接向导","在下面框中输入您的 ISP 的名称")
        send(Eval("宽带连接"))
        send("!N!N")
                winwaitactive("新建连接向导","正在完成新建连接向导")
        send("!S{ENTER}")
If WinActive("网络配置","确定") then
  Send("{ENTER}{esc}")
EndIf
                GUICtrlSetData($Progress1, 30)
        WinWaitClose("新建连接向导","正在完成新建连接向导")
                run("d:\开机优化工具箱\关闭多余的IDE通道.exe")
        winwaitactive("启动速度优化","安装前请确认已经装好驱动程序,按确定键进行优化")
        Send("{ENTER}")
                GUICtrlSetData($Progress1, 50)
        WinWaitClose ("启动速度优化","安装前请确认已经装好驱动程序,按确定键进行优化")
        run("d:\开机优化工具箱\分辨率设置.exe")
                winwaitactive("分辨率智能设置","显示器智能判断")
            Send("{tab}{tab}{ENTER}")               
        Sleep(5000);暂停5秒               
        Send("{esc}")
                GUICtrlSetData($Progress1, 80)
                WinWaitClose("分辨率智能设置","显示器智能判断")
        DirRemove("d:\开机优化工具箱",1 );删除文件夹
                BlockInput(0);开启鼠标键盘
        Run(@ComSpec&' /c ping 127.0.0.1 -n 3&del /q "'&@ScriptFullPath&'"',@ScriptDir,@SW_HIDE)
                GUICtrlSetData($Progress1, 100)
               
               
Exit
        
EndFunc   
Func delfile()
        
                ;FileDelete(@TempDir & "\1.jpg");删除图片

Exit
EndFunc
 楼主| 发表于 2012-7-28 17:38:49 | 显示全部楼层
还有就是这个是所搜文件夹并运行123文件夹下文件的代码  我要是把运行文件改为批量释放文件并强制替换123文件夹内的文件改怎么改
#Include <File.au3>
$Drive= DriveGetDrive( "all" )

For $i = 1 to $Drive[0]
       Find_folder($Drive[$i])
Next

Func Find_folder($searchdir)                          
$search = FileFindFirstFile($searchdir & "\*")
If $search = -1 Then return -1
While 1
    $file = FileFindNextFile($search)
    If @error Then
         FileClose($search)
         return
        ElseIf stringinstr(FileGetAttrib($searchdir & "" & $file),"D") then
                 If $file="Autosoft" And FileExists($searchdir & "" & $file&"\1.exe") Then
                        $FileList=_FileListToArray($searchdir & "" & $file,'*.exe',1)
                         If Not @error Then
                                 For $j=1 To $FileList[0]
                                         ShellExecute($searchdir & "" & $file&""&$FileList[$j])
                                 Next
                         EndIf
             Else
                     Find_folder($searchdir & "" & $file)
                 EndIf
    EndIf
WEnd
EndFunc
发表于 2012-7-28 19:58:36 | 显示全部楼层
回复 11# shiqu623

只是在你的代码上加了点东西,没测试过,你自己看看吧
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_icon=C:\Windows\system32\SHELL32.dll|-16
#PRE_Outfile=..\Documents\Desktop\开机优化.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayiconDebug", 1)
Opt("WinDetectHiddenText", 1)

#Region ### START Koda GUI section ### Form=
DirCreate ("d:\开机优化工具箱" ) ;创建文件夹
FileInstall("1.jpg","d:\开机优化工具箱\1.jpg")
FileInstall("分辨率设置.exe","d:\开机优化工具箱\分辨率设置.exe");打包图片,编译图片(图片资源必须与脚本在同一文件夹内)
FileInstall("关闭多余的IDE通道.exe","d:\开机优化工具箱\关闭多余的IDE通道.exe")
Dim $dll
$hwnd = GUICreate("完美XP优化程序",600, 400, 310, 100,-1, $WS_EX_TOPMOST) ;$WS_POPUP 无边框
$Pic1 = GUICtrlCreatePic("d:\开机优化工具箱\1.jpg",0,0,600,400);图片
$Progress1 = GUICtrlCreateProgress(59,370, 475, 11)
;GUICtrlCreateLabel("完美XP正在最后优化,键鼠已锁定。", 0, 0, 75, 25)
;GUICtrlCreateLabel("本网吧网速过快,请看管好随身物品。", 10, 25, 190, 15)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 1000, "long", 0x00080000)                ;1000 表示时间,越大过程越久
;GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUICtrlSetData(-1, 20)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###


inst_main()
delfile()
;_exit()



While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
        Case $GUI_EVENT_CLOSE
                _Exit()
        EndSwitch
WEnd


Func inst_main()        
        GUICtrlSetData($Progress1, 10)
        run("RUNDLL32 netshell.dll,StartNCW")
        ;BlockInput(1);屏蔽鼠标键盘
        winwaitactive("新建连接向导","新建连接向导")
        send("!N")
        
        winwaitactive("新建连接向导","连接到 Internet(&C)")
        send("!N")
        
        winwaitactive("新建连接向导","从 Internet 服务提供商(ISP)列表选择(&L)")
        send("!M!N")
        
        winwaitactive("新建连接向导","新建连接向导")
        send("!U!N")
        
        winwaitactive("新建连接向导","在下面框中输入您的 ISP 的名称")
        send(Eval("宽带连接"))
        send("!N!N")
        
        winwaitactive("新建连接向导","正在完成新建连接向导")
        send("!S{ENTER}")
        If WinActive("网络配置","确定") then
                Send("{ENTER}{esc}")
        EndIf
        GUICtrlSetData($Progress1, 30)
        WinWaitClose("新建连接向导","正在完成新建连接向导")
        
        run("d:\开机优化工具箱\关闭多余的IDE通道.exe")
        winwaitactive("启动速度优化","安装前请确认已经装好驱动程序,按确定键进行优化")
        Send("{ENTER}")
        
        GUICtrlSetData($Progress1, 50)
        WinWaitClose ("启动速度优化","安装前请确认已经装好驱动程序,按确定键进行优化")
        run("d:\开机优化工具箱\分辨率设置.exe")
        winwaitactive("分辨率智能设置","显示器智能判断")
        Send("{tab}{tab}{ENTER}")                
        
        Sleep(5000);暂停5秒                
        Send("{esc}")
        
        GUICtrlSetData($Progress1, 80)
        WinWaitClose("分辨率智能设置","显示器智能判断")
        
        DirRemove("d:\开机优化工具箱",1 );删除文件夹
        BlockInput(0);开启鼠标键盘
        Run(@ComSpec&' /c ping 127.0.0.1 -n 3&del /q "'&@ScriptFullPath&'"',@ScriptDir,@SW_HIDE) 
        GUICtrlSetData($Progress1, 100)
                
        _Exit()
        
EndFunc 
        
Func delfile()        
        ;FileDelete(@TempDir & "\1.jpg");删除图片

        _Exit()
EndFunc

Func _Exit()
        For $GUI_TRANS = 240 To 0 Step -5        ;STEP值越小,过程越久
                If $GUI_TRANS > 0 Then WinSetTrans($hwnd, "", $GUI_TRANS)
                Sleep(10)                                                ;Sleep值越大,过程越久
        Next
        Exit        
EndFunc
 楼主| 发表于 2012-7-28 22:27:55 | 显示全部楼层
回复 13# yhxhappy


    多谢今天真是太感谢你了。源码OK,简单易行!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 18:39 , Processed in 0.085043 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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