关于列表视图 右键的问题
想通过列表视图选中的项目 如果右键选中的项目的第2列为副服务器的话。弹出的菜单里有"主服转发"和"游戏转发"
如果选中第2列的不是 副服务器.则 只有连接。
求各位大大指导一番!!!!!!
谢谢 难道大大们都去抱MM去了?囧, 是不是这个意思?
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 394, 259, 365, 324)
$ListView1 = GUICtrlCreateListView("名称 |类型", 32, 24, 330, 198)
$ListViewButton = GUICtrlCreateContextMenu($ListView1)
$ListBut_1 = GUICtrlCreateMenuItem("切换为主", $ListViewButton)
$ListBut_2 = GUICtrlCreateMenuItem("切换为副", $ListViewButton)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUICtrlCreateListViewItem('主服务器|aaa', $ListView1)
GUICtrlCreateListViewItem('副服务器|bbb', $ListView1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
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_RCLICK ; 右击
$ss = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)), '|')
If $ss = '主服务器' Then
GUICtrlSetState($ListBut_1, $GUI_DISABLE)
GUICtrlSetState($ListBut_2, $GUI_ENABLE)
Else
GUICtrlSetState($ListBut_2, $GUI_DISABLE)
GUICtrlSetState($ListBut_1, $GUI_ENABLE)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
恩。。就是这个意思。。。。 不过加到我的里面就失效了。。郁闷。 本帖最后由 nmgwddj 于 2012-3-12 03:21 编辑
回复 5# 49666684
注意12行是注册WM_NOTIFY消息。这一行必不可少。
32行是需要监控哪一个控件的消息,这里控件的消息改成你自己的就可以了。
35到42行是读取所选listview的行数据进行分割判断,判断第一列的数据为xxx时禁用哪个菜单、开启哪个菜单,其他同理。 谢谢提示。。。但是你上面的 。我都是对的 本帖最后由 49666684 于 2012-3-12 03:59 编辑
发现那里出问题了。。。谢谢3楼。。。。。 #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#Include <GuiListView.au3>
#Include <GuiTab.au3>
Global $BarName,$Xzhong
#Region ### START Koda GUI section ### Form=
$Gui = GUICreate("Form1", 434, 457, 225, 115)
$Group1 = GUICtrlCreateGroup("", 8, 10, 413, 251)
$ListView1 = GUICtrlCreateListView("名称 | 类型", 19, 28, 390, 218)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 168)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 128)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 270, 413, 95)
$Label1 = GUICtrlCreateLabel("选择网吧:", 26, 300, 80, 25)
$Combo1 = GUICtrlCreateCombo("", 80, 296, 160, 25)
$Label1 = GUICtrlCreateLabel("当前:未选中网吧", 231, 332, 180, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 49, 376, 317, 65)
$Button1 = GUICtrlCreateButton("Button1", 74, 398, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 167, 398, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 260, 398, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListViewButton = GUICtrlCreateContextMenu($ListView1)
$ListBut_1 = GUICtrlCreateMenuItem("连接", $ListViewButton)
$ListBut_2 = GUICtrlCreateMenuItem("游戏转发", $ListViewButton)
$ListBut_3 = GUICtrlCreateMenuItem("主服转发", $ListViewButton)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlCreateListViewItem('主服务器|aaa', $ListView1)
GUICtrlCreateListViewItem('游戏更新|bbb', $ListView1)
GUICtrlCreateListViewItem('副服务器|ccc', $ListView1)
GUICtrlCreateListViewItem('副服务器|ddd', $ListView1)
$Xiala = "请选择网吧...|"&$BarName
GUICtrlSetData($Combo1, $Xiala, "请选择网吧...")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
Sleep (1000)
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCtrl = BitAND($wParam, 0x0000FFFF)
Local $iCode = BitShift($wParam, 16)
Switch $hWnd
Case $Gui
Switch $iCtrl
Case $Button1
Case $Button2
Case $Button3
Exit
Case $ListBut_1
MsgBox(0,0,"连接")
Case $ListBut_2
MsgBox(0,0,"游戏转发")
Case $ListBut_3
MsgBox(0,0,"主服转发")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
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_RCLICK ; 右击
GUICtrlDelete($ListBut_1)
GUICtrlDelete($ListBut_2)
GUICtrlDelete($ListBut_3)
$ss = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)), '|')
If $ss <> 1 Then
If $ss = '副服务器' Then
$ListBut_3 = GUICtrlCreateMenuItem("主服转发", $ListViewButton)
$ListBut_2 = GUICtrlCreateMenuItem("游戏转发", $ListViewButton)
ElseIf $SS = '主服务器' Then
$ListBut_1 = GUICtrlCreateMenuItem("连接", $ListViewButton)
ElseIf $SS = '游戏更新' Then
$ListBut_1 = GUICtrlCreateMenuItem("连接", $ListViewButton)
EndIf
Else
MsgBox(0,"错误","未选中网吧!请重新选择")
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
Local $nID = BitAND($wParam, 0x0000FFFF)
Switch $nID
Case 0xf060
If $hWnd = $Gui Then
Exit
Else
GUIDelete($hWnd)
EndIf
EndSwitch
EndFunc ;==>WM_SYSCOMMAND
发现新问题。。。。。 。如果先选择了主服务器然后右键 点击了连接以后 。。。。。
无论我再怎么点别的服务器。连接副服务器的时候。选择主服连接他还是 运行的连接 (可以看 选择右键菜单后弹出的对话框)
求大大们。帮我检查下。那里出了问题!! 回复 9# 49666684
按上面的方法把按钮禁用就可以了,也符合常理 没有办法实现不同的。服务器 。右键菜单不一样么? 本帖最后由 Ycxw2008 于 2012-3-13 11:42 编辑
简单的写了下,你可以根据你自己的情况再多加判断
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <guimenu.au3>
Global $Select = -1, $ConTextMenu = [['切换为主1', '切换为主2'],['切换为副1', '切换为副2']]
$Form1 = GUICreate("Form1", 394, 259, 365, 324)
$ListView1 = GUICtrlCreateListView("名称 |类型", 32, 24, 330, 198)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUICtrlCreateListViewItem('主服务器|aaa', $ListView1)
GUICtrlCreateListViewItem('副服务器|bbb', $ListView1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
$tNMHDR = DllStructCreate($tagNMHDR, $LParam)
$iCode = DllStructGetData($tNMHDR, "code")
Switch $iCode
Case $NM_RCLICK
$Select = DllStructGetData(DllStructCreate($tagNMLISTVIEW, $LParam), "Item")
Switch $Select
Case 0
_RClick(1)
Case 1
_RClick(0)
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY
Func _RClick($Flags)
$hMenu = _GUICtrlMenu_CreatePopup(2)
_GUICtrlMenu_AddMenuItem($hMenu, $ConTextMenu[$Flags], 1000)
_GUICtrlMenu_AddMenuItem($hMenu, $ConTextMenu[$Flags], 1001)
$mItem = _GUICtrlMenu_TrackPopupMenu($hMenu, GUICtrlGetHandle($ListView1), -1, -1, 1, 1, 2)
_GUICtrlMenu_DestroyMenu($hMenu)
Switch $Flags
Case 0
If $mItem>0 Then MsgBox(0, '', $ConTextMenu[$Flags][$mItem-1000])
Case 1
If $mItem>0 Then MsgBox(0, '', $ConTextMenu[$Flags][$mItem-1000])
EndSwitch
;~ $Select = -1
EndFunc ;==>_RClick
谢谢楼上!
页:
[1]