找回密码
 加入
搜索
查看: 3788|回复: 1

[GUI管理] 两个子窗口ListView右键菜单的问题

[复制链接]
发表于 2010-12-19 17:20:56 | 显示全部楼层 |阅读模式
本帖最后由 zhoujinshi 于 2010-12-20 11:19 编辑

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

Global $GUI1,$GUI2,$MainGUI,$ListView1,$ListView2
Global $Menu1, $menu2
Global Enum $MenuAdd = 1000, $MenuEdit, $MenuDel

$Menu1=_GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($Menu1, 0, " 添加数据    ", $MenuAdd)
_GUICtrlMenu_InsertMenuItem($Menu1, 1, " 修改数据    ", $MenuEdit)
_GUICtrlMenu_InsertMenuItem($Menu1, 2, " 删除数据    ", $MenuDel)

$Menu2=_GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($Menu2, 0, " 修改记录    ", $MenuEdit)
_GUICtrlMenu_InsertMenuItem($Menu2, 1, " 删除记录    ", $MenuDel)

$MainGUI=GUICreate("主窗口",800,600)
$Button1=GUICtrlCreateButton("按钮一",60,200)
$Button2=GUICtrlCreateButton("按钮二",120,200)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
        Sleep(1)
        $Msg=GUIGetMsg()
        If $Msg=$GUI_EVENT_CLOSE Then ExitLoop
        If $Msg=$Button1 Then CreateGui1()
        If $Msg=$Button2 Then CreateGui2()
WEnd

Func CreateGui1()
        $gui1=GUICreate("窗口一",400,300,-1,-1,-1,-1,$MainGUI)
        $ListView1=GUICtrlCreateListView("ABCD|EFGH",50,50)
        GUICtrlCreateListViewItem("1234|5678",-1)
        GUISetState(@SW_SHOW)
        While 1
                $Msg_child=GUIGetMsg()
                If $Msg_child=$GUI_EVENT_CLOSE Then ExitLoop
        WEnd
        GUIDelete($gui1)
EndFunc

Func CreateGui2()
        $gui2=GUICreate("窗口二",400,300,-1,-1,-1,-1,$MainGUI)
        $ListView2=GUICtrlCreateListView("1234|5678",50,50)
        GUICtrlCreateListViewItem("ABCD|EFGH",-1)
        GUISetState(@SW_SHOW)
        While 1
                $Msg_child=GUIGetMsg()
                If $Msg_child=$GUI_EVENT_CLOSE Then ExitLoop
        WEnd
        GUIDelete($gui2)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        Local $hWndFrom, $iCode, $tNMHDR, $hWndListView1,$hWndListView2, $SelectedID, $hWndTab
        $hWndListView1 = $ListView1
        $hWndListView2 = $ListView2
        If Not IsHWnd($ListView1) Then $hWndListView1 = GUICtrlGetHandle($ListView1)
        If Not IsHWnd($ListView2) Then $hWndListView2 = GUICtrlGetHandle($ListView2)
        $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case $hWndListView1
                        Switch $iCode
                                Case $NM_RCLICK
                                        If _GUICtrlListView_GetSelectedIndices($hWndListView1) = "" Then
                                                _GUICtrlMenu_SetItemDisabled($Menu1, 1)
                                                _GUICtrlMenu_SetItemDisabled($Menu1, 2)
                                        Else
                                                _GUICtrlMenu_SetItemEnabled($Menu1, 1)
                                                _GUICtrlMenu_SetItemEnabled($Menu1, 2)
                                        EndIf
                                        $SelectedID = _GUICtrlMenu_TrackPopupMenu($Menu1, $hWndListView1, -1, -1, 1, 1, 2)
                                        If $SelectedID = $MenuAdd Then
                                                MsgBox(0,"","您点击了添加")
                                        EndIf
                                        If $SelectedID = $MenuEdit Then
                                                MsgBox(0,"","您点击了编辑")
                                        EndIf
                                        If $SelectedID = $MenuDel Then
                                                MsgBox(0,"","您点击了删除")
                                        EndIf
                                Case $NM_DBLCLK
                                        If _GUICtrlListView_GetSelectedIndices($hWndListView1) <> "" Then MsgBox(0,"","您点击了编辑")
                        EndSwitch
                Case $hWndListView2
                        Switch $iCode
                                Case $NM_RCLICK
                                        If _GUICtrlListView_GetSelectedIndices($hWndListView2) = "" Then
                                                _GUICtrlMenu_SetItemDisabled($Menu2, 0)
                                                _GUICtrlMenu_SetItemDisabled($Menu2, 1)
                                        Else
                                                _GUICtrlMenu_SetItemEnabled($Menu2, 0)
                                                _GUICtrlMenu_SetItemEnabled($Menu2, 1)
                                        EndIf
                                        $SelectedID = _GUICtrlMenu_TrackPopupMenu($Menu2, $hWndListView2, -1, -1, 1, 1, 2)
                                        If $SelectedID = $MenuEdit Then
                                                MsgBox(0,"","您点击了编辑")
                                        EndIf
                                        If $SelectedID = $MenuDel Then
                                                MsgBox(0,"","您点击了删除")
                                        EndIf
                                Case $NM_DBLCLK
                                        If _GUICtrlListView_GetSelectedIndices($hWndListView2) <> "" Then MsgBox(0,"","您点击了编辑")
                        EndSwitch
                EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 楼主| 发表于 2010-12-19 17:22:59 | 显示全部楼层
为什么ListView1和ListView2的右键菜单会变成一样?请哪位大哥回复一下啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 18:50 , Processed in 0.077420 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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