Jump to content

WM_Notify with Multiple ListViews


Recommended Posts

Title says it all. I have a GUI that has 3 separate ListView controls in it and I want to use WM_Notify to see when one is double click and where at. I figured out how to make it work with a single Listview but is there a way to make this work with multiples?

Example:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Purple Sheets", 376, 550, -1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$ListViewExp = GUICtrlCreateListView("", 8, 16, 106, 382, $LVS_SHOWSELALWAYS)
$ListViewLind = GUICtrlCreateListView("", 130, 16, 106, 382, $LVS_SHOWSELALWAYS)
$ListViewScott = GUICtrlCreateListView("", 256, 16, 106, 382, $LVS_SHOWSELALWAYS)

_GUICtrlListView_AddColumn($ListViewExp, "Expected", 85)
_GUICtrlListView_AddColumn($ListViewLind, "Lindsey", 85)
_GUICtrlListView_AddColumn($ListViewScott, "Scott", 85)
_GUICtrlListView_AddItem($ListViewExp, "testing1", 0)
_GUICtrlListView_AddItem($ListViewLind, "testing2", 0)
_GUICtrlListView_AddItem($ListViewScott, "testing3", 0)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListViewExp)]
GUISetState(@SW_SHOW)
While 1
Sleep (100)
Wend
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $ListViewExp
If Not IsHWnd($ListViewExp) Then $hWndListView = GUICtrlGetHandle($ListViewExp)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
  Case $hWndListView
   Switch $iCode
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
;~    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
;~      "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
;~      "-->Code:" & @TAB & $iCode & @LF & _
;~      "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
;~      "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
;~      "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
;~      "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
;~      "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
;~      "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
;~      "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
;~      "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
;~      "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
     $text = _GUICtrlListView_GetItemText ($ListViewExp, DllStructGetData($tInfo, "Index"))
     MsgBox (0, "you clicked on", $text)
     ; No return value
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _Exit ()
Exit
Endfunc

Thank you in advance for any help provided!

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Never mind...its been a long day and I figured it out. Solution:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Purple Sheets", 376, 550, -1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$ListViewExp = GUICtrlCreateListView("", 8, 16, 106, 382, $LVS_SHOWSELALWAYS)
$ListViewLind = GUICtrlCreateListView("", 130, 16, 106, 382, $LVS_SHOWSELALWAYS)
$ListViewScott = GUICtrlCreateListView("", 256, 16, 106, 382, $LVS_SHOWSELALWAYS)
_GUICtrlListView_AddColumn($ListViewExp, "Expected", 85)
_GUICtrlListView_AddColumn($ListViewLind, "Lindsey", 85)
_GUICtrlListView_AddColumn($ListViewScott, "Scott", 85)
_GUICtrlListView_AddItem($ListViewExp, "testing1", 0)
_GUICtrlListView_AddItem($ListViewLind, "testing2", 0)
_GUICtrlListView_AddItem($ListViewScott, "testing3", 0)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;~ Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListViewExp)]
GUISetState(@SW_SHOW)
While 1
Sleep (100)
Wend
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView1 = GUICtrlGetHandle($ListViewExp)
$hWndListView2 = GUICtrlGetHandle($ListViewLind)
$hWndListView3 = GUICtrlGetHandle($ListViewScott)
;~  If Not IsHWnd($ListViewExp) Then $hWndListView = GUICtrlGetHandle($ListViewExp)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
  Case $hWndListView1
   Switch $iCode
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     $text = _GUICtrlListView_GetItemText ($ListViewExp, DllStructGetData($tInfo, "Index"))
     MsgBox (0, "you clicked on", $text)
   EndSwitch
  Case $hWndListView2
   Switch $iCode
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     $text = _GUICtrlListView_GetItemText ($ListViewLind, DllStructGetData($tInfo, "Index"))
     MsgBox (0, "you clicked on", $text)
   EndSwitch
  Case $hWndListView3
   Switch $iCode
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
     $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     $text = _GUICtrlListView_GetItemText ($ListViewScott, DllStructGetData($tInfo, "Index"))
     MsgBox (0, "you clicked on", $text)
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _Exit ()
Exit
EndFunc

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

  • 9 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...