Whats a better way to get which column was double-clicked in a gui listview? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
garry
Posts: 2458
Joined: 22 Dec 2013, 12:50

Re: Whats a better way to get which column was double-clicked in a gui listview?  Topic is solved

18 Sep 2019, 14:45

script from user 'just me'
https://autohotkey.com/board/topic/80265-solved-which-column-is-clicked-in-listview/

Code: Select all

;-------- saved at Mittwoch, 18. September 2019 21:42:50 --------------
;;-------- https://autohotkey.com/board/topic/80265-solved-which-column-is-clicked-in-listview/ ---
#NoEnv
Gui, Margin, 20, 20
Gui, Add, ListView, w400 r9 Grid HwndHLV1 gSubLV AltSubmit, Column 1|Column 2|Column 3
Loop, 9
   LV_Add("", A_Index, A_Index, A_Index)
Loop, 3
   LV_ModifyCol(A_Index, "AutoHdr")
Gui, Show, , ListView
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiCLose:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
SubLV:
   If (A_GuiEvent = "Normal") {
      Row := A_EventInfo
      Column := LV_SubItemHitTest(HLV1)
      ToolTip, You clicked on column %Column% in row %Row%!
      SetTimer, KillToolTip, -1500
   }
Return
; ----------------------------------------------------------------------------------------------------------------------
KillToolTip:
   ToolTip
Return
; ----------------------------------------------------------------------------------------------------------------------
LV_SubitemHitTest(HLV) {
   ; To run this with AHK_Basic change all DllCall types "Ptr" to "UInt", please.
   ; HLV - ListView's HWND
   Static LVM_SUBITEMHITTEST := 0x1039
   VarSetCapacity(POINT, 8, 0)
   ; Get the current cursor position in screen coordinates
   DllCall("User32.dll\GetCursorPos", "Ptr", &POINT)
   ; Convert them to client coordinates related to the ListView
   DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT)
   ; Create a LVHITTESTINFO structure (see below)
   VarSetCapacity(LVHITTESTINFO, 24, 0)
   ; Store the relative mouse coordinates
   NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int")
   NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int")
   ; Send a LVM_SUBITEMHITTEST to the ListView
   SendMessage, LVM_SUBITEMHITTEST, 0, &LVHITTESTINFO, , ahk_id %HLV%
   ; If no item was found on this position, the return value is -1
   If (ErrorLevel = -1)
      Return 0
   ; Get the corresponding subitem (column)
   Subitem := NumGet(LVHITTESTINFO, 16, "Int") + 1
   Return Subitem
}
/*
typedef struct _LVHITTESTINFO {
  POINT pt;
  UINT  flags;
  int   iItem;
  int   iSubItem;
  int   iGroup;
} LVHITTESTINFO, *LPLVHITTESTINFO;
*/
teadrinker
Posts: 1900
Joined: 29 Mar 2015, 09:41
Contact:

Re: Whats a better way to get which column was double-clicked in a gui listview?

18 Sep 2019, 15:20

Code: Select all

Gui, Add, ListView, Grid r5, Col 1|Col 2|Col 3|Col 4
Loop 5
   LV_Add()
Gui, Show
OnMessage(0x4E, "WM_NOTIFY")
Return

GuiClose:
   ExitApp

WM_NOTIFY(wp, lp) {
   static NM_DBLCLK := -3
   if NumGet(lp + A_PtrSize*2, "Int") = NM_DBLCLK
      ToolTip % NumGet(lp + A_PtrSize*3 + 4, "Int") + 1
}
teadrinker
Posts: 1900
Joined: 29 Mar 2015, 09:41
Contact:

Re: Whats a better way to get which column was double-clicked in a gui listview?

19 Sep 2019, 11:27

@garry

Code: Select all

Gui, Add, ListView, Grid r5, Col 1|Col 2|Col 3|Col 4
Loop 5
   LV_Add()
Gui, Show
OnMessage(0x4E, "WM_NOTIFY")
Return

GuiClose:
   ExitApp

WM_NOTIFY(wp, lp) {
   static notices := {-2: "NM_CLICK", -3: "NM_DBLCLK"}
   notice := NumGet(lp + A_PtrSize*2, "Int")
   if (notice = -2 || notice = -3)
      ToolTip % "Action: " . notices[notice]                         . "`n"
              . "Row: "    . NumGet(lp + A_PtrSize*3,     "Int") + 1 . "`n"
              . "Column: " . NumGet(lp + A_PtrSize*3 + 4, "Int") + 1
}
:wave:
garry
Posts: 2458
Joined: 22 Dec 2013, 12:50

Re: Whats a better way to get which column was double-clicked in a gui listview?

19 Sep 2019, 14:53

@teadrinker, thank again, now see info : click/doubleclick , row , column

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, aifritz, Bing [Bot], bracht, c7aesa7r, mikeyww and 45 guests