idbirch Posted March 11, 2009 Posted March 11, 2009 I've got a listbox in my GUI and I want to allow multiple select, just like the $LBS_MULTIPLESEL style does but only when the CTRL key is held down. I've played with _IsPressed() but polling this contantly causes flicker. I've looked at HotKeySet but can't see a way of knowing when the Ctrl key has been released again. Is there an easy way to accomplish this which I'm missing? At the moment, it's looking like I may have to add a checkbox to enable and disable muliple select but that just seems....lame.
Zedna Posted March 11, 2009 Posted March 11, 2009 Post your code with _IsPressed() and I will remove flickering for you. Resources UDF ResourcesEx UDF AutoIt Forum Search
Zedna Posted March 11, 2009 Posted March 11, 2009 (edited) Princip of antiflickering: Global $ctrl = False Global $ctrl_prev = False While 1 $ctrl = _IsPressed('11') = 1 ; Ctrl If $ctrl <> $ctrl_prev Then $ctrl_prev = $ctrl If $ctrl Then ; enable ; ... Else ; disable ; ... EndIf EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case ... EndSwitch WEnd Edited March 11, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
idbirch Posted March 11, 2009 Author Posted March 11, 2009 (edited) Thanks for the help Zedna, your example script has solved the flickering issue. The only remaining problem is I can't get the toggle of multi-select to work. Here's an example script: expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <Misc.au3> #Include <GuiTab.au3> Global $CTRLisPressed = False Global $CTRLisPressed_prev = False #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 283, 289, 192, 124) $List1 = GUICtrlCreateList("", 16, 40, 241, 214) GUICtrlCreateLabel("List of stuff:", 16, 16, 58, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData ( $List1, "Item 1" ) GUICtrlSetData ( $List1, "Item 2" ) GUICtrlSetData ( $List1, "Item 3" ) While 1 $CTRLisPressed = _IsPressed('11') = 1; Ctrl If $CTRLisPressed <> $CTRLisPressed_prev Then $CTRLisPressed_prev = $CTRLisPressed If $CTRLisPressed Then $Change = GUICtrlSetStyle ( $List1, $LBS_MULTIPLESEL ) ConsoleWrite ( "Ctrl is held. SetStyle result = " & $Change & @CRLF ) Else $Change = GUICtrlSetStyle ( $List1, BitOr ($LBS_SORT, $WS_BORDER, $WS_VSCROLL)) ConsoleWrite ( "Ctrl is released. SetStyle result = " & $Change & @CRLF ) EndIf EndIf $nMsgMainGUI = GUIGetMsg(1) Select Case $nMsgMainGUI[0] = $GUI_EVENT_CLOSE and $nMsgMainGUI[1] = $Form1 Exit EndSelect WEnd Edited March 11, 2009 by idbirch
Zedna Posted March 11, 2009 Posted March 11, 2009 (edited) From helpfile: GUICtrlSetStyle() Remarks Some styles cannot be changed dynamically, check MSDN documentation. $CBS_UPPERCASE combo style is one example. It seems you can't change LBS_MULTIPLESEL dynamically. This works OK: $List1 = GUICtrlCreateList("", 16, 40, 241, 214, BitOr($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL)) This doesn't work: $List1 = GUICtrlCreateList("", 16, 40, 241, 214) GUICtrlSetStyle ( $List1, BitOr($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL)) Edited March 11, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
idbirch Posted March 11, 2009 Author Posted March 11, 2009 Hm, yes I did note that caveat in the help file but found nothing on MSDN to suggest that it couldn't be changed on the fly, damn. I'm not in the office with my code now but would destroying the listbox (backing up its contents first of course) and then recreating it with that style work? Or is that a stupid idea? Does anyone have any other suggestions as to how this could be achieved?
Zedna Posted March 11, 2009 Posted March 11, 2009 I'm not sure about my theory. I just did some quick tests. So try to search on the forum to see if somebody did something similar. Resources UDF ResourcesEx UDF AutoIt Forum Search
Authenticity Posted March 11, 2009 Posted March 11, 2009 If you're satisfied with shift also, you can use $LBS_EXTENDEDSEL.
idbirch Posted March 12, 2009 Author Posted March 12, 2009 Thanks Authenticity, another case of the 'GUI Control Styles' section of the help file not being updated with the newer styles available with the _GUICtrl* family. Anyway, yes, this seems like the best alternative for now. And thanks again Zedna, I'm sure I'll find another use for that IsPressed() trick.
idbirch Posted March 12, 2009 Author Posted March 12, 2009 Hang on a sec! I've just tried out $LBS_EXTENDEDSEL and holding shift highlights everything in between the 2 items you click and CTRL lets you select multiple, non-adjacent items! Brilliant!
Authenticity Posted March 12, 2009 Posted March 12, 2009 Are you using $LBS_MULTIPLESEL also? I didn't use it because it's not required in this case.
idbirch Posted March 12, 2009 Author Posted March 12, 2009 No, just $LBS_EXTENDEDSEL which is doing exactly what I originally asked for - thanks.
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