将就着看一下吧,仅供参考
#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#NoTrayIcon
Dim $inifile_path = "playlist.ini"
If Not FileExists($inifile_path) Then
FileInstall("playlist.ini", $inifile_path)
EndIf
Dim $csname = "List", $hClass = 0
$Manage = GUICreate("选择", 300, 300, (@DesktopWidth - 215) / 2, (@DesktopHeight - 100) / 2)
$treeview = GUICtrlCreateTreeView(0, 0, 200, 300, -1, $WS_EX_CLIENTEDGE)
readinfo($inifile_path, $treeview) ;加载ini
;右键菜单
$Menu = GUICtrlCreateContextMenu($treeview)
$rclk = GUICtrlCreateMenuItem("萌萌的菜单", $Menu)
;备用按钮
$exit = GUICtrlCreateButton("退出", 216, 180, 67, 25)
GUISetState(@SW_SHOW, $Manage)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
Local $msg = GUIGetMsg()
Select
Case $msg = -3
Exit
EndSelect
WEnd
Func readinfo($ini, $htv, $csname = "List", $hClass = 0) ;加载ini
If Not $hClass Then $hClass = $htv
$aSec = IniReadSection($ini, $csname)
If @error Then Return False
For $i = 1 To $aSec[0][0]
$child = IniReadSection($ini, $aSec[$i][0])
If @error Then;类
$hItem = GUICtrlCreateTreeViewItem($aSec[$i][0], $hClass)
Else;子类
$hClass1 = GUICtrlCreateTreeViewItem($aSec[$i][0], $hClass)
readinfo($ini, $hClass, $aSec[$i][0], $hClass1)
EndIf
Next
Return True
EndFunc ;==>readinfo
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam) ;注册消息,待修改
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
$tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
ConsoleWrite($IDFrom & @CRLF)
Switch $IDFrom ;选择产生事件的控件
Case $treeview
Switch $Event ;选择产生的事件
Case $NM_CLICK ; 左击
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlTreeView_GetSelection($treeview)
If Not $Index Then Return; 这里用以判断是否选定了TreeViewItem
MsgBox(0, 0, "双击了" & GUICtrlRead($treeview, 1))
Case $NM_RCLICK ; 右击
;MsgBox(0,"","右击!") ;调试
EndSwitch
Case $rclk
Switch $Event ;选择产生的事件
Case $NM_CLICK ; 左击
MsgBox(0, 0, "菜单:" & GUICtrlRead($treeview, 1))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $Msg
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
Local $hCtrl = $lParam
Switch $nID
Case $exit
Switch $nNotifyCode
Case 0
Exit
EndSwitch
Case $rclk
Switch $nNotifyCode
Case 0
MsgBox(0, "", "不要点我!")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
|