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

[GUI管理] GUI占用CPU100%的问题?

  [复制链接]
发表于 2010-7-15 16:56:44 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 171, 215, 212)
$Button1 = GUICtrlCreateButton("开始", 192, 120, 49, 33)
$Button2 = GUICtrlCreateButton("退出", 255, 119, 49, 33)
$Label1 = GUICtrlCreateLabel("请选择核心目录:", 22, 34, 100, 25)
$Input1 = GUICtrlCreateInput("", 24, 64, 225, 21)
$Button3 = GUICtrlCreateButton("浏览", 264, 64, 33, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $var, $ok

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        _shanchu()
                Case $Button2
                Exit                        
                Case $Button3
GUICtrlSetState($Button3, $GUI_DISABLE)
        $var = FileSelectFolder("请选择目录:", "")
GUICtrlSetData($Input1, $var, GUICtrlRead($Input1))
                $ok = 1
If FileExists($var)=0 Then
Else
GUICtrlSetData($Input1,$var)
EndIf
GUICtrlSetState($Button3, $GUI_ENABLE)
        GUICtrlSetBkColor($Input1, 0xFFFAF0)
                
        EndSwitch
WEnd

Func _shanchu()
GUICtrlSetState($Button1, $GUI_DISABLE)
$var &= "\log"        
$lujing = $var
MsgBox(0,"",$lujing)
While 1
FileDelete($lujing)
Sleep(5000)
WEnd
EndFunc
谁能帮我看看是怎么回事,只要我一点开始CPU使用就狂飙到100%,而且还不能退出,研究很久了实在是找不到原因了。
 楼主| 发表于 2010-7-15 17:18:12 | 显示全部楼层
没有人知道是哪里出现问题了吗?
发表于 2010-7-15 17:32:05 | 显示全部楼层
一点开始CPU使用就狂飙到100%---我这里测试正常
而且还不能退出---Func _shanchu()那一段代码用一个while已经进入死循环了,当然无法响应GUI退出消息了
 楼主| 发表于 2010-7-15 18:23:39 | 显示全部楼层
那就没办法退出了吗?
发表于 2010-7-15 18:52:17 | 显示全部楼层
楼主应该再多看看帮助,其实代码并不难。
多嘴勿怪。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 171, 215, 212)
$Button1 = GUICtrlCreateButton("开始", 192, 120, 49, 33)
$Button2 = GUICtrlCreateButton("退出", 255, 119, 49, 33)
$Label1 = GUICtrlCreateLabel("请选择核心目录:", 22, 34, 100, 25)
$Input1 = GUICtrlCreateInput("", 24, 64, 225, 21)
$Button3 = GUICtrlCreateButton("浏览", 264, 64, 33, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $var, $ok

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        _shanchu()
                Case $Button2
                        Exit
                Case $Button3
                        GUICtrlSetState($Button3, $GUI_DISABLE)
                        $var = FileSelectFolder("请选择目录:", "")
                        If @error Then
                                $var = GUICtrlRead($Input1)
                        Else
                                GUICtrlSetData($Input1, $var)
                        EndIf
                        GUICtrlSetState($Button3, $GUI_ENABLE)
                        GUICtrlSetBkColor($Input1, 0xFFFAF0)

        EndSwitch
WEnd

Func _shanchu()
        GUICtrlSetState($Button1, $GUI_DISABLE)
        $lujing = $var & "\log"
        If FileExists($lujing) Then
                $search = FileFindFirstFile($lujing&"*.*")
                If $search = -1 Then
                        MsgBox(0, "错误", "没有文件/目录 匹配搜索")
                        Exit
                EndIf

                While 1
                        $file = FileFindNextFile($search)
                        If @error Then ExitLoop
                        MsgBox(4096, "文件:", $lujing&$file);如果删除文件这行改为Filedelete($lujing&$file)
                WEnd
                FileClose($search)
        Else
                MsgBox(0,"警告","未找到LOG文件夹")
        EndIf
EndFunc   ;==>_shanchu

评分

参与人数 1贡献 +2 收起 理由
afan + 2

查看全部评分

 楼主| 发表于 2010-7-15 19:40:35 | 显示全部楼层
谢谢你,但是我还有个问题没解决,就是我想循环执行删除脚本,我一加上时间程序就退不出来了,能给我一个思路吗?
发表于 2010-7-15 21:16:46 | 显示全部楼层
回复 6# 93779252
见第55行注释
发表于 2010-7-15 21:42:36 | 显示全部楼层
回复 6# 93779252

while 1
sleep(500)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-16 06:23 , Processed in 0.095877 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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