RAMzor Posted August 12, 2020 Posted August 12, 2020 (edited) Hello all, I am trying to get scrolling events for ListBox (mouse wheel and up/down arrows) but without success. The event not occured on row change but if I click on it - yes The ComboBox works fine even if not in focus (with mouse wheel) but I prefer visual look of ListBox. In addition to all, I can't change the height of control. Unfortunately it depends only on font size and same fonts has different heights between InputBox and ComboBox Is there a way to get over the issue? Any other ideas for unit selection realization are welcome expandcollapse popup#include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $idCombo, $idComboUnit, $idList, $idListUnit Global $sComboInitUnit = "pJ", $fComboVal = 7.5 Global $sListInitUnit = "nF", $fListVal = 0.15 Units_Conversion_Example() Func Units_Conversion_Example() ; Create GUI GUICreate("Units Conversion", 400, 296) $idCombo = GUICtrlCreateInput($fComboVal, 22, 20, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idComboUnit = GUICtrlCreateCombo("", 112, 20, 50, 30) GUICtrlSetData(-1, "uJ|nJ|pJ", $sComboInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idList = GUICtrlCreateInput($fListVal, 22, 80, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idListUnit = GUICtrlCreateList("", 112, 80, 57, 26, BitOR($LBS_NOTIFY,$LBS_NOSEL,$WS_VSCROLL)) GUICtrlSetData(-1, "uF|nF|pF", $sListInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Do Sleep(5) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndListBox If Not IsHWnd($idComboUnit) Then $hWndCombo = GUICtrlGetHandle($idComboUnit) If Not IsHWnd($idListUnit) Then $hWndListBox = GUICtrlGetHandle($idListUnit) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndCombo Switch $iCode Case $LBN_SELCHANGE ConsoleWrite(GUICtrlRead($idComboUnit) & @CRLF) EndSwitch Case $hWndListBox Switch $iCode Case $CBN_SELCHANGE ConsoleWrite(GUICtrlRead($idListUnit) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Edited August 12, 2020 by RAMzor
Zedna Posted August 12, 2020 Posted August 12, 2020 (edited) Just idea/concept, not working ... expandcollapse popup#include <GuiListBox.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global Const $WM_MOUSEWHEEL = 0x020A ; needed only for older AutoIt's versions Global $idCombo, $idComboUnit, $idList, $idListUnit Global $sComboInitUnit = "pJ", $fComboVal = 7.5 Global $sListInitUnit = "nF", $fListVal = 0.15 Global $hWndCombo, $hWndListBox Units_Conversion_Example() Func Units_Conversion_Example() ; Create GUI GUICreate("Units Conversion", 400, 296) $idCombo = GUICtrlCreateInput($fComboVal, 22, 20, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idComboUnit = GUICtrlCreateCombo("", 112, 20, 50, 30) $hWndCombo = GUICtrlGetHandle($idComboUnit) GUICtrlSetData(-1, "uJ|nJ|pJ", $sComboInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idList = GUICtrlCreateInput($fListVal, 22, 80, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idListUnit = GUICtrlCreateList("", 112, 80, 57, 26, BitOR($LBS_NOTIFY,$LBS_NOSEL,$WS_VSCROLL)) $hWndListBox = GUICtrlGetHandle($idListUnit) GUICtrlSetData(-1, "uF|nF|pF", $sListInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") Do Sleep(5) Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndCombo Switch $iCode Case $LBN_SELCHANGE ConsoleWrite('LBN_SELCHANGE1 ' & GUICtrlRead($idComboUnit) & @CRLF) EndSwitch Case $hWndListBox Switch $iCode Case $LBN_SELCHANGE ConsoleWrite('LBN_SELCHANGE2 ' & GUICtrlRead($idListUnit) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) If $hWnd <> $hWndListBox Then Return $i = _GUICtrlListBox_GetTopIndex($idListUnit) ; first visible item _GUICtrlListBox_SetSel($idListUnit, $i) EndFunc Edited August 12, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
argumentum Posted August 12, 2020 Posted August 12, 2020 1 hour ago, RAMzor said: I am trying to get scrolling events for ListBox ..not that I can code it but, to what purpose is the scrolling position needed ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Nine Posted August 12, 2020 Posted August 12, 2020 That seems to work quite well : expandcollapse popup#include <GuiListBox.au3> #include <WinAPI.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $idCombo, $idComboUnit, $idList, $idListUnit Global $sComboInitUnit = "pJ", $fComboVal = 7.5 Global $sListInitUnit = "nF", $fListVal = 0.15 Units_Conversion_Example() Func Units_Conversion_Example() ; Create GUI Global $hGUI = GUICreate("Units Conversion", 400, 296) $idCombo = GUICtrlCreateInput($fComboVal, 22, 20, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idComboUnit = GUICtrlCreateCombo("", 112, 20, 50, 30) GUICtrlSetData(-1, "uJ|nJ|pJ", $sComboInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idList = GUICtrlCreateInput($fListVal, 22, 80, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idListUnit = GUICtrlCreateList("", 112, 80, 57, 26, BitOR($LBS_NOTIFY, $LBS_NOSEL, $WS_VSCROLL)) GUICtrlSetData(-1, "uF|nF|pF", $sListInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") Global $hCtrl = GUICtrlGetHandle($idListUnit) Global $iDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Local $hProc = DllCallbackRegister(WM_LIST_BOX, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") Local $hProcPtr = DllCallbackGetPtr($hProc) DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hCtrl, "ptr", $hProcPtr, "uint_ptr", 0xBEEF, "dword_ptr", 0) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iDummy ;ControlFocus ($hGUI, "", $hCtrl) ControlClick($hGUI, "", $idListUnit) EndSwitch WEnd GUIDelete() DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hCtrl, "ptr", $hProcPtr, "uint_ptr", $WM_VSCROLL) DllCallbackFree($hProc) EndFunc ;==>Units_Conversion_Example Func WM_LIST_BOX($hWnd, $iMsg, $wParam, $lParam, $uIdSubClass, $IRefData) #forceref $hWnd, $iMsg, $wParam, $lParam, $uIdSubClass, $IRefData Local $iDirection Switch $iMsg Case $WM_VSCROLL $iDirection = _WinAPI_LoWord ($wParam) If $iDirection = 0 Or $iDirection = 1 Then GUICtrlSendToDummy ($iDummy) Case $WM_MOUSEWHEEL $iDirection = _WinAPI_HiWord ($wParam) GUICtrlSendToDummy ($iDummy) EndSwitch Return DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0] EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndListBox If Not IsHWnd($idComboUnit) Then $hWndCombo = GUICtrlGetHandle($idComboUnit) If Not IsHWnd($idListUnit) Then $hWndListBox = GUICtrlGetHandle($idListUnit) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndCombo Switch $iCode Case $CBN_SELCHANGE ConsoleWrite(GUICtrlRead($idComboUnit) & @CRLF) EndSwitch Case $hWndListBox Switch $iCode Case $LBN_SELCHANGE ConsoleWrite(GUICtrlRead($idListUnit) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND RAMzor and Zedna 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
RAMzor Posted August 12, 2020 Author Posted August 12, 2020 2 hours ago, argumentum said: ..not that I can code it but, to what purpose is the scrolling position needed ? The issue that the value in ListBox can be changed without control is focused - only mouse pointer hovers over a ListBox and mouse wheel will change the value. Even arrows up and down not really change a value (only move it). This is very useful option but very "danger" because the value visually changed without really be accepted. Hope I made my self clear because my English is lame 🤪 @Zedna Thanks a lot but it still not worked as you said... argumentum 1
RAMzor Posted August 12, 2020 Author Posted August 12, 2020 (edited) 1 hour ago, Nine said: That seems to work quite well : expandcollapse popup#include <GuiListBox.au3> #include <WinAPI.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $idCombo, $idComboUnit, $idList, $idListUnit Global $sComboInitUnit = "pJ", $fComboVal = 7.5 Global $sListInitUnit = "nF", $fListVal = 0.15 Units_Conversion_Example() Func Units_Conversion_Example() ; Create GUI Global $hGUI = GUICreate("Units Conversion", 400, 296) $idCombo = GUICtrlCreateInput($fComboVal, 22, 20, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idComboUnit = GUICtrlCreateCombo("", 112, 20, 50, 30) GUICtrlSetData(-1, "uJ|nJ|pJ", $sComboInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idList = GUICtrlCreateInput($fListVal, 22, 80, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idListUnit = GUICtrlCreateList("", 112, 80, 57, 26, BitOR($LBS_NOTIFY, $LBS_NOSEL, $WS_VSCROLL)) GUICtrlSetData(-1, "uF|nF|pF", $sListInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") Global $hCtrl = GUICtrlGetHandle($idListUnit) Global $iDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Local $hProc = DllCallbackRegister(WM_LIST_BOX, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") Local $hProcPtr = DllCallbackGetPtr($hProc) DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hCtrl, "ptr", $hProcPtr, "uint_ptr", 0xBEEF, "dword_ptr", 0) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iDummy ;ControlFocus ($hGUI, "", $hCtrl) ControlClick($hGUI, "", $idListUnit) EndSwitch WEnd GUIDelete() DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hCtrl, "ptr", $hProcPtr, "uint_ptr", $WM_VSCROLL) DllCallbackFree($hProc) EndFunc ;==>Units_Conversion_Example Func WM_LIST_BOX($hWnd, $iMsg, $wParam, $lParam, $uIdSubClass, $IRefData) #forceref $hWnd, $iMsg, $wParam, $lParam, $uIdSubClass, $IRefData Local $iDirection Switch $iMsg Case $WM_VSCROLL $iDirection = _WinAPI_LoWord ($wParam) If $iDirection = 0 Or $iDirection = 1 Then GUICtrlSendToDummy ($iDummy) Case $WM_MOUSEWHEEL $iDirection = _WinAPI_HiWord ($wParam) GUICtrlSendToDummy ($iDummy) EndSwitch Return DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0] EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndListBox If Not IsHWnd($idComboUnit) Then $hWndCombo = GUICtrlGetHandle($idComboUnit) If Not IsHWnd($idListUnit) Then $hWndListBox = GUICtrlGetHandle($idListUnit) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndCombo Switch $iCode Case $CBN_SELCHANGE ConsoleWrite(GUICtrlRead($idComboUnit) & @CRLF) EndSwitch Case $hWndListBox Switch $iCode Case $LBN_SELCHANGE ConsoleWrite(GUICtrlRead($idListUnit) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Wow! Thanks a lot, it really works! Is this normal behavior? So many code for so simple thing 😬 Edited August 12, 2020 by RAMzor
Zedna Posted August 12, 2020 Posted August 12, 2020 If you want nonstandard functionality then you have to be ready for much more complicated code ... Resources UDF ResourcesEx UDF AutoIt Forum Search
Nine Posted August 12, 2020 Posted August 12, 2020 It is not such a big deal, it is, after all, only a few additional lines of code to get the functionality you wanted. The hard part is to find the right API to perform the task properly. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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