找回密码
 加入
搜索
查看: 3442|回复: 4

子窗口问题:用按钮打开子窗口正常,但在Listview里双击打开异常

[复制链接]
发表于 2008-8-27 10:22:31 | 显示全部楼层 |阅读模式
本来还以为很简单的问题,但实际操作起来,还是存在很多问题
在这个练习程序里,在Listview里双击一个条目,窗口是打开了,但显示不正常(一开始2个窗口都死掉,过了10秒左右显示“没有响应”)
最后新建了个按钮,打开却是正常的,百思不得其解,请高手指导
Autoit版本:3.2.10.0
[au3]#AutoIt3Wrapper_UseAnsi=y

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

#Region
$Form_main = GUICreate("$Form_main", 703, 446)
$Button_show_subgui = GUICtrlCreateButton("显示", 598, 19, 75, 25, 0)
; ListView
Global $ListView_main = _GUICtrlListView_Create($Form_main, "", 10, 65, 681, 330, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
    ; Add columns
    _GUICtrlListView_InsertColumn($ListView_main, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($ListView_main, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($ListView_main, 2, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($ListView_main, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($ListView_main, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($ListView_main, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($ListView_main, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($ListView_main, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($ListView_main, "Row 3: Col 1", 2)

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListView_main)]
_GUICtrlListView_SetExtendedListViewStyle($ListView_main, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $GUI_DOCKAUTO))
GUICtrlSendMsg($ListView_main, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
#EndRegion

While 1
        $nMsg = GUIGetMsg()
        Select
                Case $nMsg = $GUI_EVENT_CLOSE
                        Exit
                Case $nMsg = $Button_show_subgui
                        _subgui_show()
        EndSelect
WEnd

Func _subgui_show()
        $Form_show = GUICreate("$Form_show", 400, 300)
        $Button_close_subgui = GUICtrlCreateButton("关闭子窗口",10,10)
       
        GUISetState(@SW_SHOW)
       
        While 1
                Switch guigetmsg()
                        Case $GUI_EVENT_CLOSE
                                GUISetState(@SW_ENABLE,$Form_main)
                                GUIDelete($Form_show)
                                ExitLoop
                        Case $Button_close_subgui
                                GUISetState(@SW_ENABLE,$Form_main)
                                GUIDelete($Form_show)
                                ExitLoop
                EndSwitch
        WEnd
       
EndFunc                ;==>_gui_show

Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
        Local $HDR_hwndFrom, $HDR_code, $HDR_tNM
        $HDR_tNM = DllStructCreate($tagNMHDR, $lParam)
        $HDR_hwndFrom = HWnd(DllStructGetData($HDR_tNM, "hWndFrom"))
        $HDR_code = DllStructGetData($HDR_tNM, "Code")
           
        Switch $HDR_hwndFrom
                Case $ListView_main                       
                        Switch $HDR_code
                                Case $LVN_COLUMNCLICK ; A column was clicked
                                        Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                                        ;ListView排序
                                        _GUICtrlListView_SimpleSort($ListView_main, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
                                Case $NM_RCLICK                         ; 右击
                                        If _GUICtrlListView_GetSelectedCount($ListView_main) >= 1 Then
;~                                                 ShowMenu($Form_main, $OptionsContext)
                                        EndIf
                                Case $NM_DBLCLK                         ; 双击
                                        If _GUICtrlListView_GetSelectedCount($ListView_main) >= 1 Then
                                                _subgui_show()
                                        EndIf
                        EndSwitch
        EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY[/au3]

[ 本帖最后由 zeebit 于 2008-8-27 10:27 编辑 ]
发表于 2008-9-6 16:48:43 | 显示全部楼层
我也是这个问题,怎么就没有人回答啊。。晕。。
发表于 2008-9-6 17:04:42 | 显示全部楼层
这个问题已处理,但是我就是不知道为什么。。晕
发表于 2008-9-6 17:06:19 | 显示全部楼层
#AutoIt3Wrapper_UseAnsi=y

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

#Region
$Form_main = GUICreate("$Form_main", 703, 446)
$Button_show_subgui = GUICtrlCreateButton("显示", 598, 19, 75, 25, 0)
; ListView
Global $ListView_main = _GUICtrlListView_Create($Form_main, "", 10, 65, 681, 330, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
    ; Add columns
    _GUICtrlListView_InsertColumn($ListView_main, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($ListView_main, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($ListView_main, 2, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($ListView_main, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($ListView_main, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($ListView_main, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($ListView_main, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($ListView_main, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($ListView_main, "Row 3: Col 1", 2)

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListView_main)]
_GUICtrlListView_SetExtendedListViewStyle($ListView_main, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $GUI_DOCKAUTO))
GUICtrlSendMsg($ListView_main, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
#EndRegion

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Button_show_subgui
            _subgui_show()
    EndSelect
WEnd

Func _subgui_show()
GUISetState(@SW_HIDE,$Form_main)
    $Form_show = GUICreate("$Form_show", 400, 300)
    $Button_close_subgui = GUICtrlCreateButton("关闭子窗口",10,10)
   
    GUISetState(@SW_SHOW)
   
    While 1
sleep (10)
        Switch guigetmsg()

            Case $Button_close_subgui
                GUISetState(@SW_SHOW ,$Form_main)
                GUIDelete($Form_show)
                ExitLoop
        EndSwitch
    WEnd
   
EndFunc        ;==>_gui_show

Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    Local $HDR_hwndFrom, $HDR_code, $HDR_tNM
    $HDR_tNM = DllStructCreate($tagNMHDR, $lParam)
    $HDR_hwndFrom = HWnd(DllStructGetData($HDR_tNM, "hWndFrom"))
    $HDR_code = DllStructGetData($HDR_tNM, "Code")
        
    Switch $HDR_hwndFrom
        Case $ListView_main            
            Switch $HDR_code
                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    ;ListView排序
                    _GUICtrlListView_SimpleSort($ListView_main, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
                Case $NM_RCLICK             ; 右击
                    If _GUICtrlListView_GetSelectedCount($ListView_main) >= 1 Then
;~                         ShowMenu($Form_main, $OptionsContext)
                    EndIf
                Case $NM_DBLCLK             ; <strong><font color="#FF0000">双击</font></strong>
                    If _GUICtrlListView_GetSelectedCount($ListView_main) >= 1 Then
                        _subgui_show()
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
 楼主| 发表于 2008-9-7 13:42:59 | 显示全部楼层
试了下,可以
先谢谢aa147147

研究一下
发表于 2010-6-2 12:49:43 | 显示全部楼层
用你的代码调试了一下,部分调试结果如下:

        $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0068: 0-0:         Local $HDR_hwndFrom, $HDR_code, $HDR_tNM
0069: 0-0:         $HDR_tNM = DllStructCreate($tagNMHDR, $lParam)
0070: 0-0:         $HDR_hwndFrom = HWnd(DllStructGetData($HDR_tNM, "hWndFrom"))
0071: 0-0:         $HDR_code = DllStructGetData($HDR_tNM, "Code")
0073: 0-0:         Switch $HDR_hwndFrom
0075: 0-0:                         Switch $HDR_code
0089: 0-0:         EndSwitch
0090: 0-0:     Return $GUI_RUNDEFMSG
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0068: 0-0:         Local $HDR_hwndFrom, $HDR_code, $HDR_tNM
0069: 0-0:         $HDR_tNM = DllStructCreate($tagNMHDR, $lParam)
0070: 0-0:         $HDR_hwndFrom = HWnd(DllStructGetData($HDR_tNM, "hWndFrom"))
0071: 0-0:         $HDR_code = DllStructGetData($HDR_tNM, "Code")
0073: 0-0:         Switch $HDR_hwndFrom
0075: 0-0:                         Switch $HDR_code
0089: 0-0:         EndSwitch
0090: 0-0:     Return $GUI_RUNDEFMSG
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0068: 0-0:         Local $HDR_hwndFrom, $HDR_code, $HDR_tNM
0069: 0-0:         $HDR_tNM = DllStructCreate($tagNMHDR, $lParam)
0070: 0-0:         $HDR_hwndFrom = HWnd(DllStructGetData($HDR_tNM, "hWndFrom"))
0071: 0-0:         $HDR_code = DllStructGetData($HDR_tNM, "Code")
0073: 0-0:         Switch $HDR_hwndFrom
0075: 0-0:                         Switch $HDR_code
0089: 0-0:         EndSwitch
0090: 0-0:     Return $GUI_RUNDEFMSG
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select
0043: 0-0: WEnd
0036: 0-0:         $nMsg = GUIGetMsg()
0037: 0-0:         Select


可以看到在Func _subgui_show()函数中的While循环为死循环,While循环时间间隔很短,导致在循环的过程中无法捕获关闭消息  
        While 1
                Switch guigetmsg()
                        Case $GUI_EVENT_CLOSE
                                GUISetState(@SW_ENABLE,$Form_main)
                                GUIDelete($Form_show)
                                ExitLoop
                        Case $Button_close_subgui
                                GUISetState(@SW_ENABLE,$Form_main)
                                GUIDelete($Form_show)
                                ExitLoop
                EndSwitch
        WEnd
        
EndFunc                ;==>_gui_show
发表于 2010-6-2 12:51:31 | 显示全部楼层
停顿一下就行了
   While 1
        Sleep(10)
                Switch guigetmsg()
                        Case $GUI_EVENT_CLOSE
                                GUISetState(@SW_ENABLE,$Form_main)
                                GUIDelete($Form_show)
                                ExitLoop
                        Case $Button_close_subgui
                                GUISetState(@SW_ENABLE,$Form_main)
                                GUIDelete($Form_show)
                                ExitLoop
                EndSwitch
        WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 05:25 , Processed in 0.074260 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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