子窗口问题:用按钮打开子窗口正常,但在Listview里双击打开异常
本来还以为很简单的问题,但实际操作起来,还是存在很多问题在这个练习程序里,在Listview里双击一个条目,窗口是打开了,但显示不正常(一开始2个窗口都死掉,过了10秒左右显示“没有响应”)
最后新建了个按钮,打开却是正常的,百思不得其解,请高手指导
Autoit版本:3.2.10.0
#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_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
[ 本帖最后由 zeebit 于 2008-8-27 10:27 编辑 ] 我也是这个问题,怎么就没有人回答啊。。晕。。 这个问题已处理,但是我就是不知道为什么。。晕 #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_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 试了下,可以
先谢谢aa147147
研究一下 用你的代码调试了一下,部分调试结果如下:
$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 停顿一下就行了
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
页:
[1]