powerofos Posted April 8 Share Posted April 8 Hi, Everyone, i have a muliple column listview, How to get the right click position for multiple column items ? Thank you! expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> Local $hGUI = GUICreate("How to obtain the right mouse click position for multiple column items",1000,600) Local $OK = GUICtrlCreateButton("OK", 10, 10, 85, 25) Local $ListView = GUICtrlCreateListView("",10,50,978,500) Local $hListView = GUICtrlGetHandle($ListView) For $i = 0 To 19 _GUICtrlListView_AddColumn($ListView,$i,80) Next Local $2DArray[100][20] For $i = 0 To 19 For $t = 0 To 99 $2DArray[$t][$i] = "R"&$t&" - "&"C"&$i Next Next _GUICtrlListView_AddArray($ListView,$2DArray) Local $header = _GUICtrlListView_GetHeader($ListView) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg(0x004E,"WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $OK Exit EndSwitch WEnd Func WM_NOTIFY($hWnd,$Msg,$wParam,$lParam) Local $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$lParam);$tagNMHDR Local $hWndFrom = HWnd(DllStructGetData($tNMHDR,"hWndFrom")) Local $Code = DllStructGetData($tNMHDR,"Code") Switch $hWndFrom Case $header Switch $Code Case -5;$NM_RCLICK ;Local $cID = DllStructGetData(DllStructCreate($tagNMHEADER,$lParam),"Item") Local $mPos = _WinAPI_GetMousePos(True,$hListView) Local $hID = _GUICtrlHeader_HitTest($header,DllStructGetData($mPos,"X"),DllStructGetData($mPos,"Y")) If $hID[0] = -1 Then Return MsgBox(0,"","Header RightClick:"&$hID[0]) Case $HDN_ITEMCLICK,$HDN_ITEMCLICKW Local $cID = DllStructGetData(DllStructCreate($tagNMHEADER,$lParam),"Item") MsgBox(0,"","Header LeftClick:"&$cID) EndSwitch EndSwitch EndFunc Link to comment Share on other sites More sharing options...
Andreik Posted April 8 Share Posted April 8 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> Local $hGUI = GUICreate("How to obtain the right mouse click position for multiple column items",1000,600) Local $OK = GUICtrlCreateButton("OK", 10, 10, 85, 25) Local $ListView = GUICtrlCreateListView("",10,50,978,500) Local $hListView = GUICtrlGetHandle($ListView) For $i = 0 To 19 _GUICtrlListView_AddColumn($ListView,$i,80) Next Local $2DArray[100][20] For $i = 0 To 19 For $t = 0 To 99 $2DArray[$t][$i] = "R"&$t&" - "&"C"&$i Next Next _GUICtrlListView_AddArray($ListView,$2DArray) Local $header = _GUICtrlListView_GetHeader($ListView) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg(0x007B, 'WM_CONTEXTMENU') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $OK Exit EndSwitch WEnd Func WM_CONTEXTMENU($hWnd,$Msg,$wParam,$lParam) If $wParam = $hListView Then Local $tPoint = _WinAPI_GetMousePos(True, $hListView) Local $aLVItem =_GUICtrlListView_SubItemHitTest($hListView, $tPoint.X, $tPoint.Y) Local $aHItem = _GUICtrlHeader_HitTest($header, $tPoint.X, $tPoint.Y) If $aHItem[0] <> -1 Then ConsoleWrite('Clicked on header: ' & $aLVItem[1] & @CRLF) EndIf EndFunc Or you can use the info already existent in lParam: Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg If $wParam = $hListView Then Local $tPoint = DllStructCreate('long X;long Y;') $tPoint.X = _WinAPI_LoWord($lParam) $tPoint.Y = _WinAPI_HiWord($lParam) _WinAPI_ScreenToClient($hListView, $tPoint) Local $aLVItem =_GUICtrlListView_SubItemHitTest($hListView, $tPoint.X, $tPoint.Y) Local $aHItem = _GUICtrlHeader_HitTest($header, $tPoint.X, $tPoint.Y) If $aHItem[0] <> -1 Then ConsoleWrite('Clicked on header: ' & $aLVItem[1] & @CRLF) EndIf EndFunc Edited April 8 by Andreik powerofos and Zedna 1 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
powerofos Posted April 8 Author Share Posted April 8 8 hours ago, Andreik said: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> Local $hGUI = GUICreate("How to obtain the right mouse click position for multiple column items",1000,600) Local $OK = GUICtrlCreateButton("OK", 10, 10, 85, 25) Local $ListView = GUICtrlCreateListView("",10,50,978,500) Local $hListView = GUICtrlGetHandle($ListView) For $i = 0 To 19 _GUICtrlListView_AddColumn($ListView,$i,80) Next Local $2DArray[100][20] For $i = 0 To 19 For $t = 0 To 99 $2DArray[$t][$i] = "R"&$t&" - "&"C"&$i Next Next _GUICtrlListView_AddArray($ListView,$2DArray) Local $header = _GUICtrlListView_GetHeader($ListView) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg(0x007B, 'WM_CONTEXTMENU') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $OK Exit EndSwitch WEnd Func WM_CONTEXTMENU($hWnd,$Msg,$wParam,$lParam) If $wParam = $hListView Then Local $tPoint = _WinAPI_GetMousePos(True, $hListView) Local $aLVItem =_GUICtrlListView_SubItemHitTest($hListView, $tPoint.X, $tPoint.Y) Local $aHItem = _GUICtrlHeader_HitTest($header, $tPoint.X, $tPoint.Y) If $aHItem[0] <> -1 Then ConsoleWrite('Clicked on header: ' & $aLVItem[1] & @CRLF) EndIf EndFunc Or you can use the info already existent in lParam: Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg If $wParam = $hListView Then Local $tPoint = DllStructCreate('long X;long Y;') $tPoint.X = _WinAPI_LoWord($lParam) $tPoint.Y = _WinAPI_HiWord($lParam) _WinAPI_ScreenToClient($hListView, $tPoint) Local $aLVItem =_GUICtrlListView_SubItemHitTest($hListView, $tPoint.X, $tPoint.Y) Local $aHItem = _GUICtrlHeader_HitTest($header, $tPoint.X, $tPoint.Y) If $aHItem[0] <> -1 Then ConsoleWrite('Clicked on header: ' & $aLVItem[1] & @CRLF) EndIf EndFunc Thank you Andreik ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now