本帖最后由 雪栀 于 2014-8-27 17:49 编辑
回复 22# user3000
试过了,好像不行啊,我从自己写的东西里弄出个稍稍复杂点的例子,你看一下,关键是第29行怎么写,或者说你在20楼的回答中的_WinAPI_SetWindowLong怎么写……对API不是很懂,囧之……
#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
$exit = GUICtrlCreateButton("退出", 216, 180, 67, 25)
;右键菜单
$Menu = GUICtrlCreateContextMenu($treeview)
$rclk = GUICtrlCreateMenuItem("萌萌的菜单", $Menu)
GUISetState(@SW_SHOW, $Manage)
;关键测试代码===========================================================================
$handle = DllCallbackRegister("MouseEvents", "ptr", "hwnd;uint;long;ptr")
$handle2 = _WinAPI_SetWindowLong(GUICtrlGetHandle($Manage), $GWL_WNDPROC, DllCallbackGetPtr($handle)) ;关键是这个地方怎么写。。。
Func MouseEvents($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_LBUTTONUP ;左键按下后松开
Switch _WinAPI_GetDlgCtrlID($hWnd)
Case $exit
Exit
Case $rclk
MsgBox(0,0,"点击了萌萌的菜单!")
EndSwitch
Case $WM_LBUTTONDBLCLK ; 左键双击
Switch _WinAPI_GetDlgCtrlID($hWnd)
Case $treeview
MsgBox(0,0,"双击了treeviewitem!")
EndSwitch
;Case $WM_RBUTTONUP ; 右键按下后松开
;MsgBox(64, "提示", "右击!")
EndSwitch
Return _WinAPI_CallWindowProc($handle2, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>MouseEvents
;关键测试代码===========================================================================
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
playlist.ini[List]
List1=List1
List2=List2
[List1]
1=0001
2=0010
[List2]
3=0011
如果这类烦人的单击、双击、右击控件的问题(……话说这两天一直在找这方面资料)解决了,大家可以整合一下别的什么GUICtrlOnHover之类的,最好能写个UDF,顺便根据p版的说法,这种SetWindowLong的方法好像还能在某些方面模拟一下多线程,多学习学习也是好的 |