Popular Post LarsJ Posted August 19, 2018 Popular Post Share Posted August 19, 2018 (edited) I've been testing the subclassing technique in recent months and have used ComboBox examples for tests. Here is one of the examples. More examples will be added over the coming weeks. All examples are small and simple. However, all of them are based on the subclassing technique. It's the interesting aspect of the examples. Some are implemented with complete UDFs. Others are made as code examples only. First post becomes a list of examples as well as the first example. ComboBox Examples Color Combo (just below) Checkbox Combo Checkbox Combo slightly modified ListView Combo Other Control Examples Tabs and subtabs on demand My first script in the Examples forum. Well. You have to start somewhere. Windows Explorer address bar Colors and fonts in TreeViews Implementing Virtual TreeViews Hot-Track Enabled Toolbar Menu Simulating a modeless Choose Color Dialog Color Combo The first example is about color selection. It's an owner drawn ComboBox created with the $CBS_OWNERDRAWVARIABLE style so that colors can be displayed directly in the ComboBox by responding to $WM_DRAWITEM messages. There are already many of these examples, but none are implemented through the subclassing technique. The big advantage of subclassing is that a user of the UDF still can use his own $WM_DRAWITEM message handler through GUIRegisterMsg. The same Windows message can be used in both techniques without any conflicts. This is an example with a single ComboBox: expandcollapse popup#include <GUIConstantsEx.au3> #include "..\Includes\ComboColors.au3" Example() Func Example() ; Create GUI GUICreate( "1 ComboBox", 220, 264 ) ; Create ComboBox for color selection GUICtrlCreateLabel( "Named colors:", 10, 10, 200, 16 ) Local $aInfo = ComboColors_Create( "Tomato", 10, 26, 200, 26, 10, "Colors\NamedColors.txt", 9 ) ; $aInfo = [ $idComboBox, $aColors, $oColors, $sColors, $iColors ] ; $aColors = [ "Color name", 0xBackColor, 0xTextColor, 0xBrush ] ; $oColors dict obj: Key = "Color name", Val = index in $aColors ; $sColors = "Color0|Color1|Color2|..." ; $iColors = Number of colors ; Show GUI GUISetState() ; Message loop While 1 Switch GUIGetMsg() Case $aInfo[0] Local $sColor = GUICtrlRead( $aInfo[0] ) Local $iIndex = $aInfo[2]($sColor) ConsoleWrite( "Color = " & $sColor & @CRLF & _ "Index = " & $iIndex & @CRLF & _ "Back = 0x" & Hex( ($aInfo[1])[$iIndex][1], 6 ) & @CRLF & _ "Fore = 0x" & Hex( ($aInfo[1])[$iIndex][2], 6 ) & @CRLF & _ "Brush = " & ($aInfo[1])[$iIndex][3] & @CRLF & @CRLF ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc Two different sources can be used to specify colors: An array and a text file. It's demonstrated in examples. ComboColors_Create() is defined this way: ; Create ComboBox for color selection ; ; Error code in @error Return value ; 1 => Invalid color info file/array Success => [ $idComboBox, $aColors, $oColors, $sColors, $iColors ] ; 2 => Error creating ComboBox Failure => 0 ; 3 => Too many ComboBoxes ; Func ComboColors_Create( _ $sColorInit, _ ; Initial ComboBox color $x, $y, $w, $h, _ ; Left, top, width, height $iListRows, _ ; Rows in drop-down ListBox $vColorInfo, _ ; File/array with color info $iFirstRow = 0 ) ; First row with color info There is also a ComboColors_Delete() function. This is a picture of an example with two ComboBoxes: The example above and this example is included in zip-file. Zip-file You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. ColorSelection.7z Edited July 3, 2021 by LarsJ Topic title and two new sections at top of post Danyfirex, KaFu, mLipok and 4 others 7 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...
Skeletor Posted August 23, 2018 Share Posted August 23, 2018 First zip file that failed to download.. why? Chrome detects a virus. Strange. Please post the code. Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI Link to comment Share on other sites More sharing options...
LarsJ Posted August 23, 2018 Author Share Posted August 23, 2018 Note that it's a 7z-file. It contains 11 files and they are all text files. I'm sure they do not contain viruses or malware. So I find it strange too. I guess it's Microsoft SmartScreen that's the problem. You can try disable SmartScreen and download again. I cannot do anything about viruses or malware that simply does not exist in the 7z-file. 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...
LarsJ Posted August 23, 2018 Author Share Posted August 23, 2018 Thank you, Mr KaFu. And also thanks to everyone else. Let me know if there are any virus issues. 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...
Popular Post LarsJ Posted August 29, 2018 Author Popular Post Share Posted August 29, 2018 (edited) Checkbox Combo A Checkbox Combo control for multiple selections must be owner drawn to display Checkboxes. And the ListBox must remain open after an item is in/un-checked. Owner drawn Combo An owner drawn Combo control is discussed in first post. But there was one thing I forgot. For both WM_DRAWITEM and WM_MEASUREITEM messages, controlId is contained in wParam. In case of multiple Combo controls, the correct Combo can be determined by comparing controlId with wParam. Of course, it's much faster than first to create $tDIS and $tMIS structures from lParam, then extract CtlID from the structures, and finally compare controlId and CtlID. UDF and zip-file in first post updated. ListBox control An owner drawn Combo control can be implemented by subclassing the parent window. To keep the ListBox open, it's necessary to subclass the ListBox itself, and respond to WM_LBUTTONUP messages this way: Case $WM_LBUTTONUP Return 0 ; Prevents ListBox from closing This looks relatively easy in first place, but it has significant impact on the functionality of the entire Combo control. A number of smaller pieces of code must be added to make the control work normally again. Among other things AutoIt events are no longer generated for the corresponding controlID. This can be corrected by generating events for a Dummy control instead of: Case $WM_COMMAND Switch BitShift( $wParam, 16 ) ; _WinAPI_HiWord Case $CBN_CLOSEUP ; $idComboBox (Dummy control) event is generated when ListBox is closed GUICtrlSendToDummy( $aCheckboxCombo_Info[$iIdx][5] ) ; Dummy control EndSwitch Functions CheckboxCombo_Create() creates the Combo control but returns a Dummy control as mentioned above. CheckboxCombo_GetChecked() takes controlID (Dummy control) as input and returns checked items. CheckboxCombo_Delete() takes controlID (Dummy control) as input and deletes control. Example CheckboxCombo, 2D array.au3: expandcollapse popup;#include <Array.au3> #include <GUIConstantsEx.au3> #include "..\Includes\CheckboxCombo.au3" Example() Func Example() ; Create GUI GUICreate( "Checkbox Combo", 220, 244 ) ; Combo items Local $aItems = [ [ "Item0" ], _ [ "Item1" ], _ [ "Item2", 1 ], _ ; Item2 is checked [ "Item3" ], _ [ "Item4", 1 ], _ ; Item4 is checked [ "Item5" ], _ [ "Item6", 1 ], _ ; Item6 is checked [ "Item7" ], _ [ "Item8" ], _ [ "Item9" ] ] ; Create Checkbox Combo Local $idComboBox = CheckboxCombo_Create( 10, 10, 200, 20, 10, $aItems ) ; Show GUI GUISetState() ; Message loop While 1 Switch GUIGetMsg() Case $idComboBox ConsoleWrite( "Checked items: " & CheckboxCombo_GetChecked( $idComboBox ) & @CRLF ) ;Local $aChecked = CheckboxCombo_GetChecked( $idComboBox, 1 ) ;_ArrayDisplay( $aChecked ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc Zip-file You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. CheckboxCombo.7z Edited September 1, 2018 by LarsJ New zip: Ctrl+a mLipok, ioa747, ptrex and 3 others 5 1 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...
ptrex Posted August 30, 2018 Share Posted August 30, 2018 Hi Lars, The Checkbox Combo is a masterpiece again ! But would it be possible to add the SELECT ALL option on top. This functionality would SELECT or DESELECT all checkboxes... This becomes very handy if you have a long list of multiple checkboxes. Forgive me if the functionality is already there, because I did not yet have time to run the UDF on my machine. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
LarsJ Posted September 1, 2018 Author Share Posted September 1, 2018 ptrex, you can use Ctrl+a to check/uncheck all items. New zip above. Skysnake and mLipok 1 1 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...
ptrex Posted September 3, 2018 Share Posted September 3, 2018 Hi LarsJ, Tested and all works fine Thanks ptrex LarsJ 1 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Aelc Posted April 24, 2020 Share Posted April 24, 2020 (edited) Hey LarsJ, Sorry for replying to such an old post. awesome work those Checkboxes ! But i have a question: I wanted to start with zero checked items and the Combobox doesn't appear in my GUI then. Is this a bug? Or did i missed something? If not is there a way around? 2D array example: Local $aItems = [ [ "Item0" ], _ [ "Item1" ], _ [ "Item2" ], _ [ "Item3" ], _ [ "Item4" ], _ [ "Item5" ], _ [ "Item6" ], _ [ "Item7" ], _ [ "Item8" ], _ [ "Item9" ] ] Edited April 24, 2020 by Aelc why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
LarsJ Posted April 24, 2020 Author Share Posted April 24, 2020 Come on. This isn't an old post. It seems to be a bug. You can use this array as a workaround: Local $aItems = [ [ "Item0", 0 ], _ [ "Item1" ], _ [ "Item2" ], _ [ "Item3" ], _ [ "Item4" ], _ [ "Item5" ], _ [ "Item6" ], _ [ "Item7" ], _ [ "Item8" ], _ [ "Item9" ] ] Aelc 1 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...
Aelc Posted April 24, 2020 Share Posted April 24, 2020 5 minutes ago, LarsJ said: Come on. This isn't an old post. Yes sorry for this, but didn't want to create a new topic if it's actually the same subject 8 minutes ago, LarsJ said: It seems to be a bug. You can use this array as a workaround: Local $aItems = [ [ "Item0", 0 ], _ [ "Item1" ], _ [ "Item2" ], _ [ "Item3" ], _ [ "Item4" ], _ [ "Item5" ], _ [ "Item6" ], _ [ "Item7" ], _ [ "Item8" ], _ [ "Item9" ] ] many thanks why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
dmob Posted September 12, 2020 Share Posted September 12, 2020 I tried to hack your code and failed miserably I desire to have the combo display the number of items selected other than the default comma-delimited list of selected items. How can I achieve this? LarsJ 1 Link to comment Share on other sites More sharing options...
Gianni Posted September 12, 2020 Share Posted September 12, 2020 (edited) 2 hours ago, dmob said: I desire to have the combo display the number of items selected I think you have to modify the CheckboxCombo_ComboHandler() function located in the CheckboxCombo.au3 file like this: 1) add a variable ($iTotChecked) in line 315: Local $sText = "", $j = 0, $iTotChecked = 0 2) change line 323 from this If $sText Then $sText = StringLeft( $sText, StringLen( $sText ) - 2 ) to this If $sText Then $sText = StringReplace(StringTrimRight($sText, 2), ',', ',') $iTotChecked = @extended + 1 EndIf 3) change line 325 from this DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sText, "int", -1, "struct*", DllStructGetPtr( $tDIS, 8 ), "uint", $DT_SINGLELINE+$DT_VCENTER+$DT_END_ELLIPSIS ) ; _WinAPI_DrawText to this DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", String($iTotChecked), "int", -1, "struct*", DllStructGetPtr( $tDIS, 8 ), "uint", $DT_SINGLELINE+$DT_VCENTER+$DT_END_ELLIPSIS ) ; _WinAPI_DrawText Edited September 12, 2020 by Chimp dmob 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
dmob Posted September 12, 2020 Share Posted September 12, 2020 (edited) Thank you @Chimp, I will try that. Edit: Sadly the changes did not work, still exhibits default behavior. Edited September 12, 2020 by dmob Link to comment Share on other sites More sharing options...
Gianni Posted September 13, 2020 Share Posted September 13, 2020 Hi @dmob, my mods refer to the files included in the zip of the post "Checkbox Combo". I have checked and it works as expected. That is, when you check/uncheck the check boxes, the combo box header shows the number of checked boxes instead of the list of checked boxes.Did I misunderstand something about your goal? Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
dmob Posted September 13, 2020 Share Posted September 13, 2020 1 hour ago, Chimp said: I have checked and it works as expected. I used same UDF from the link. I will recheck my code. 1 hour ago, Chimp said: Did I misunderstand something about your goal? No, however the functionally I desire is: a) The combo is created with some items pre-checked. I would like it to display "3 Items selected" after creation. b) When selections are made, update combo text accordingly, e.g. "4 Items selected" etc. either during selection or after combo is closed/collapsed. Link to comment Share on other sites More sharing options...
LarsJ Posted September 13, 2020 Author Share Posted September 13, 2020 (edited) Slightly modified code and new function parameters: ; Create Checkbox Combo for multiple selections ; ; Flag values ; 0 => Display comma-delimited list of checked items in Edit control of Combo (default) ; 1 => Display number of checked items in Edit control, leading text in Edit control ; 2 => Display number of checked items in Edit control, trailing text in Edit control ; ; Error code in @error Return value ; 1 => Invalid item info string/array Success => $idComboBox (Dummy control) ; 2 => Error creating ComboBox Failure => 0 ; 3 => Too many ComboBoxes ; Func CheckboxCombo_Create( _ $x, $y, $w, $h, _ ; Left, top, width, height $iListRows, _ ; Rows in drop-down ListBox $vItemInfo, _ ; Item info string/array $iFlag = 0, _ ; Set option flag values $sEdit = "" ) ; Edit text if $iFlag = 1/2 CheckboxCombo.7z Edited September 13, 2020 by LarsJ Gianni and dmob 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...
Gianni Posted September 13, 2020 Share Posted September 13, 2020 (edited) 57 minutes ago, dmob said: a) The combo is created with some items pre-checked. I would like it to display "3 Items selected" after creation. b) When selections are made, update combo text accordingly, e.g. "4 Items selected" etc. either during selection or after combo is closed/collapsed. "ubi maior minor cessat" ... well, so just download the new zip from @LarsJ from the post here above and using the "CheckboxCombo, 2D array.au3" as a basic example, call the CheckboxCombo_Create() like this: ; Create Checkbox Combo Local $idComboBox = CheckboxCombo_Create(10, 10, 200, 20, 10, $aItems, 1, " Items selected") Edited September 13, 2020 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
dmob Posted September 13, 2020 Share Posted September 13, 2020 1 hour ago, LarsJ said: Slightly modified code and new function parameters: Yebo! Thank you so much @LarsJ. Most of your code zips right over my head but your UDFs bring magic Thank you @Chimp for taking the time Link to comment Share on other sites More sharing options...
dmob Posted September 13, 2020 Share Posted September 13, 2020 31 minutes ago, Chimp said: "ubi maior minor cessat" Indeed so (Had to google-translate that ) 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