MyEarth Posted March 21, 2017 Share Posted March 21, 2017 (edited) Hello, I need to know when user manually drag the box of a vertical-horizontal scroll of a listview, specifically when end to drag the box with the right click of the mouse. I have try to catch the WM_VSCROLL but nothing, the two events $LVN_BEGINSCROLL and $LVN_ENDSCROLL keep firing continuously...what i'm miss? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $iFire = 0 $Form1 = GUICreate("Form1", 374, 217, 219, 155) $ListView = GUICtrlCreateListView("A", 8, 8, 354, 206) $hListView = GUICtrlGetHandle($ListView) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) For $i = 0 To 100 GUICtrlCreateListViewItem("a", $ListView) Next GUISetState(@SW_SHOW) GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_VSCROLL" & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_EXITSIZEMOVE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_BEGINSCROLL $iFire += 1 ConsoleWrite("LVN_BEGINSCROLL " & $iFire & @CRLF) Case $LVN_ENDSCROLL $iFire += 1 ConsoleWrite("LVN_ENDSCROLL " & $iFire & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited March 21, 2017 by MyEarth Link to comment Share on other sites More sharing options...
LarsJ Posted March 22, 2017 Share Posted March 22, 2017 GUIRegisterMsg is able to catch messages which are send to the GUI. The scrollbars are child windows of the listview. WM_VSCROLL messages are always send to the parent window. In this case the listview. The GUI will never receive the messages and GUIRegisterMsg cannot catch them. You can catch the messages by subclassing the listview: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <WinAPIShellEx.au3> Global $iFire = 0 $Form1 = GUICreate("Form1", 374, 217, 219, 155) $ListView = GUICtrlCreateListView("A", 8, 8, 354, 206) $hListView = GUICtrlGetHandle($ListView) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) For $i = 0 To 100 GUICtrlCreateListViewItem("a", $ListView) Next GUISetState(@SW_SHOW) GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $pListViewCallback = DllCallbackGetPtr( DllCallbackRegister( "ListViewCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) _WinAPI_SetWindowSubclass( $hListView, $pListViewCallback, 9999, 0 ) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd _WinAPI_RemoveWindowSubclass( $hListView, $pListViewCallback, 9999 ) Func ListViewCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData ) Switch $iMsg Case $WM_VSCROLL ConsoleWrite("ListViewCallback WM_VSCROLL" & @CRLF) EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $iSubclassId, $pData EndFunc Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_VSCROLL" & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_EXITSIZEMOVE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_BEGINSCROLL $iFire += 1 ConsoleWrite("LVN_BEGINSCROLL " & $iFire & @CRLF) Case $LVN_ENDSCROLL $iFire += 1 ConsoleWrite("LVN_ENDSCROLL " & $iFire & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY pixelsearch and MyEarth 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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