请教高手关于 while 内嵌套for to step问题
本帖最后由 ditser 于 2010-10-13 09:51 编辑#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
Opt('MustDeclareVars', 1)
open();声明方法
; 示例 1
Func open()
Local $msg,$Form1,$menu_A,$menu_A_A,$menu_A_B,$menu_A_C,$menu_A_D,$menu_B,$menu_B_A,$menu_B_B,$menu_B_C,$menu_B_D,$menu_c,$menu_c_a,$Button_a
Local $treeview,$filels,$at,$startlabel
Local $infobutton
Local $msg, $item, $hItem, $text
Local $views
;从配置文件中读出值
$views = IniRead("softset.ini","views","views","");读取文件数
Local $filedir[$views],$filedes[$views],$sunfilels[$views],$description[$views]
For $i = 0 to $views-1 Step 1
$filedir[$i]=IniRead("softset.ini",$i,"filedir","")
$filedes[$i]=IniRead("softset.ini",$i,"filedes","")
Next
#cs
$msg = GUIGetMsg()
MsgBox(6,"11",$filedir,10)
MsgBox(6,"11",$filedes,10)
#ce
$Form1 = GUICreate("GUI例子", 720, 550, -1, -1, $WS_OVERLAPPEDWINDOW);创建一个 GUI 窗口
GUISetIcon("favicon.ico", 0);设置窗口图标
GUISetState(@SW_SHOW) ; 显示窗口
;创建菜单控件
;一级菜单控件
$menu_A = GUICtrlCreateMenu("文件")
$menu_B = GUICtrlCreateMenu("编辑")
$menu_c = GUICtrlCreateMenu("关于")
;二级菜单控件
$menu_A_A = GUICtrlCreateMenuItem("打开", $menu_A)
$menu_A_B = GUICtrlCreateMenuItem("关闭", $menu_A)
$menu_A_B = GUICtrlCreateMenuItem("保存", $menu_A)
$menu_A_D = GUICtrlCreateMenuItem("另存为", $menu_A)
$menu_B_A = GUICtrlCreateMenuItem("全选",$menu_B)
$menu_B_B = GUICtrlCreateMenuItem("剪切",$menu_B)
$menu_B_C = GUICtrlCreateMenuItem("复制",$menu_B)
$menu_B_D = GUICtrlCreateMenuItem("粘贴",$menu_B)
$menu_C_A = GUICtrlCreateMenuItem("版本",$menu_c)
;创建树形目录的容器,指定其样式
$treeview = GUICtrlCreateTreeView(6, 6, 200, 520, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
;在树形目录框中创建菜单
$filels = GUICtrlCreateTreeViewItem("文件列表", $treeview)
$at = GUICtrlCreateTreeViewItem("其他说明", $treeview)
;文件列表 子菜单
For $i = 0 to $views-1 Step 1
$sunfilels[$i] = GUICtrlCreateTreeViewItem($filedir[$i], $filels)
Next
$startlabel = GUICtrlCreateLabel("TreeView Demo", 220, 12, 490, 490, $SS_SUNKEN)
For $i = 0 to $views-1 Step 1
$description[$i] = GUICtrlCreateLabel($filedes[$i], 220, 12, 490, 490, $SS_SUNKEN)
;GUICtrlSetState(-1, $GUI_HIDE); 在初始化期间隐藏"关于..."文本
Next
$infobutton = GUICtrlCreateButton("修改", 490, 505, 70, 20)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $menu_c_a
MsgBox(266304, "版本", "版本:初始版(1.0)")
Case $msg = $infobutton
$item = GUICtrlRead($treeview) ; 获取当前挑选的 treeview 项目的控件ID
If $item = 0 Then
MsgBox(64, "TreeView 演示", "现在没有选择项目")
Else
$text = GUICtrlRead($item, 1) ; 获取 treeview 项目的文本
If $text == "" Then
MsgBox(16, "Error", "当取回关于项目信息时发生错误")
Else
;MsgBox(64, "",$text); $advmsg 包含文本 and $advmsg 包含 treeview 项目的状态数值
Run("E:\tools\开发工具\EditPlus 3\EditPlus.exe " & $text)
EndIf
EndIf
EndSelect
For $i = 0 to $views-1 Step 1
GUICtrlSetState($description[$i], $GUI_HIDE)
If $msg = $sunfilels[$i] Then
GUICtrlSetState($description[$i], $GUI_show)
Else
GUICtrlSetState($description[$i], $GUI_HIDE)
EndIf
Next
WEnd
GUIDelete()
EndFunc ;==>open
以上是所有代码,想实现效果创建一个GUI 然后从ini文件中读取个树形目录名称,其中每个栏目中对应一个label ,单击每个项目时显示对应label
遇到的问题: label不停的循环显示。
请高人解答,小弟不胜感激! 怎么没人回答啊 是我描述的不清楚吗? 不要在主循环里循环,用$WM_NOTIFY 更好,参考 http://www.autoitx.com/thread-18979-1-1.html 本帖最后由 ditser 于 2010-10-13 12:21 编辑
谢谢楼上{:face (396):} 不过不在主循环里循环 程序会失效{:face (197):} $WM_NOTIFY这个怎么用啊?我在帮助里没找。。。。。。刚学AUTOIT 不是很了解 自己改好了,贴出来留个纪念,我得第一个AUTOIT (8)
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=favicon.ico
#AutoIt3Wrapper_outfile=autoconf_V1.0.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
Opt('MustDeclareVars', 1)
open();声明方法
; 示例 1
Func open()
Local $msg,$Form1,$menu_A,$menu_A_A,$menu_A_B,$menu_A_C,$menu_A_D,$menu_B,$menu_B_A,$menu_B_B,$menu_B_C,$menu_B_D,$menu_c,$menu_c_a,$Button_a
Local $treeview,$filels,$at,$startlabel
Local $infobutton
Local $msg, $item, $hItem, $text,$qt
Local $editplus, $views, $j
;从配置文件中读出值
$editplus = IniRead("conf.ini","editplus","editplus","");读取editplus路径
$views = IniRead("conf.ini","views","views","");读取文件数
Local $filename[$views],$filedir[$views],$filedes[$views],$sunfilels[$views],$description[$views];创建数组,分别装文件路径,文件简介和创建文件列表用的菜单,装简介的label
For $i = 0 to $views-1 Step 1
$filename[$i]=IniRead("conf.ini",$i,"filename","")
$filedir[$i]=IniRead("conf.ini",$i,"filedir","")
$filedes[$i]=IniRead("conf.ini",$i,"filedes","")
Next
$Form1 = GUICreate("GUI例子", 720, 550, -1, -1, $WS_OVERLAPPEDWINDOW);创建一个 GUI 窗口
GUISetIcon("favicon.ico", 0);设置窗口图标
GUISetState(@SW_SHOW) ; 显示窗口
;创建树形目录的容器,指定其样式
$treeview = GUICtrlCreateTreeView(6, 6, 200, 520, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
;在树形目录框中创建一级菜单
$filels = GUICtrlCreateTreeViewItem("文件列表", $treeview)
;文件列表,根据配置文件中所设置的创建子菜单
For $i = 0 to $views-1 Step 1
$sunfilels[$i] = GUICtrlCreateTreeViewItem($filedir[$i], $filels)
Next
$startlabel = GUICtrlCreateLabel("autoconf V1.0版,欢迎各位多提意见以改进,谢谢!", 220, 12, 490, 490,$ES_READONLY);创建开始最开始的label
For $i = 0 to $views-1 Step 1
$description[$i] = GUICtrlCreateEdit($filedes[$i], 220, 12, 490, 490,$ES_READONLY);创建说明容器
GUICtrlSetState(-1, $GUI_HIDE); 在初始化期间隐藏
Next
$infobutton = GUICtrlCreateButton("修改", 490, 505, 70, 20) ;创建按钮,用于读取文件路径
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $infobutton
$item = GUICtrlRead($treeview) ; 获取当前挑选的 treeview 项目的控件ID
If $item = 0 Then
MsgBox(64, "autoconf V1.0", "没有选择文件")
Else
$text = GUICtrlRead($item, 1) ; 获取 treeview 项目的文本
If $text == "" Then
MsgBox(16, "Error", "当取回关于文件信息时发生错误")
ElseIf $text == $filels Then
MsgBox(16, "Error", "请选择住下列文件")
ElseIf $text == $qt Then
MsgBox(16, "Error", "请选择住下列文件")
Else
;MsgBox(64, "",$text); $advmsg 包含文本 and $advmsg 包含 treeview 项目的状态数值
Run($editplus & " " & $text)
EndIf
EndIf
Case $msg = $filels
GUICtrlSetState($startlabel, $GUI_SHOW)
For $i = 0 To $views-1 Step 1
GUICtrlSetState($description[$i], $GUI_HIDE)
Next
EndSelect
;判断当i不等于j时 label的显示与否
For $i = 0 To $views-1 Step 1
For $j = 0 To $views-1 Step 1
If $msg = $sunfilels[$i] And $j <> $i Then
GUICtrlSetState($description[$i], $GUI_show)
GUICtrlSetState($description[$j], $GUI_HIDE)
GUICtrlSetState($startlabel, $GUI_HIDE)
EndIf
Next
Next
WEnd
GUIDelete()
EndFunc ;==>open
页:
[1]