找回密码
 加入
搜索
查看: 3722|回复: 3

[GUI管理] 关于列表框(GUICtrlCreateList)问题.

[复制链接]
发表于 2010-4-25 11:32:03 | 显示全部楼层 |阅读模式
1.使用GUICtrlCreateList建立了二个列表框,现在希望当左边的列表框中被选中的块的内容会列出在右边列表框中.功能是实现,但有一个问题,由于使用了WHILE循环,右边的内容会一直不间断被刷新,无法选取.如选了第3或其它条目,瞬间又被清除了选择?如何实现根据左列表框被选中项目在右列表框中列出内容且不会自动刷新.
2.由于使用了多个WHILE循环,退出程式要点N次关闭.有办法解决么?
各位大哥,帮帮忙.
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <GuiTreeView.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\temp\image.kxf
$Form1_1 = GUICreate("Image Restore Tool", 743, 450, 197, 154)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1_1)
_GUICtrlStatusBar_SetSimple($StatusBar1)
_GUICtrlStatusBar_SetText($StatusBar1, "Create By:Yuanyongping  Create Date:2010/04/19 Version:V1.0")
$Label1 = GUICtrlCreateLabel("     Image Restore and Backup Tool For RSI-SH         ", 0, 0, 743, 45)
GUICtrlSetFont(-1, 26, 400, 0, "Georgia")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x008080)
$Group1 = GUICtrlCreateGroup("Storage Device Information", 10, 200, 529, 129)
GUICtrlSetFont(-1, 12, 400, 0, "Constantia")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("本机硬盘:", 24, 225, 81, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
$Label3 = GUICtrlCreateLabel("恢复硬盘:", 24, 246, 81, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
$Label4 = GUICtrlCreateLabel("容量:", 286, 225, 47, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
$Label5 = GUICtrlCreateLabel("容量:", 286, 246, 47, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
$Label6 = GUICtrlCreateLabel("分区数:", 432, 226, 64, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
$Label7 = GUICtrlCreateLabel("分区数:", 433, 246, 64, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
$Label8 = GUICtrlCreateLabel("提示:", 24, 287, 47, 20)
GUICtrlSetFont(-1, 12, 800, 0, "新宋体")
GUICtrlSetColor(-1, 0xFF0000)
$Input1 = GUICtrlCreateInput("", 72, 281, 457, 27)
GUICtrlSetFont(-1, 14, 800, 0, "黑体")
GUICtrlSetColor(-1, 0xFF0000)
$L_hdd = GUICtrlCreateLabel("", 99, 220, 184, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
$D_HDD = GUICtrlCreateLabel("", 99, 240, 184, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
$D_HDD_SIZE = GUICtrlCreateLabel("", 329, 240, 94, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
$L_HDD_SIZE = GUICtrlCreateLabel("", 329, 220, 94, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
$D_HDD_PAR = GUICtrlCreateLabel("", 493, 240, 24, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
$L_HDD_PAR = GUICtrlCreateLabel("", 493, 220, 24, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Note", 11, 48, 529, 137)
GUICtrlSetFont(-1, 12, 400, 0, "Segoe UI")
GUICtrlSetColor(-1, 0x0000FF)
$Label9 = GUICtrlCreateLabel("1.在镜像恢复前,请移除除需恢复硬盘外的其它存储设备.", 19, 72, 485, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Constantia")
$Label10 = GUICtrlCreateLabel("2.若恢复硬盘有异响,请检查是否供电不足导致.", 19, 99, 438, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Constantia")
$Label11 = GUICtrlCreateLabel("3.在镜像恢复期间请勿插入其它移动存储设备,否则会报错.", 21, 124, 508, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Constantia")
$Label12 = GUICtrlCreateLabel("4.若发现"我的电脑"内盘符过多,请重启计算机.", 22, 149, 429, 27)
GUICtrlSetFont(-1, 14, 400, 0, "Constantia")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Restore and Backup", 9, 343, 529, 81, -1, $WS_EX_TRANSPARENT)
GUICtrlSetFont(-1, 12, 400, 0, "Constantia")
GUICtrlSetColor(-1, 0x0000FF)
$Setting = GUICtrlCreateButton("Setting", 370, 367, 153, 41)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
$Button1 = GUICtrlCreateButton("Restore", 22, 367, 153, 41)
GUICtrlSetFont(-1, 15, 800, 0, "Comic Sans MS")
$Button2 = GUICtrlCreateButton("Backup", 194, 367, 153, 41)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Restore Option", 547, 46, 185, 377)
GUICtrlSetFont(-1, 11, 400, 0, "Segoe UI")
GUICtrlSetColor(-1, 0x0000FF)
$Combo1 = GUICtrlCreateCombo("Choose Model", 551, 72, 177, 25)
GUICtrlSetData(-1, "Toshiba|Sony|Benq|Viewsonic|Sharp|HP|Acer|NB5|Install System")
GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
$List1 = GUICtrlCreateList("", 551, 108, 177, 306)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetCursor (-1, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;判断GHOST程式是否存在
$cfg=@ScriptDir&"\config.ini"
If FileExists($cfg)= 0  Then
                MsgBox(0+64,"Error","Config.ini配置文件丢失!")
        Else 
                $Read_ghost=IniRead($cfg,"config","exe","")
If FileExists($Read_ghost)=0  Then
        MsgBox(0+64,"Error","没有发现Ghost32.exe程式,请配置GHOST32程式路径")
        Exit
EndIf
EndIf
AdlibRegister ("usb",1000)
IniWrite($cfg,"config","image","")

Global $read_combo,$read_list,$read_model,$yp,$np,$newprj,$prj_name,$read_prjname,$newname,$yname,$nname,$chgname
Global $var1,$iI,$var,$ii,$lb_project,$List1,$l_model,$l_project,$var2,$newname1,$del_prj,$rd_prjname,$savechg,$rd_prj
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $List1
        If $read_combo <> "Choose Model" Then
                $read_list=GUICtrlRead ($List1)
        EndIf
        If $read_combo <> "Choose Model" And $read_list <> "" Then
                $read_model=IniRead($cfg,$read_combo,$read_list,"")
                IniWrite ($cfg,"config","image",$read_model)
    EndIf
Case $Combo1
     Project()

Case $Button1
     Restore()

Case $Setting
        set()
EndSwitch
WEnd

Func usb()
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$getdevice = $objWMIService.ExecQuery("Select * from Win32_DISKDRIVE")
$usbdev=0
For $object in $getdevice
        If $object.interfaceType = "USB" Then
               $usbdev=$usbdev+1
        EndIf
        If $usbdev > 1 Then MsgBox(0+64,"USB Test","System Detect two USB device!Pls Remove.")
Next

$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$getdevice = $objWMIService.ExecQuery("Select * from Win32_DISKDRIVE")
For $object in $getdevice
        If $object.DeviceID = "\\.\PHYSICALDRIVE0" And  $object.interfaceType = "IDE" Then
              GUICtrlSetData($L_hdd,$object.Caption)
                GUICtrlSetData($L_HDD_SIZE,Floor($object.size/1000/1000/1000)&" GB")
                GUICtrlSetData($L_HDD_PAR,$object.Partitions)
        EndIf
Next

$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$getdevice = $objWMIService.ExecQuery("Select * from Win32_DISKDRIVE")
For $object in $getdevice
        If $object.DeviceID <> "\\.\PHYSICALDRIVE0"  Then
              GUICtrlSetData($d_hdd,$object.Caption)
                GUICtrlSetData($d_HDD_SIZE,Floor($object.size/1000/1000/1000)&" GB")
                GUICtrlSetData($d_HDD_PAR,$object.Partitions)
                GUICtrlSetData($Input1,"请在右边窗口中选择对应机型进行恢复.")
                ExitLoop
        ElseIf $object.DeviceID = "\\.\PHYSICALDRIVE0" Then
                GUICtrlSetData($Input1,"未检测到外置存储器,请插入要恢复的硬盘!")
        EndIf
Next
EndFunc


Func Restore()
        $read_input=GUICtrlRead($Input1)
If ProcessExists("ghost32.exe")=0 Then
If $read_model <> ""  Then
GUICtrlSetData($Input1,"恢复系统进行中...")
Run ($Read_ghost&" "&"-clone"&","&"Mode=load"&","&"src="&$read_model&","&"dst=2"&"-fx -sure -nofile")
ElseIf StringInStr($read_input,"未")=0 Then
GUICtrlSetData($Input1,"请选择要恢复的镜像.")
ElseIf $read_model = ""  Then
        MsgBox(0,"路径出错","系统检测到所选机型镜像文件路径为空.")
EndIf
Else
        MsgBox(0+64,"注意!","系统检测到已经有在运行Ghost32程式,"&@CRLF&"请先结束已运行的Ghost32.")
EndIf

EndFunc


Func Project()
$read_combo=GUICtrlRead ($Combo1)
         If $read_combo = "Choose Model" Then GUICtrlSetData ($List1,"")
         If $read_combo="sharp" Or  $read_combo="benq" Or $read_combo="nb5" Or $read_combo="acer" Or $read_combo="Toshiba" Or $read_combo="hp"  Or $read_combo="Viewsonic" Or $read_combo="Sony" Or $read_combo="Install system" Then
     GUICtrlSetData($List1,"")
        $var = IniReadSection("config.ini", $read_combo)
     If @error Then 
        MsgBox(4096, "项目无机型", "系统检测到所选项目没有配置机型.")
     Else
        For $i = 1 To $var[0][0]
                If $var[$i][0] <>""  Then
                        GUICtrlSetData ($List1,StringUpper($var[$i][0]))
                EndIf
        Next
    EndIf
EndIf
EndFunc


Func set()
        
$Form2 = GUICreate("Restore and Backup Option", 481, 492, 192, 122)
$Restore = GUICtrlCreateGroup("Restore", 6, 16, 465, 113)
GUICtrlSetFont(-1, 11, 800, 0, "MS UI Gothic")
GUICtrlSetColor(-1, 0x0000FF)
$FX = GUICtrlCreateCheckbox("不出现提示", 16, 40, 97, 17)
$SURE = GUICtrlCreateCheckbox("确认所有询问", 16, 62, 105, 17)
$RB = GUICtrlCreateCheckbox("重启", 16, 85, 97, 17)
$quiet = GUICtrlCreateCheckbox("静默模式", 16, 107, 97, 17)
$nocrc = GUICtrlCreateCheckbox("忽略CRC校验错误", 128, 61, 137, 17)
$noask = GUICtrlCreateCheckbox("不询问分卷文件", 128, 39, 129, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$backup = GUICtrlCreateGroup("Backup", 6, 136, 465, 113)
GUICtrlSetFont(-1, 11, 800, 0, "MS UI Gothic")
GUICtrlSetColor(-1, 0x0000FF)
$split = GUICtrlCreateCheckbox("指定大小", 16, 160, 81, 17)
$autoname = GUICtrlCreateCheckbox("自动命名GHS", 16, 182, 113, 17)
$compress = GUICtrlCreateCheckbox("压缩模式", 16, 205, 97, 17)
$Compressrate = GUICtrlCreateCombo("Z1", 99, 159, 145, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$pm = GUICtrlCreateGroup("Project/Model", 5, 256, 465, 225)
GUICtrlSetFont(-1, 11, 800, 0, "MS UI Gothic")
GUICtrlSetColor(-1, 0x0000FF)
$l_Project = GUICtrlCreateList("", 10, 295, 121, 174)
$l_model = GUICtrlCreateList("", 240, 296, 121, 174)
$p_add = GUICtrlCreateButton("增加", 146, 319, 75, 33)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
$p_chg = GUICtrlCreateButton("重命名", 146, 362, 75, 33)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
$p_del = GUICtrlCreateButton("删除", 146, 406, 75, 33)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
$m_add = GUICtrlCreateButton("增加", 375, 319, 75, 33)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
$m_chg = GUICtrlCreateButton("重命名", 375, 362, 75, 33)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
$m_del = GUICtrlCreateButton("删除", 375, 406, 75, 33)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
$lb_project = GUICtrlCreateLabel("项目", 48, 274, 34, 18)
$lb_model = GUICtrlCreateLabel("机型", 286, 275, 34, 18)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$var1 = IniReadSectionNames("config.ini")
If @error Then 
        MsgBox(4096, "Config Error", "Config文件未配置.")
     Else
        For $ii = 1 To $var1[0]
                        GUICtrlSetData ($l_project,StringUpper($var1[$ii]))
        Next
EndIf        
 



While 1
$mMsg = GUIGetMsg()
Switch $mMsg
        Case $GUI_EVENT_CLOSE        
ExitLOOP
Case $p_add 
        add()
Case $p_chg
    chg()
Case $l_project <> ""
ls_model()

Case $m_chg

Case $m_del
        
EndSwitch
WEnd
GUIDelete("from2")
EndFunc



Func chg()
$Form5 = GUICreate("Input New Project Name", 211, 104, 192, 124)
$rd_prjname=GUICtrlRead($l_project)
If $rd_prjname <> "" Or $rd_prjname="sharp" Or  $rd_prjname="benq" Or $rd_prjname="nb5" Or $rd_prjname="acer" Or $rd_prjname="Toshiba" Or $rd_prjname="hp"  Or $rd_prjname="Viewsonic" Or $rd_prjname="Sony" Or $rd_prjname="Install system" Then
$name = GUICtrlCreateLabel("Please Input New Name:", 8, 8, 181, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x808000)
$chgname = GUICtrlCreateInput("", 8, 40, 185, 21)
$yname = GUICtrlCreateButton("确定", 21, 72, 75, 25)
$nname = GUICtrlCreateButton("取消", 104, 72, 75, 25)
GUISetState(@SW_SHOW)
EndIf

While 1
$savechg=GUICtrlRead($chgname)
$nMsg = GUIGetMsg()
Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        ExitLOOP
                Case $yname
If $savechg<> "" Then
                $a=IniRenameSection($cfg,$rd_prjname,$savechg,1)
                ExitLOOP
                If $a= 0 Then 
                        MsgBox (0,"提示","该项目没有任何机型.")
                EndIf
        Else
                MsgBox (0,"错误!","项目名称不能为空,请重新输入.")
EndIf
Case $nname
        ExitLOOP
        EndSwitch
WEnd
set()
GUIDelete ("from5")
EndFunc

Func  add()
$Form3 = GUICreate("Input New Project", 211, 104, 192, 124)
$Label1 = GUICtrlCreateLabel("Please Input New Project:", 8, 8, 181, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x808000)
$newprj = GUICtrlCreateInput("", 8, 40, 185, 21)
$yp = GUICtrlCreateButton("确定", 21, 72, 75, 25)
$np = GUICtrlCreateButton("取消", 104, 72, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
        $rd_newprj=GUICtrlRead($newprj)
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        ExitLOOP
                Case $yp
If  $rd_newprj<> "" Then 
                IniWriteSection($cfg,$rd_newprj,"")
                ExitLoop
        Else
        MsgBox (0,"错误提示!","新增项目名称不能为空!")
        EndIf

Case $np
        ExitLOOP
        EndSwitch
WEnd
GUIDelete("form3")
SET()
EndFunc
                
Func ls_model()
$rd_prj=GUICtrlRead($l_project)
If  $rd_prj<> "" Or $rd_prj="sharp" Or  $rd_prj="benq" Or $rd_prj="nb5" Or $rd_prj="acer" Or $rd_prj="Toshiba" Or $rd_prj="hp"  Or $rd_prj="Viewsonic" Or $rd_prj="Sony" Or $rd_prj="Install system" Then
          GUICtrlSetData($l_model,"")
        $var2 = IniReadSection("config.ini", $rd_prj)
     If Not @error Then
        If $var2 <> "" Then   
        For $iii = 1 To $var2[0][0]
                If $var2[$iii][0] <>""  Then
                        GUICtrlSetData ($l_model,StringUpper($var2[$iii][0]))
                EndIf
        Next        
        EndIf
EndIf
EndIf        

EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-4-25 12:06:51 | 显示全部楼层
你的这种代码生成模式不好。 建议你将所有用到的窗体在程序运行的时候都创建出来。 只显示主窗体。 然后根据主窗体的相应事件控制相应窗体的显示。主循环中包括主窗体的事件和所有子窗体中的消息循环。 这样,就不会出错了。
发表于 2010-4-25 12:19:00 | 显示全部楼层
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
;主窗体的创建
$MainForm = GUICreate("主窗体", 418, 260, 192, 114)
$BTinMainForm1 = GUICtrlCreateButton("主窗体的按钮1", 16, 16, 169, 65)
$BTinMainForm2 = GUICtrlCreateButton("主窗体的按钮2", 16, 104, 169, 65)
;子窗体一的创建
$ChildWindow1 = GUICreate("子窗体一", 413, 305, 238, 145)
$BTinChildWD1 = GUICtrlCreateButton("子窗体一的按钮", 112, 96, 177, 73)
;子窗体二的创建
$ChildWindow2 = GUICreate("子窗体二", 413, 305, 436, 275)
$BTinChildWD2 = GUICtrlCreateButton("子窗体二的按钮", 16, 16, 161, 217)
;关键代码
GUISwitch($MainForm)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

        ;主消息循环中写入所有消息的操作代码
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE  ;关闭的代码
                        ;判断是哪个窗体发送的$GUI_EVENT_CLOSE消息。
                        If WinActive("主窗体") Then  
                                Exit
                        ElseIf WinActive("子窗体一") Then
                                GUISwitch($ChildWindow1)  ;子窗体一发送的则隐藏子窗体一
                            GUISetState(@SW_HIDE)
                        ElseIf WinActive("子窗体二") Then        
                                GUISwitch($ChildWindow2)  ;子窗体二发送的则隐藏子窗体二
                            GUISetState(@SW_HIDE)
                        EndIf                                
                Case $BTinMainForm1   ;主窗体的第一个按钮的代码
                        GUISwitch($ChildWindow1)  ;切换到第一个子窗体并显示
                        GUISetState(@SW_SHOW)
                Case $BTinMainForm2   ;主窗体第二个按钮的代码
                    GUISwitch($ChildWindow2) ;切换到第二个子窗体并显示
                        GUISetState(@SW_SHOW)
                Case $BTinChildWD1  ;子窗体一的按钮的代码
                        MsgBox(0,"子窗体一","我点了第一个子窗体的按钮")
                        GUISwitch($ChildWindow1)  ;隐藏自窗体一
                        GUISetState(@SW_HIDE)
                Case $BTinChildWD2
                        MsgBox(0,"子窗体二","我点了第二个子窗体的按钮")
                        GUISwitch($ChildWindow2)  ;隐藏子窗体二
                        GUISetState(@SW_HIDE)
        EndSwitch
WEnd
给你个代码的例子。 清晰明了。 比你那个多个WHILE循环好多了。

评分

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

查看全部评分

发表于 2010-4-25 22:18:52 | 显示全部楼层
哈哈,楼上的不错,学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 10:44 , Processed in 0.084856 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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