GUICtrlCreateListView双击事件窗口关闭问题。[已解决]
本帖最后由 ddx13 于 2010-10-25 12:57 编辑在GUICtrlCreateListView里双击后,跳出新的窗体,但是关闭新的窗体的同时主窗口也会被关闭,请有什么办法可以解决关(关闭新跳出的窗体,但是主窗口却不关闭。)
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
$Form1 = GUICreate("Form1", 410, 310)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("||", 8, 8, 400, 300)
GUISetState(@SW_SHOW)
For $I = 1 To 10
GUICtrlCreateListViewItem($I, $ListView1)
Next
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom
Case $ListView1
Switch $Event
Case $NM_DBLCLK ; 双击
$JHLIST1=GUICtrlRead(GUICtrlRead($ListView1))
If $JHLIST1=0 Then Return
$JHLIST2 = StringSplit($JHLIST1, "|",1)
$JHSPCK=GUICreate("商品查看" , 415, 325)
GUICtrlCreateGroup("", 2, 0, 409, 321)
GUICtrlCreatePic("", 4, 9, 404, 308)
GUICtrlSetImage ( -1, @ScriptDir & "\IMAGE\商品\"&$JHLIST2[$JHLIST2-1] )
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc 试试这个:
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <array.au3>
$WinMain = GUICreate("主窗口", 410, 310) ;创建主窗口
$ListView1 = GUICtrlCreateListView("||", 8, 8, 400, 300)
For $I = 1 To 10
GUICtrlCreateListViewItem($I, $ListView1)
Next
$WinSub = GUICreate("商品查看", 415, 325 );创建子窗口
$Group1=GUICtrlCreateGroup("", 2, 0, 409, 321)
$Pic=GUICtrlCreatePic("", 4, 9, 404, 308)
GUICtrlSetImage(-1, @ScriptDir & "\IMAGE\商品\");& $JHLIST2[$JHLIST2 - 1])
$Group2=GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISwitch($WinMain) ;切换当前窗口到主窗口
GUISetState(@SW_SHOW,$WinMain)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Switch $nMsg
Case $WinMain
Exit
Case $WinSub
GUISwitch($WinSub)
GUISetState(@SW_HIDE)
EndSwitch
EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom
Case $ListView1
Switch $Event
Case $NM_DBLCLK ; 双击
$JHLIST1 = GUICtrlRead(GUICtrlRead($ListView1))
If $JHLIST1 = 0 Then Return
$JHLIST2 = StringSplit($JHLIST1, "|", 1)
GUISwitch($WinSub)
GUISetState(@SW_SHOW)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY 谢谢,晕死,昨天想到死胡同里了,非常感谢。 3mile 的代码真强,漂亮,谢谢分享。{:face (317):} $nMsg = GUIGetMsg(1)
学到这个。
页:
[1]