Jump to content
Sign in to follow this  
SlowCoder74

Sending a message to GUIGetMsg to simulate ComboBox selection change

Recommended Posts

SlowCoder74

Sample code:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 405, 284, 343, 1121)
$Combo1 = GUICtrlCreateCombo("", 24, 8, 113, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Item1|Item2")
$Button1 = GUICtrlCreateButton("Simulate", 24, 40, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
            msgbox(0,"","Selection changed!")
        Case $Button1 ;simulate combobox selection change
            ControlClick($Form2,"",$Combo1)
    EndSwitch
WEnd

My desired outcome is to simulate a click on the combobox so that a gui message is sent and the messagebox appears.  What actually happens is that the combobox drops down.

I don't want to have to create a separate function that needs to be called from each point in the code, if I can help it.

Share this post


Link to post
Share on other sites
FireFox

Hi,

If you click on the ComboBox you don't change the selection.

If you want to fire a MsgBox when the combo is clicked then do :

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2");, 405, 284, 343, 1121)
$Combo1 = GUICtrlCreateCombo("", 24, 8, 113, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Item1|Item2")
$Button1 = GUICtrlCreateButton("Simulate", 24, 40, 65, 25)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1

        Case $Button1 ;simulate combobox selection change
            ControlClick($Form2, "", $Combo1)
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF)
    Local $iCode = BitShift($wParam, 16)

    Switch $iIDFrom
        Case $Combo1
            Switch $iCode
                Case $CBN_DROPDOWN
                    MsgBox(0, "", "Selection changed!")
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
SlowCoder74

Hi,

If you click on the ComboBox you don't change the selection.

If you want to fire a MsgBox when the combo is clicked then do :

 

Well, I wasn't trying to actually click the combobox.  I know ControlClick isn't what I wanted to do.  I want to create a GUI message so that it's picked up by GUIGetMsg as if the combobox value has been changed.

If you're familiar with VB, an event procedure is created for a control object, e.g. MyControl_Click, that would fire when you clicked the MyControl control.  Or you could simply call it as a sub from code.

I need to see if I can get a solution that does not require the building of a separate function.  Any other options?

Share this post


Link to post
Share on other sites
BrewManNH

Why?


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
SlowCoder74

Why?

I figured that question was coming. :ermm:

This is a multi-form project.

example (main form):

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 180, 120, 345, 935)
$Button1 = GUICtrlCreateButton("Button1", 8, 8, 97, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            #include "myincludeforbutton1.au3"
    EndSwitch
WEnd

myincludeforbutton1.au3 (2nd level form):

... form drawing code ...
... 2nd loop to handle 2nd form messages, etc ...

Due to the size of project code, and in attempt to keep myself sane, I've split the code into multiple includes.  The includes contain the form creation and loops for each new form/window.  Unfortunately, I cannot create a function within one of the includes, because procedurally, they are inside at least one loop (switch).  To create a function, I would need to put it in the 1st level code file.  This makes the code feel disorganized.  It's not that it couldn't work, but I want to prevent it if I can.

Share this post


Link to post
Share on other sites
BrewManNH

I figured that question was coming. :ermm:

 

This is a multi-form project.

 

example (main form):

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 180, 120, 345, 935)
$Button1 = GUICtrlCreateButton("Button1", 8, 8, 97, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            #include "myincludeforbutton1.au3"
    EndSwitch
WEnd
myincludeforbutton1.au3 (2nd level form):

As I am sure you found out, or will find out after trying to run that, you shouldn't put an include in the middle of your script, and especially not inside a loop like that.

 

Due to the size of project code, and in attempt to keep myself sane, I've split the code into multiple includes.  The includes contain the form creation and loops for each new form/window.  Unfortunately, I cannot create a function within one of the includes, because procedurally, they are inside at least one loop (switch).  To create a function, I would need to put it in the 1st level code file.  This makes the code feel disorganized.  It's not that it couldn't work, but I want to prevent it if I can.

Don't be penny wise and pound foolish, create your code inside functions, add the functions into your include files, put the #include lines at the top of your script. Use the function calls where needed. Right now, you're making it MUCH more difficult for yourself or anyone else to follow that spaghetti code 2 weeks down the road, let alone 2 years down the road. Edited by BrewManNH
  • Like 1

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
SlowCoder74

Don't be penny wise and pound foolish, create your code inside functions, add the functions into your include files, put the #include lines at the top of your script. Use the function calls where needed. Right now, you're making it MUCH more difficult for yourself or anyone else to follow that spaghetti code 2 weeks down the road, let alone 2 years down the road.

BrewManNH,

I went ahead and tried what you suggested on another part of the project, (separate program), and now see what you are explaining.  It was easy to code.  Thank you.

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  

×