Sign in to follow this  
Followers 0
DicatoroftheUSA

Auto Drop ComboBox - solved

11 posts in this topic

#1 ·  Posted (edited)

I have a gui for most buttons and checkboxes I name with "&exemple" for keyboard navigation.

I have a combo box, that when clicked on, it drops and then the user can click on an item in the list. When the user clicks on an item it takes that text and puts into an input box. Basically it lists field headers as a helper for a sqlite database syntax.

The problem is, I can set a hotkey for the input box label, it gives it focus, but it does not drop the box down. The down arrow does not cause it to drop when it has focus either, it will just select the next item in the box.

I would like it that when a hotkey is pressed to give the combobox focus, and if the down arrow is pressed, it drops down automatically,

TIA

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

take a look at ContolCommand() And GUICtrlSetState() in the help file

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

take a look at ContolCommand() And GUICtrlSetState() in the help file

It goes without saying. I did, and it didn't help. Which should go without saying, else I would not have posted. Please don't make useless replies, it wastes time; mine, yours, and everyone else who might be looking for a similar issue. If your trying to make yourself look smart by being a sarcastic smartass, you failed.

Below is an example of my script. I need it so that when in the below example, when alt+f or alt+C is pressed the respective input box drops. In the below example, clicking on the label, it does what I want it to be able to do with the keyboard. As it is, with the keyboard, it just gives focus.

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
$loGUI=GUICreate("EXAMPLE")
 
$loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10,400,200)
$loLColumn=GUICtrlCreateLabel("&Fields", 10,215)
$loComboColumns = GUICtrlCreateCombo("", 10,240,100,20,BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboColumns,"EXAMPLE1")
GUICtrlSetData($loComboColumns,"EXAMPLE2")
$lolCommand=GUICtrlCreateLabel("&Compare", 120, 215)
$loComboCommands = GUICtrlCreateCombo("", 120, 240,100,20,  BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboCommands,"EXAMPLE3")
GUICtrlSetData($loComboCommands,"EXAMPLE4")
GUISetState()
WHILE 1
  SWITCH GUIGetMsg()
   Case $loComboColumns
    GUICtrlSetData($loInpSelect, GUICtrlRead($loComboColumns), "test")
   Case $loComboCommands
    GUICtrlSetData($loInpSelect, GUICtrlRead($loComboCommands), "test")
   CASE $loLColumn
    ConsoleWrite("hugh")
    ControlCommand($loGUI,"",$loComboColumns,"ShowDropDown", "")
   CASE $lolCommand
    ConsoleWrite("hugh")
    ControlCommand($loGUI,"",$loComboCommands,"ShowDropDown", "")
   Case $GUI_EVENT_CLOSE
    GUIDelete($loGUI)
    ExitLoop
   EndSwitch
WEnd
Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

HotKeySet("^d","dropdown")

Func dropdown()

Guictrlsetstate($comboname, $GUI_FOCUS)

Send("{F4}")

otherwise check this post -

Edited by nevodj

Share this post


Link to post
Share on other sites

Send F4 will drop the combo box down

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
HotKeySet("!f", "_drop")
HotKeySet("!c", "_undrop")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 152, 361, 178)
Global $Combo1 = GUICtrlCreateCombo("Combo1", 16, 64, 145, 25)
GUICtrlSetData(-1, "i|see|this|script|works")
$Label1 = GUICtrlCreateLabel("Press Alt+f to drop the box", 16, 16, 128, 17)
$Label2 = GUICtrlCreateLabel("Press Alt+c to undrop the box", 16, 40, 143, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
 
Func _drop()
    ControlCommand("Form1", "", $Combo1, "ShowDropDown", "")
EndFunc
 
Func _undrop()
    ControlCommand("Form1", "", $Combo1, "HideDropDown", "")
EndFunc

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 152, 361, 178)
$Combo1 = GUICtrlCreateCombo("Combo1", 16, 64, 145, 25)
GUICtrlSetData(-1, "i|see|this|script|works")
$Label1 = GUICtrlCreateLabel("Press Alt+f to drop the box", 16, 16, 128, 17)
$Label2 = GUICtrlCreateLabel("Press Alt+c to undrop the box", 16, 40, 143, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If _IsPressed(12) And _IsPressed(46) Then
        ControlCommand("Form1", "", $Combo1, "ShowDropDown", "")
    ElseIf _IsPressed(12) And _IsPressed(43) Then
        ControlCommand("Form1", "", $Combo1, "HideDropDown", "")
    EndIf
WEnd

Examples of how to use them, both ways i believe you will find work

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks guys, what I ended up doing is below. I really like to minimize global declares, registers, and process usage, as my scripts tend to get massive. I need them to be easy enouph to read, with clearcut cause>effect chains, that neophyte coworkers can manipulate it when needed, and can eventually be turned into #includes without worry.

The problem with below, is the mouse no longer works on the combobox as expected for an end user, but that is a better problem than not having keyboard control. And worse, it forces them to select something. I know I can write a process hungry escape pattern, but I want it to be lean. I would appreciate any further tips.

#include <GUIConstantsEx.au3>
#Include <Misc.au3>
#include <ComboConstants.au3>
$loGUI = GUICreate("EXAMPLE")
 
_gui()
func _gui()
$loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10, 400, 200)
$loLColumn = GUICtrlCreateLabel("&Fields", 10, 215)
$loComboColumns = GUICtrlCreateCombo("", 10, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboColumns, "EXAMPLE1")
GUICtrlSetData($loComboColumns, "EXAMPLE2")
$lolCommand = GUICtrlCreateLabel("&Compare", 120, 215)
$loComboCommands = GUICtrlCreateCombo("", 120, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboCommands, "EXAMPLE3")
GUICtrlSetData($loComboCommands, "EXAMPLE4")
GUISetState()
$loDll = DllOpen("user32.dll")
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   GUIDelete($loGUI)
   ExitLoop
EndSwitch
_UnMouseCombo($loGui,$loComboColumns,$loInpSelect,$loDll )
_UnMouseCombo($loGui,$loComboCommands,$loInpSelect,$loDll )
 
WEnd
DllClose($loDll)
EndFunc
Func _UnMouseCombo($loGui,$loCombo,$loRefocus,$loDll )
WHILE 1
$X=0
If ControlGetHandle($loGUI, "", ControlGetFocus($loGUI)) = GUICtrlGetHandle($loCombo) AND $X=0 Then
  ControlCommand($loGUI,"",$loCombo,"ShowDropDown", "")
  $X=1
  If _IsPressed('0D', $loDll) Or _IsPressed('20', $loDll) Then
   ControlFocus($loGui,"",$loRefocus)
   GUICtrlSetData($loRefocus, GUICtrlRead($loRefocus)&" "&  GUICtrlRead($loCombo)&" ")
   RETURN (1)
  EndIf
else
  SetError(2)
  ControlCommand($loGUI,"",$loCombo,"HIDEDropDown", "")
  Return (-1)
  ExitLoop
EndIf
WEnd
EndFunc
Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

the easiest way is for the user to press F4 to drop / minimize the combobox... it's a standard windows function... why complicate your script by replicating it.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

the easiest way is for the user to press F4 to drop / minimize the combobox... it's a standard windows function... why complicate your script by replicating it.

To answer your retorical question in short; it is because the drop down combo object is doesn't work as I need it to. If the solution was so simple, I wouldn't have posted. If I am not making it clear on what I am trying to accomplish, let me know how to clarify. If you are being snarky, shame on you for wasting everyones time.

What happens when they press f4, and then use the arrow keys, every time the arrow key is pressed it registers with guigetmsg() and performs the function, namely reading the value and appending it to an input box. I only want that after their selection is highlighted and press enter, or click on it. If you run the first example script, you will note this behavoir.

For some reason if I try to modify that behavior by making so that under guigetmsg=combo, if I use _ispressed is mouse click or keyboard. It doesn't run the function. Also if I just check for the enter or click event, and then check for focus, it would cause problems, as it is possible for the user to click another portion of the gui while the combobox still has focus.

I could use hotkey set, but as I stated before, I hate using global values and functions, as I intend this to be modular and used under different applications, and I would rather use a method that won't eventually cause conflicts. And ultamately I bet it is unnescessary, because I am familiar with other native windows apps that behave in the way I am trying accomplish here.

If a solution doesn't come up soon, I think I will just have to make a popup child gui. It is much uglier in script and in UI, but I am short on ideas.

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

Create a button that is used to activate the Combobox selection instead. This way you can scroll up and down the list as much as you want, but until you press the button, nothing gets activated. I took your script and added a button to the GUI and a message box to demonstrate one way to do it.

Func _gui()
    $loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10, 400, 200)
    $loLColumn = GUICtrlCreateLabel("&Fields", 10, 215)
    $loComboColumns = GUICtrlCreateCombo("", 10, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
    GUICtrlSetData($loComboColumns, "EXAMPLE1")
    GUICtrlSetData($loComboColumns, "EXAMPLE2")
    $lolCommand = GUICtrlCreateLabel("&Compare", 120, 215)
    $loComboCommands = GUICtrlCreateCombo("", 120, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
    GUICtrlSetData($loComboCommands, "EXAMPLE3")
    GUICtrlSetData($loComboCommands, "EXAMPLE4")
    $Button1 = GUICtrlCreateButton("GO", 20, 300)
    GUISetState()
    $loDll = DllOpen("user32.dll")
    While 1
         Switch GUIGetMsg()
             Case $GUI_EVENT_CLOSE
                  GUIDelete($loGUI)
                  Exit
             Case $Button1
                  MsgBox(0, "", "ComboBox1 reads: " & GUICtrlRead($loComboColumns) & @CRLF & "ComboBox2 reads: " & GUICtrlRead($loComboCommands))
        EndSwitch
;~   _UnMouseCombo($loGUI, $loComboColumns, $loInpSelect, $loDll)
;~   _UnMouseCombo($loGUI, $loComboCommands, $loInpSelect, $loDll)
      WEnd
       DllClose($loDll)
EndFunc   ;==>_gui

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@BrewManNH -Thanks, I thought of that, but for this application, it is not intuitive enouph. In nature this application going to be unavoidably too complex for its users, any multistep buttons, even clicking an extra couple buttons (ie tab+enter) will slow them down too much and cause their heads to explode.

I think I will settle with the script below, and teach them f4. Marking as solved.

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
#include <Misc.au3>
 
Local $loComboSelection
$loGUI = GUICreate("EXAMPLE")
$loDLL = DllOpen("user32.dll")
$loInpSelect = GUICtrlCreateInput('select  * from records where scandate>' & @YEAR & @MON & @MDAY & 0000 & ' order by scandate limit 254;', 10, 10, 400, 200)
$loLColumn = GUICtrlCreateLabel("&Fields", 10, 215)
$loComboColumns = GUICtrlCreateCombo(" ", 10, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboColumns, "EXAMPLE1")
GUICtrlSetData($loComboColumns, "EXAMPLE2")
$lolCommand = GUICtrlCreateLabel("&Compare", 120, 215)
$loComboCommands = GUICtrlCreateCombo(" ", 120, 240, 100, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData($loComboCommands, "EXAMPLE3")
GUICtrlSetData($loComboCommands, "EXAMPLE4")
GUISetState()
 
While 1
Switch GUIGetMsg()
  Case $loComboColumns
;~  GUICtrlSetData($loInpSelect, GUICtrlRead($loComboColumns), "test")
   $loComboSelection = GUICtrlRead($loComboColumns)
   GUICtrlSetData($loComboCommands, " ")
  Case $loComboCommands
;~  GUICtrlSetData($loInpSelect, GUICtrlRead($loComboCommands), "test")
   $loComboSelection = GUICtrlRead($loComboCommands)
   GUICtrlSetData($loComboColumns, " ")
  Case $loLColumn
   ControlCommand($loGUI, "", $loComboColumns, "ShowDropDown", "")
  Case $lolCommand
   ControlCommand($loGUI, "", $loComboCommands, "ShowDropDown", "")
  Case $GUI_EVENT_CLOSE
   GUIDelete($loGUI)
   ExitLoop
EndSwitch
If WinActive($loGUI) Then
  _HandleBox($loGUI, $loComboColumns, $loInpSelect, $loDLL)
  _HandleBox($loGUI, $loComboCommands, $loInpSelect, $loDLL)
EndIf
WEnd
Sleep(100)
Func _HandleBox($loGUI, $loComboBox, $loInputBox, $loDLL)
Local $lsRead
If _GuiCtrlGetFocus($loGUI) = $loComboBox Then
If _IsPressed('01', $loDLL) Or _IsPressed('0D', $loDLL) Then
   $lhGui = GUICtrlGetHandle($loGUI)
   If GUICtrlRead($loComboBox) <> "" Then
    $lsRead = GUICtrlRead($loComboBox)
    GUICtrlSetData($loComboBox, " ")
    While _IsPressed('01', $loDLL) Or _IsPressed('0D', $loDLL)
     Sleep(1)
    WEnd
    GUICtrlSetData($loInpSelect, $lsRead, "test")
   EndIf
  EndIf
EndIf
EndFunc   ;==>_HandleBox
 
Func _GuiCtrlGetFocus($GuiRef)
Local $hwnd = ControlGetHandle($GuiRef, "", ControlGetFocus($GuiRef))
Local $result = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hwnd)
Return $result[0]
EndFunc   ;==>_GuiCtrlGetFocus
Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Xandy
      By Xandy
      I have a bunch of SDL_Surfaces loaded into memory.  I want to list them in a ComboBox.
      Using this code, I can load images to the combobox from file but not from existing SDL_Surface memory
      CODE ISN"T MEANT TO RUN
      ; Create combobox pic list example $aControl[$iControl_id][$eControl_data] = _GUICtrlComboBoxEx_Create($gui, $data_value, $data_x, $data_y, $data_w, $data_h, $CBS_DROPDOWNLIST) ; Image List for ComboboxEx Local $hImage = _GUIImageList_Create($gTile_w, $gTile_h, 6) ; Fill hImage with SDL_Surfaces stored in memory: aNPC_surf[scale][type][way][frame] For $i = 0 To 1 ; This works but only from file: ;_GUIImageList_AddBitmap($hImage, $gFolder_graphics & $gaWorld_info[$player.iWorld_cur][$eWi_filename] & "Tiles\" & $i & ".bmp") ; I've broken up a sprite sheet and want to insert into combobox from memory ;_GUIImageList_Add($hImage, $aNPC_surf[1][1][1][$i]) _GUIImageList_Add($hImage, _GDIPlus_BitmapCreateFromMemory($aNPC_surf[1][1][1][$i]), True) ;_GDIPlus_BitmapCreateFromMemory($aNPC_surf[1][1][1][$i]) ; Add the index number to combobox item _GUICtrlComboBoxEx_AddString($aControl[$eNPC_iPic_type][$eControl_data], $i, $i, $i) Next ; Set hImage list to combobox control _GUICtrlComboBoxEx_SetImageList($aControl[$eNPC_iPic_type][$eControl_data], $hImage) Anyone know if I can convert from SDL_Surface to hBitmap?  Maybe I'm doing something else wrong.
       
      I've seen hBitmap converted to SDL_Surface but I don't really understand it yet: 
       
      My full script can be found here:
       
    • odaylton
      By odaylton
      I even understand that the Handle generated by _WinAPI_LoadCursor is not an Icon but how to display the image in the Combobox
      Here is the listing and please tell me how to make the current user current cursor image uncertainty
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo Local $idListview, $hImage Local $sWow64 = "" Local $Pasta="C:\WINDOWS\Cursors\3dgarro.cur" $hGUI = GUICreate("ImageList Mouse Icons", 400, 300) $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100) $idListview = GUICtrlCreateListView("", 2, 104, 394, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create(16, 16) ;teste _GUIImageList_AddIcon($hImage, $Pasta) ;<<<<<<<<<<<<<<<<<<<<<this $hIcon= _WinAPI_CopyCursor(_WinAPI_LoadCursor(0,$IDC_HAND));32649 ; Hand cursor _GUIImageList_AddIcon($hImage, $hIcon);<<<<<<<<<<<<<<<<<< erro for $i=1 to 15 $hIcon= _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, $i));<<<<<<<<<<<<<<<<< _GUIImageList_AddIcon($hImage, $hIcon);<<<<<<<<<<<< Next _GUIImageList_AddIcon($hImage, $Pasta) _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Items", 120) ; Add items $a=StringSplit("testeIcone|HAND|APPSTARTING|ARROW|CROSS|HELP|IBEAM|ICON|NO|SIZE|SIZEALL|SIZENESW|SIZENS|SIZENWSE|SIZEWE|UPARROW|WAIT|testefim","|") For $i=1 to $a[0] _GUICtrlListView_AddItem($idListview, $a[$i], $i-1) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $i-1) Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Note that only the initial image is uncertain because it comes from a file
      And the one that would be the last enters as the second
      And the background is black how to transform into transparent
      imagem de cursor.bmp
    • Ian_Mac
      By Ian_Mac
      hello, i just wanted to ask if how........
       I have a gui combo box with a list and i wanted it to remember the last item that i selected, that when i close the gui and then open the gui again, my last selected item will be automatically show in the combobox as selected item already.
      thank you in advance.
    • argumentum
      By argumentum
      #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Array.au3> #include <WinAPITheme.au3> #include <GDIPlus.au3> #Region GUICtrlComboSetColors UDF Global $g__aWM_CTLCOLORLISTBOX[1][16] = [[0, 0, 0]] ; init. the Global array ; #FUNCTION# ==================================================================================================================== ; Name...........: GUICtrlComboSetColors ; Description ...: Change the colors and position/size of a ComboBox ; Syntax.........: GUICtrlComboSetColors ( $idCombo [, $iBgColor = Default] [, $iFgColor = Default] [, $iExtendLeft = Default] ) ; Parameters ....: $idCombo - GUICtrlCreateCombo() ControlID / [ ArrayIndex ] ; $iBgColor - Background RGB color ; - or "-1" to use prior color declared ; - or to remove a control by ControlID, "-2" ; - or to remove a control by ArrayIndex, "-3" ; $iFgColor - Foreground RGB color ; - or "-1" to use prior color declared ; - or "-2" to use sytem color and leave theme default ; $iExtendLeft - pixels to extend the dropdown list ; - or "-1" to use prior width declared ; - or "1" auto size, extending left ( see Remarks/AutoSize ) ; - or "2" auto size, extending right ( see Remarks/AutoSize ) ; Return values .: Success - index position in the array ; Failure - 0 ; @error - 1 : Control handle = 0 ; - 2 : GetComboBoxInfo failed ; - 3 : Control for removal not found ; @extended - 2 : Success on Control removal ; Author ........: argumentum ; Modified.......: v0.0.0.5 ; Remarks .......: this UDF is in its a work in progress, will expand if needed. ; AutoSize...: use the pertinent parameters from GUICtrlComboSetColors_SetAutoSize() ; minus the CtrlID as semicolon separated to initialize. Ex: "2;Arial;8.5;0" ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-bgcolor/ ; Example .......: Yes, at the end of the file ; =============================================================================================================================== Func GUICtrlComboSetColors($idCombo = 0, $iBgColor = Default, $iFgColor = Default, $iExtendLeft = Default) If Not $idCombo Then Return SetError(1, 0, 0) Local $n, $tInfo, $i = 0 If $iBgColor = -2 Or $iBgColor = -3 Then Local $m For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If ($g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo And $iBgColor = -2) Or ($g__aWM_CTLCOLORLISTBOX[$n][9] = $idCombo And $iBgColor = -3) Then _ArrayDelete($g__aWM_CTLCOLORLISTBOX, $n) $g__aWM_CTLCOLORLISTBOX[0][0] -= 1 Return SetError(0, 2, $n) EndIf Next Return SetError(3, 0, 0) EndIf For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo Then $i = $n ExitLoop EndIf Next If Not $i Then $g__aWM_CTLCOLORLISTBOX[0][0] += 1 $i = $g__aWM_CTLCOLORLISTBOX[0][0] ; If $i >= UBound($g__aWM_CTLCOLORLISTBOX) Then ReDim $g__aWM_CTLCOLORLISTBOX[$i + 1][16] ; add extra "slots" EndIf EndIf Local $sStr = GUICtrlRead($idCombo) Local $iSetWindowTheme = 1 If $iBgColor = Default And $iFgColor = Default Then $iSetWindowTheme = 0 If $iBgColor = Default Then $iBgColor = _WinAPI_GetSysColor($COLOR_WINDOW) If $iFgColor = Default Then $iFgColor = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) If $iBgColor = -1 Then $iBgColor = $g__aWM_CTLCOLORLISTBOX[$i][10] If $iFgColor = -1 Then $iFgColor = $g__aWM_CTLCOLORLISTBOX[$i][11] $g__aWM_CTLCOLORLISTBOX[$i][11] = $iFgColor $g__aWM_CTLCOLORLISTBOX[$i][10] = $iBgColor If $iExtendLeft = Default Then $iExtendLeft = 0 $g__aWM_CTLCOLORLISTBOX[$i][12] = 0 EndIf If $iExtendLeft = -1 Then $iExtendLeft = $g__aWM_CTLCOLORLISTBOX[$i][8] ElseIf Int($iExtendLeft) = 1 Then $g__aWM_CTLCOLORLISTBOX[$i][12] = 1 ElseIf Int($iExtendLeft) = 2 Then $g__aWM_CTLCOLORLISTBOX[$i][12] = 2 Else $g__aWM_CTLCOLORLISTBOX[$i][12] = 0 EndIf $g__aWM_CTLCOLORLISTBOX[$i][8] = Int($iExtendLeft) $g__aWM_CTLCOLORLISTBOX[$i][0] = $idCombo $g__aWM_CTLCOLORLISTBOX[$i][1] = GUICtrlGetHandle($idCombo) $g__aWM_CTLCOLORLISTBOX[$i][13] = "Arial" ; default $sFont $g__aWM_CTLCOLORLISTBOX[$i][14] = 8.5 ; default $fSize $g__aWM_CTLCOLORLISTBOX[$i][15] = 0 ; default $iStyle If $g__aWM_CTLCOLORLISTBOX[$i][12] Then $f = StringSplit($iExtendLeft, ";") If UBound($f) > 1 Then $g__aWM_CTLCOLORLISTBOX[$i][8] = Int($f[1]) If UBound($f) > 2 Then $g__aWM_CTLCOLORLISTBOX[$i][13] = $f[2] If UBound($f) > 3 Then $g__aWM_CTLCOLORLISTBOX[$i][14] = Int($f[3]) If UBound($f) > 4 Then $g__aWM_CTLCOLORLISTBOX[$i][15] = Int($f[4]) $t = TimerInit() GUICtrlComboSetColors_SetAutoSize(Int("-" & $i), $g__aWM_CTLCOLORLISTBOX[$i][12], $g__aWM_CTLCOLORLISTBOX[$i][13], $g__aWM_CTLCOLORLISTBOX[$i][14], $g__aWM_CTLCOLORLISTBOX[$i][15]) ConsoleWrite(TimerDiff($t) & @CRLF) EndIf If _GUICtrlComboBox_GetComboBoxInfo($idCombo, $tInfo) Then If $iSetWindowTheme Then If $g__aWM_CTLCOLORLISTBOX[$i][11] <> -2 Then _WinAPI_SetWindowTheme($g__aWM_CTLCOLORLISTBOX[$i][1], "", "") If $g__aWM_CTLCOLORLISTBOX[$i][11] <> -2 Then GUICtrlSetColor($g__aWM_CTLCOLORLISTBOX[$i][0], $iFgColor) GUICtrlSetBkColor($g__aWM_CTLCOLORLISTBOX[$i][0], $iBgColor) Else GUICtrlSetBkColor($g__aWM_CTLCOLORLISTBOX[$i][0], _WinAPI_GetSysColor($COLOR_HOTLIGHT)) _WinAPI_SetWindowTheme($g__aWM_CTLCOLORLISTBOX[$i][1], 0, 0) EndIf $g__aWM_CTLCOLORLISTBOX[$i][2] = DllStructGetData($tInfo, "hCombo") $g__aWM_CTLCOLORLISTBOX[$i][3] = DllStructGetData($tInfo, "hEdit") $g__aWM_CTLCOLORLISTBOX[$i][4] = DllStructGetData($tInfo, "hList") ; this is what is colored Else $g__aWM_CTLCOLORLISTBOX[0][0] -= 1 Return SetError(2, 0, 0) EndIf If Int($g__aWM_CTLCOLORLISTBOX[$i][5]) Then _WinAPI_DeleteObject($g__aWM_CTLCOLORLISTBOX[$i][5]) $g__aWM_CTLCOLORLISTBOX[$i][5] = 0 ; holder for "_WinAPI_CreateSolidBrush()" return value $g__aWM_CTLCOLORLISTBOX[$i][6] = BitOR(BitAND($iBgColor, 0x00FF00), BitShift(BitAND($iBgColor, 0x0000FF), -16), BitShift(BitAND($iBgColor, 0xFF0000), 16)) If $g__aWM_CTLCOLORLISTBOX[$i][11] = -2 Then $iFgColor = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) $g__aWM_CTLCOLORLISTBOX[$i][7] = BitOR(BitAND($iFgColor, 0x00FF00), BitShift(BitAND($iFgColor, 0x0000FF), -16), BitShift(BitAND($iFgColor, 0xFF0000), 16)) If Not $g__aWM_CTLCOLORLISTBOX[0][1] Then If $g__aWM_CTLCOLORLISTBOX[$i][4] Then $g__aWM_CTLCOLORLISTBOX[0][1] = GUIRegisterMsg($WM_CTLCOLORLISTBOX, "UDF_WM_CTLCOLORLISTBOX") If $g__aWM_CTLCOLORLISTBOX[0][1] Then OnAutoItExitRegister("OnAutoItExit_UDF_WM_CTLCOLORLISTBOX") EndIf EndIf $g__aWM_CTLCOLORLISTBOX[0][2] += 1 $g__aWM_CTLCOLORLISTBOX[$i][9] = $g__aWM_CTLCOLORLISTBOX[0][2] ; internal ID $g__aWM_CTLCOLORLISTBOX[0][3] = TimerInit() ; to use in UDF_WM_CTLCOLORLISTBOX() $g__aWM_CTLCOLORLISTBOX[0][4] = 0 ; to use in UDF_WM_CTLCOLORLISTBOX() If $sStr Then GUICtrlSetData($idCombo, $sStr) Return SetError(0, 0, $g__aWM_CTLCOLORLISTBOX[0][2]) EndFunc ;==>GUICtrlComboSetColors Func UDF_WM_CTLCOLORLISTBOX($hWnd, $Msg, $wParam, $lParam) ConsoleWrite('+ Func UDF_WM_CTLCOLORLISTBOX(' & $hWnd & ', ' & $Msg & ', ' & $wParam & ', ' & $lParam & ')' & @CRLF) For $i = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$i][4] = $lParam Then If TimerDiff($g__aWM_CTLCOLORLISTBOX[0][3]) > 500 Or $g__aWM_CTLCOLORLISTBOX[0][4] <> $lParam Then If $g__aWM_CTLCOLORLISTBOX[$i][12] Then GUICtrlComboSetColors_SetAutoSize("-" & $i) EndIf $g__aWM_CTLCOLORLISTBOX[0][3] = TimerInit() $g__aWM_CTLCOLORLISTBOX[0][4] = $lParam If $g__aWM_CTLCOLORLISTBOX[$i][8] > 0 Then Local $aWPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$i][2]) WinMove($lParam, "", $aWPos[0] - $g__aWM_CTLCOLORLISTBOX[$i][8], $aWPos[1] + $aWPos[3], $aWPos[2] + $g__aWM_CTLCOLORLISTBOX[$i][8]) ElseIf $g__aWM_CTLCOLORLISTBOX[$i][8] < 0 Then Local $aWPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$i][2]) WinMove($lParam, "", $aWPos[0], $aWPos[1] + $aWPos[3], $aWPos[2] - $g__aWM_CTLCOLORLISTBOX[$i][8]) EndIf If $g__aWM_CTLCOLORLISTBOX[$i][7] >= 0 Then _WinAPI_SetTextColor($wParam, $g__aWM_CTLCOLORLISTBOX[$i][7]) EndIf If $g__aWM_CTLCOLORLISTBOX[$i][6] >= 0 Then _WinAPI_SetBkColor($wParam, $g__aWM_CTLCOLORLISTBOX[$i][6]) If Not $g__aWM_CTLCOLORLISTBOX[$i][5] Then $g__aWM_CTLCOLORLISTBOX[$i][5] = _WinAPI_CreateSolidBrush($g__aWM_CTLCOLORLISTBOX[$i][6]) Return $g__aWM_CTLCOLORLISTBOX[$i][5] EndIf Return 0 EndIf Next EndFunc ;==>UDF_WM_CTLCOLORLISTBOX ; #FUNCTION# ==================================================================================================================== ; Name...........: GUICtrlComboSetColors_SetAutoSize ; Description ...: Set autosize for a ComboBox initialized in GUICtrlComboSetColors() ; Syntax.........: GUICtrlComboSetColors ( $idCombo [, $iExtendLeft = Default] [, $sFont = Default] [, $fSize = Default] [, $iStyle = Default] ) ; Parameters ....: $idCombo - GUICtrlCreateCombo() ControlID / [ ArrayIndex ] ; $iExtendLeft - 1 = Left, 2 = Right, 0 = disable auto-sizing ; $sFont - Font name ; $fSize - Font size ; $iStyle - Font style ; Return values .: Success - widthest string in pixels ; Failure - -1 ; @error - look at the comments in the function ; Author ........: argumentum ; Modified.......: v0.0.0.5 ; Remarks .......: this UDF is in its a work in progress, will expand if needed. ; Related .......: GUICtrlComboSetColors() ; Link ..........: https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-bgcolor/ ; Example .......: Yes, at the end of the file ; =============================================================================================================================== Func GUICtrlComboSetColors_SetAutoSize($idCombo, $iExtendLeft = Default, $sFont = Default, $fSize = Default, $iStyle = Default) ConsoleWrite('+ Func GUICtrlComboSetColors_AutoSizeSet("' & $idCombo & '", "' & $iExtendLeft & '", "' & $sFont & '", "' & $fSize & '", "' & $iStyle & '")' & @CRLF) $idCombo = Int($idCombo) ; just in case the value is a string Local $n, $iArrayIndex = 0, $iCtrl = 0 If $idCombo > 0 Then For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo Then ; the expected value, is the ControlID $iArrayIndex = $n ExitLoop EndIf Next Return SetError(4, 0, -1) ; $iArrayIndex not found ElseIf $idCombo < 0 Then ; the expected value, is a negative of array's index .. $iArrayIndex = Int(StringTrimLeft(StringStripWS($idCombo, 8), 1)) ; .. so now is a positive value .. If $iArrayIndex < 1 Then Return SetError(3, 0, -1) ; .. else, error .. If $iArrayIndex > $g__aWM_CTLCOLORLISTBOX[0][0] Then Return SetError(2, 0, -1) ; .. as long as is not greater than expected Else Return SetError(1, 0, -1) ; could not find a usable value EndIf Switch $iExtendLeft Case 0, 1, 2 $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][12] = $iExtendLeft EndSwitch Local $aCtrlPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$iArrayIndex][1]) If UBound($aCtrlPos) <> 4 Then Return SetError(5, 0, -1) ; could not get a usable value Local $sString = StringReplace(_GUICtrlComboBox_GetList($g__aWM_CTLCOLORLISTBOX[$iArrayIndex][0]), "|", @CRLF) Local $aStrWidth = _GDIPlus_MeasureString($sString, $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][13], $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][14], $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][15]) If UBound($aStrWidth) <> 2 Then Return SetError(6, 0, -1) ; could not get a usable value If $aStrWidth[0] < $aCtrlPos[2] Then $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = 0 Else $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = $aStrWidth[0] - $aCtrlPos[2] If $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][12] = 2 Then $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = Int("-" & $aStrWidth[0] - $aCtrlPos[2]) EndIf Return $aStrWidth[0] EndFunc ;==>GUICtrlComboSetColors_SetAutoSize Func _GDIPlus_MeasureString($sString, $sFont = "Arial", $fSize = 12, $iStyle = 0, $bRound = True) ConsoleWrite('Func _GDIPlus_MeasureString("' & $sString & '", "' & $sFont & '", "' & $fSize & '", "' & $iStyle & '", "' & $bRound & '")' & @CRLF) ; original code @ https://www.autoitscript.com/forum/topic/150736-gdi-wrapping-text/?do=findComment&comment=1077210 If Not $__g_iGDIPRef Then _GDIPlus_Startup() ; added by argumentum for this UDF's implementation ( AutoIt v3.3.14 ) due to the way the function is written ;~ Func _GDIPlus_Startup($sGDIPDLL = Default, $bRetDllHandle = False) ;~ $__g_iGDIPRef += 1 <-- I believe this aspect should be coded differently in "GDIPlus.au3" ;~ If $__g_iGDIPRef > 1 Then Return True Local $aSize[2] Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) If Not $hFamily Then Return SetError(1, 0, $aSize) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle) Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) Local Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) $aSize[0] = $bRound ? Round($aInfo[0].Width, 0) : $aInfo[0].Width $aSize[1] = $bRound ? Round($aInfo[0].Height, 0) : $aInfo[0].Height _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return $aSize EndFunc ;==>_GDIPlus_MeasureString Func OnAutoItExit_UDF_WM_CTLCOLORLISTBOX() For $i = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If Int($g__aWM_CTLCOLORLISTBOX[$i][5]) Then _WinAPI_DeleteObject($g__aWM_CTLCOLORLISTBOX[$i][5]) Next If $__g_iGDIPRef Then _GDIPlus_Shutdown() EndFunc ;==>OnAutoItExit_UDF_WM_CTLCOLORLISTBOX #EndRegion GUICtrlComboSetColors UDF Example() Func Example() ; Create GUI GUICreate("ComboBox Set DROPDOWNLIST BgColor", 640, 300) Local $a_idCombo[7] = [6] $a_idCombo[1] = GUICtrlCreateCombo("", 2, 2, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[1], 0xEEEEEE, -2, Default) Example_FillTheCombo($a_idCombo[1]) GUICtrlCreateLabel("<<< change BG color, default theme && size ", 400, 4, 396, 296) $a_idCombo[2] = GUICtrlCreateCombo("", 2, 32, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[2], 0x0000FF, 0xFFFF00, 0) Example_FillTheCombo($a_idCombo[2]) GUICtrlCreateLabel("<<< change colors", 400, 34, 396, 296) $a_idCombo[3] = GUICtrlCreateCombo("", 2, 62, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[3], 0xdddddd, Default, 100) Example_FillTheCombo($a_idCombo[3]) GUICtrlCreateLabel("<<< change BG color, resize 100px. left", 400, 64, 396, 296) $a_idCombo[4] = GUICtrlCreateCombo("", 2, 92, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[4], Default, 0x0000FF, -100) Example_FillTheCombo($a_idCombo[4]) GUICtrlCreateLabel("<<< change FG color, resize 100px. right", 400, 94, 396, 296) $a_idCombo[5] = GUICtrlCreateCombo("", 2, 122, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[5], 0x00FFFF, 0x0000FF, 1) Example_FillTheCombo($a_idCombo[5]) GUICtrlCreateLabel("<<< change colors, resize auto left", 400, 124, 396, 296) $a_idCombo[6] = GUICtrlCreateCombo("", 2, 152, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($a_idCombo[6], 10, 400, 0, "Courier New") GUICtrlComboSetColors($a_idCombo[6], Default, Default, "2;Courier New;10") Example_FillTheCombo($a_idCombo[6]) GUICtrlCreateLabel("<<< default colors, resize auto right", 400, 154, 396, 296) Local $bttnArrayShow = GUICtrlCreateButton("Show array", 2, 296 - 27, 75, 25) Local $bttnStrMore = GUICtrlCreateButton("Longer str.", 102, 296 - 27, 75, 25) Local $idLorem = GUICtrlCreateLabel("", 195, 296 - 27, 50, 25) Local $bttnStrLess = GUICtrlCreateButton("Shorter str.", 252, 296 - 27, 75, 25) GUISetState(@SW_SHOW) WinActivate("ComboBox Set DROPDOWNLIST BgColor") ;~ Sleep(3500) ; you can reassign colors, size, or restore default ;~ GUICtrlComboSetColors($idCombo5, Default, Default, 300) ; this resets the Control back to default and changes $iExtendLeft ;~ GUICtrlComboSetColors($idCombo5, 0x0000FF, 0x00FFFF, -1) ; this changes the colors and keeps $iExtendLeft as it was ;~ GUICtrlComboSetColors($idCombo5, -1, -1, 300) ; using "-1" will keep the existing colors ;~ ; so in this case, only the $iExtendLeft is declared ;~ Example_FillTheCombo($idCombo5) ;~ Sleep(500) ; after removal, it will not repaint "hList", but then again, you're deleteing the control ;~ GUICtrlComboSetColors($idColors, -3) ;~ GUICtrlDelete($idCombo2) Local $iLorem = 5, $sLorem = "" Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Return Case $bttnArrayShow _ArrayDisplay($g__aWM_CTLCOLORLISTBOX, "$g__aWM_CTLCOLORLISTBOX") Case $bttnStrMore $iLorem += 5 Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) Case $bttnStrLess $iLorem -= 5 Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) EndSwitch WEnd EndFunc ;==>Example Func Example_FillTheCombo(ByRef $idComboCtrl) GUICtrlSetData($idComboCtrl, "") _GUICtrlComboBox_AddString($idComboCtrl, "something") _GUICtrlComboBox_AddString($idComboCtrl, "something else") _GUICtrlComboBox_AddString($idComboCtrl, "blah, blah, blah, blah") _GUICtrlComboBox_AddString($idComboCtrl, "Lorem will change") Local $a = _GUICtrlComboBox_GetListArray($idComboCtrl) GUICtrlSetData($idComboCtrl, $a[1]) EndFunc ;==>Example_FillTheCombo Func Example_LoremStr(ByRef $iLorem, ByRef $sLorem, ByRef $a_idCombo, ByRef $idLorem) Local Static $s = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat." $s &= " Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat." Local Static $i = 5, $a = StringSplit($s, " ") If $iLorem < 1 Then $iLorem = 1 If $iLorem > $a[0] Then $iLorem = $a[0] Local $x, $iLastEntry $sLorem = "" GUICtrlSetData($idLorem, $iLorem & ' words') For $x = 1 To $iLorem $sLorem &= $a[$x] & " " Next For $x = 1 To $a_idCombo[0] $iLastEntry = _GUICtrlComboBox_GetCount($a_idCombo[$x]) - 1 _GUICtrlComboBox_DeleteString($a_idCombo[$x], $iLastEntry) _GUICtrlComboBox_AddString($a_idCombo[$x], $sLorem) Next EndFunc ;==>Example_LoremStr new in v0.0.0.5: auto size the dropdown.
    • kcvinu
      By kcvinu
      Hi all,
      How can i get notified when user clicks on a combo box's edit area ? This is my code so far. 
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <ComboConstants.au3> #include <ListBoxConstants.au3> Global $btn ; creates a window Global $Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) GUICtrlSetFont(-1,12,400) Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300) GUICtrlSetFont(-1,12,400) GUIRegisterMsg($WM_COMMAND, "MyEventCallback") GUIRegisterMsg($WM_SIZE, "MyEventCallback") GUIRegisterMsg($WM_NOTIFY, "NotifyManager") GUISetState(@SW_SHOW) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") Do $Event = GUIGetMsg( ) Until $Event = $GUI_EVENT_CLOSE Func MyEventCallback($hwnd, $message, $wParam, $lParam) Select Case $message = $WM_COMMAND ;---------------------------------------------------------------- If LoWord($wParam) = $cmb Then ; if control id is combox's Then Local $Notification = HiWord($wParam) Select Case $Notification = $CBN_DROPDOWN ; here we check the notification code. ConsoleWrite("$CBN_DROPDOWN Worked " & @MIN & ":" & @SEC & @CRLF) Case $Notification = $CBN_EDITCHANGE ; here we check the notification code. ConsoleWrite("$CBN_EDITCHANGE Worked " & @MIN & ":" & @SEC & @CRLF) ; **** Here i want add the code for combo box clicking. EndSelect ;--------------------------------------------------------------------- ElseIf LoWord($wParam) = $lstbx Then Local $Notification = HiWord($wParam) Select Case $Notification = $LBN_SELCHANGE ConsoleWrite("$LBN_SELCHANGE" & @CRLF) EndSelect EndIf ;------------------------------------------------------------------ Case $message = $WM_SIZE EndSelect Return $GUI_RUNDEFMSG EndFunc ;==>ProGUI_EventCallback Func NotifyManager($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ;Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If DllStructGetData($tagNMHDR, 3) = $NM_LDOWN Then ConsoleWrite("Notify Worked" & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc Func LoWord($Variable) Return BitAND($Variable, 0xFFFF) EndFunc Func HiWord($Variable) Return BitShift($Variable, 16) EndFunc