回复 8# fenhanxue
沒時間測試
你的情況 跟我之前遇到一個類似
重點是 你無法 真正抓到 滑鼠 按下的那個觸發點
下面 可以 可是標題 不可以
標題其實是因為 圖片 卡住了
放在圖片 其他 功能循環時候 又不行
所以 癥結點 在於 抓到滑鼠 按下的瞬間
可能要使用 回CALL 的方法
參考一下 下面的 用法
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>
#include <GuiListView.au3>
Opt( "MustDeclareVars", 1 )
Global $idListView, $idAddSingleSel, $idDelSingleSel
Example()
Func Example()
; Create GUI
GUICreate( "ctrl+single-click --> single-click", 420, 200 )
; Create ListView
$idListView = GUICtrlCreateListView( "", 10, 10, 400, 180, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE )
_GUICtrlListView_SetExtendedListViewStyle( $idListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT )
Local $hListView = GUICtrlGetHandle( $idListView )
; Add columns to ListView
_GUICtrlListView_InsertColumn( $idListView, 0, "Column 1", 94 )
_GUICtrlListView_InsertColumn( $idListView, 1, "Column 2", 94 )
_GUICtrlListView_InsertColumn( $idListView, 2, "Column 3", 94 )
_GUICtrlListView_InsertColumn( $idListView, 3, "Column 4", 94 )
; Fill ListView
Local $iItems = 100
For $i = 0 To $iItems - 1
GUICtrlCreateListViewItem( $i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $idListView )
Next
; Subclass ListView to receive keyboard/mouse messages
Local $pListViewFunc = DllCallbackGetPtr( DllCallbackRegister( "ListViewFunc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hListView, $pListViewFunc, 0, 0 ) ; $iSubclassId = 0, $pData = 0
; Add/del single selection
$idAddSingleSel = GUICtrlCreateDummy()
$idDelSingleSel = GUICtrlCreateDummy()
Local $iItem
; Show GUI
GUISetState( @SW_SHOW )
; Message loop
While 1
Switch GUIGetMsg()
Case $idAddSingleSel
$iItem = GUICtrlRead( $idAddSingleSel )
_GUICtrlListView_SetItemSelected( $idListView, $iItem, True )
_GUICtrlListView_SetItemFocused( $idListView, $iItem )
Case $idDelSingleSel
$iItem = GUICtrlRead( $idDelSingleSel )
_GUICtrlListView_SetItemSelected( $idListView, $iItem, False )
_GUICtrlListView_SetItemFocused( $idListView, $iItem )
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
; Cleanup
_WinAPI_RemoveWindowSubclass( $hListView, $pListViewFunc, 0 )
GUIDelete()
EndFunc
Func ListViewFunc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
If $iMsg <> $WM_LBUTTONDOWN Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
Switch $wParam
Case 0x0001 ; 0x0001 = MK_LBUTTON (LButton down)
If _GUICtrlListView_GetSelectedCount( $idListView ) Then
Local $aHit = _GUICtrlListView_HitTest( GUICtrlGetHandle( $idListView ), BitAND( $lParam, 0xFFFF ), BitShift( $lParam, 16 ) )
If Not ( @error Or $aHit[0] = -1 ) Then
If _GUICtrlListView_GetItemSelected( $idListView, $aHit[0] ) Then
GUICtrlSendToDummy( $idDelSingleSel, $aHit[0] )
Else
GUICtrlSendToDummy( $idAddSingleSel, $aHit[0] )
EndIf
EndIf
Return 0 ; Disable single-click in ListView to prevent resetting selections
EndIf
Case 0x0009 ; 0x0009 = MK_LBUTTON (LButton down) + MK_CONTROL (Ctrl down)
Return 0 ; Disable single selections in ListView with ctrl+single-click
EndSwitch
Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
; Call next function in subclass chain (this forwards messages to main GUI)
#forceref $iSubclassId, $pData
EndFunc
上面範例 要看的是 滑鼠 攔截消息的方法 |