|
发表于 2013-7-20 21:41:30
|
显示全部楼层
回复 1# jwwlchen
你的代码有两个循环(完全没有必要的), 但没有退出内层循环的操作,程序当然会假死了.
而且不应该在点击菜单后才建立控件,否则岂不是多次点击会反复建立相同的控件?
在你代码基础上作了相应修改, 自己比对吧.#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
Local $iMemo
Local Enum $idNew = 1000, $Extract
Local $hGUI, $hEdit, $hMain
$hGUI = GUICreate("Log 分析工具 --version: 1.0", 400, 300)
$Combo1 = GUICtrlCreateCombo("", 72, 20, 177, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("浏览...", 280, 10, 65, 33)
$label0 = GUICtrlCreateLabel("请点击浏览选择LOG文件存放目录", 72, 60, 220, 100)
$Line = GUICtrlCreateInput("", 72, 90, 100, 20)
$Button_1 = GUICtrlCreateButton("Go", 300, 150, 50, 40)
$label1 = GUICtrlCreateLabel("请输入要处理的行数", 72, 120, 220, 100)
$label2 = GUICtrlCreateLabel(" 2 正数第二行", 72, 140, 220, 100)
$label3 = GUICtrlCreateLabel("-2 倒数第二行", 72, 160, 220, 100)
$hMain = _GUICtrlMenu_CreateMenu()
$hEdit = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hEdit, 0, "提取制定行信息", $Extract)
_GUICtrlMenu_InsertMenuItem($hMain, 1, "设置", 0, $hEdit)
_GUICtrlMenu_SetMenu($hGUI, $hMain)
_set_controls_state(0)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit (255)
Case $msg = $Button1
$userpath = FileSelectFolder("选择一个位置", "")
If $userpath <> "" Then
GUICtrlSetData($Combo1, "")
GUICtrlSetData($Combo1, $userpath, $userpath)
EndIf
GUICtrlSetState($Line, $GUI_FOCUS)
Case $msg = $Button_1
Go($Combo1, $Line)
EndSelect
WEnd
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $ilParam
Switch _WinAPI_LoWord($iwParam)
Case $Extract
_set_controls_state(1)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func GO($Combo1, $Line)
$LogFile = GUICtrlRead($Combo1)
$LogLine = GUICtrlRead($Line)
If 0 == FileExists($LogFile & "\*.log") And 0 == FileExists($LogFile & "\*.txt") Then
MsgBox(16, "错误", $LogFile & " 没有发现 LOG 或 TXT 文件,请重新选择")
ElseIf $LogLine < 1 And $LogLine >= 0 Then
MsgBox(16, "错误", "行数为空,请重新输入要处理的行数")
GUICtrlSetState($Line, $GUI_FOCUS)
Else
Write_Info($LogFile, $LogLine)
EndIf
EndFunc ;==>GO
Func Write_Info($LogFile, $LogLine)
If FileExists(@ScriptDir & "" & "out.log") Then FileDelete(@ScriptDir & "" & "out.log")
$search = FileFindFirstFile($LogFile & "\*.*")
If $search = -1 Then
MsgBox(0, "错误", "没有文件/目录 匹配搜索")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$CountLines = _FileCountLines($LogFile & "" & $file)
If $LogLine < 0 Then
$Data = FileReadLine($LogFile & "" & $file, $CountLines + $LogLine + 1)
EndIf
If $LogLine > 0 Then
$Data = FileReadLine($LogFile & "" & $file, $LogLine)
EndIf
$outlog = FileOpen("out.log", 9)
FileWrite($outlog, $Data & @CRLF)
FileClose($outlog)
WEnd
FileClose($search)
MsgBox(64, "", "所有数据已导入到 " & @CRLF _
& @ScriptDir & "" & "OUT.LOG")
ShellExecute("out.log")
EndFunc ;==>Write_Info
Func _set_controls_state($iFlag = 1)
Local $state
If $iFlag Then
$state = $gui_show
Else
$state = $gui_hide
EndIf
For $i = $Combo1 To $label3
GUICtrlSetState($i, $state)
Next
EndFunc ;==>_set_controls_state
|
|