Blaxxun Posted November 6, 2023 Posted November 6, 2023 Hello Forum, What is the proper way to dynamically create ComboBoxes that are able to us WM_NOTIFY. I get correct messaging when i dont use an handle array. But with handle array it stops working to trigger messages. (User changes content in Editbox my typing or choosing from the dropdown list)
Nine Posted November 7, 2023 Posted November 7, 2023 Post a replicable snippet of code that shows your issue “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents 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
Blaxxun Posted November 7, 2023 Author Posted November 7, 2023 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBoxEx.au3> Global $hCombo[4] Global $hGUI = GUICreate("GUI", 450, 200, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) For $i = 0 To 3 $hCombo[$i] = _GUICtrlComboBoxEx_Create($hGUI, "Item1", 10 + ($i * 101), 10, 100, 200) _GUICtrlComboBoxEx_AddString($hCombo[$i], "Item2") Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMCOMBOBOXEX = DllStructCreate($tagNMCOMBOBOXEX, $lParam) Local $hWndFrom = DllStructGetData($tNMCOMBOBOXEX, 'hWndFrom') Local $Code = DllStructGetData($tNMCOMBOBOXEX, 'Code') Switch $hWndFrom Case $hCombo[0] To $hCombo[UBound($hCombo) - 1] Switch $Code Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW ConsoleWrite(DllStructGetData($tNMCOMBOBOXEX, 'Item') & @LF) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Now it seems to work but sometimes stops messaging. After SciTE restart and Tidy it works again. Weird somehow. At the moment it reports the Item ID Number everytime i hover over an Item in the dropdown list. How can i limit this to just report once, once an item is actually selected? Thanks
Nine Posted November 7, 2023 Posted November 7, 2023 This line is the problem : Case $hCombo[0] To $hCombo[UBound($hCombo) - 1] Handles are not created sequentially. Consider looping into the array, or another solution would be to use control ids. As for your single report, you could use a Static variable to check if it is the last reported or not... “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents 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
Blaxxun Posted November 7, 2023 Author Posted November 7, 2023 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBoxEx.au3> #include <Array.au3> Global $hCombo[4] Global $ComboID[4] Global $hGUI = GUICreate("GUI", 450, 200, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) For $i = 0 To 3 $hCombo[$i] = _GUICtrlComboBoxEx_Create($hGUI, "Item1", 10 + ($i * 101), 10, 100, 200) $ComboID[$i] = _WinAPI_GetDlgCtrlID($hCombo[$i]) _GUICtrlComboBoxEx_AddString($hCombo[$i], "Item2") _GUICtrlComboBoxEx_SetExtendedStyle($hCombo[$i], $CBES_EX_NOSIZELIMIT) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) _ArrayDisplay($ComboID,"$ComboID") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch Sleep(10) WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMCOMBOBOXEX = DllStructCreate($tagNMCOMBOBOXEX, $lParam) Local $hWndFrom = DllStructGetData($tNMCOMBOBOXEX, 'hWndFrom') Local $Code = DllStructGetData($tNMCOMBOBOXEX, 'Code') Switch $hWndFrom Case $ComboID[0] To $ComboID[UBound($hCombo) - 1] Switch $Code Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW ConsoleWrite(DllStructGetData($tNMCOMBOBOXEX, 'Item') & " - " & $hWndFrom & @LF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY I changed the code, and i get the ID from the handle. But now i don't get any event reported... In the final program the comboboxes are generated by the user. They are on top of a Listviews colums. Colums can be added and removed and so the number of Comboboxes also change. If i use a loop to go through the array i run into timing problems...
Andreik Posted November 7, 2023 Posted November 7, 2023 On 11/7/2023 at 11:58 AM, Blaxxun said: I changed the code, and i get the ID from the handle. But now i don't get any event reported... Expand Because you are comparing handles with control ids. Switch $hWndFrom ; This is handle Case $ComboID[0] To $ComboID[UBound($hCombo) - 1] ; these are not
Blaxxun Posted November 7, 2023 Author Posted November 7, 2023 (edited) 🤦♂️ Yeah, now that you say it. Thank you! Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMCOMBOBOXEX = DllStructCreate($tagNMCOMBOBOXEX, $lParam) Local $hWndFrom = DllStructGetData($tNMCOMBOBOXEX, 'hWndFrom') Local $WndFromID = _WinAPI_GetDlgCtrlID($hWndFrom) Local $Code = DllStructGetData($tNMCOMBOBOXEX, 'Code') Switch $WndFromID Case $ComboID[0] To $ComboID[UBound($hCombo) - 1] Switch $Code Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW ConsoleWrite(DllStructGetData($tNMCOMBOBOXEX, 'Item') & " - " & $hWndFrom & @LF) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Now this works! Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW I just need a report when the user chose an item from the dropdown list and it appears in the editbox. At the moment it fires already when i click the dropdown arrow. What can i use to achive this? Edited November 7, 2023 by Blaxxun
Blaxxun Posted November 7, 2023 Author Posted November 7, 2023 Case $CBEN_ENDEDITW "Sent when the user has concluded an operation within the edit box or has selected an item from the control's drop-down list." In my case this reports already when i click the dropdown arrow. (Which is empty at first) Then when i choose an actual Item it does not report anymore. Just when i click in another combobox edit box it reports...
Solution Blaxxun Posted November 7, 2023 Author Solution Posted November 7, 2023 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiComboBoxEx.au3> Global $hCombo[4] Global $iCombo[4] Global $sComboTxt Global $hGUI = GUICreate("GUI", 450, 200, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) For $i = 0 To 3 $hCombo[$i] = _GUICtrlComboBoxEx_Create($hGUI, "Item1", 10 + ($i * 101), 10, 100, 200) $iCombo[$i] = _WinAPI_GetDlgCtrlID($hCombo[$i]) _GUICtrlComboBoxEx_AddString($hCombo[$i], "Item2") Next GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nCode = BitShift($wParam, 16) ; Hiword Local $iCtrl = BitAND($wParam, 0xFFFF) ; Loword Local $hCtrl = $lParam Switch $iCtrl Case $iCombo[0] To $iCombo[UBound($iCombo) - 1] Switch $nCode ;Case $CBN_EDITUPDATE, $CBN_EDITCHANGE ; When user types in new Data ;ConsoleWrite("Types" & @LF) Case $CBN_SELCHANGE ; Item from Dropdown selected $iComboIdx = _GUICtrlComboBox_GetCurSel($hCtrl) $aComboAtt = _GUICtrlComboBoxEx_GetItem($hCtrl, $iComboIdx) $sComboTxt = $aComboAtt[0] ConsoleWrite($sComboTxt & @TAB & $iCtrl & @TAB & $hCtrl & @LF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND This works and only fires when an Item was selected Edited November 7, 2023 by Blaxxun
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