|
本帖最后由 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 |
|