Jump to content
Sign in to follow this  
BJJ

Problem with ComboBox

Recommended Posts

BJJ

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

Opt("GuiOnEventMode", 1)

Global $aCombo[1]
Dim $sY = 10

$hGUI = GUICreate("Test GUI", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $i = 0 To UBound($aCombo) - 1
    $aCombo[$i] = GUICtrlCreateCombo("", 50, $sY, 100, 20)
    GUICtrlSetData(-1, "Item 1|Item 2|Item 3", "Item 1")
    GUICtrlSetOnEvent(-1, "_GetCurSel")
    $sY += 30
Next

GUISetState()

While 1
    Sleep(100)
WEnd

Func _GetCurSel()
    MsgBox(0, "Info", StringFormat("Current selected item: \nID: %s\nItem text: %s\nItem index: %s", _
                                    @GUI_CtrlId, GUICtrlRead(@GUI_CtrlId), GUICtrlSendMsg(@GUI_CtrlId, $CB_GETCURSEL, 0, 0)))
EndFunc

Func _Exit()
    GUIDelete($hGUI)
    Exit

EndFunc

I want see difrent MsgBox for any item

example

I have a list 7 items a,b,c,d,e,f,g, etc.

and 7 difrent msgbox's for a "hello" for b "hi" for c "aloha" etc.

when i click on c want see attributable msgbox

How change this code ??

Share this post


Link to post
Share on other sites
martin

Quzziy, Your script already does what I understand you want, so I must not understand what you want.

Do you mean you want a msgbox if you click on the caption in the combobox? If not then you need to give a bit more detail.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
BJJ

yes .. but difrent msgbox for any caption

Share this post


Link to post
Share on other sites
ResNullius

Like this?

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

Opt("GuiOnEventMode", 1)

Global $aCombo[1]
Dim $sY = 10

$hGUI = GUICreate("Test GUI", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $i = 0 To UBound($aCombo) - 1
    $aCombo[$i] = GUICtrlCreateCombo("", 50, $sY, 100, 20)
    GUICtrlSetData(-1, "Item 1|Item 2|Item 3", "Item 1")
    GUICtrlSetOnEvent(-1, "_GetCurSel")
    $sY += 30
Next

GUISetState()

While 1
    Sleep(100)
WEnd

Func _GetCurSel()
    Local $msgText

        Switch GUICtrlRead(@GUI_CtrlId)
            Case "Item 1" 
                $msgText = "Hello"
            Case "Item 2"
                $msgText = "Hi"
            Case "Item 3"
                $msgText = "BYE"
        EndSwitch
            
        MsgBox(0,"Info", $msgText)
        
EndFunc

Func _Exit()
    GUIDelete($hGUI)
    Exit

EndFunc

Share this post


Link to post
Share on other sites
BJJ

Wonderfull :)

This work brilaint

Thx

Share this post


Link to post
Share on other sites
BJJ

But hmm ..how use gui in place of $msgText = "Hello" ??

Share this post


Link to post
Share on other sites
ResNullius

But hmm ..how use gui in place of $msgText = "Hello" ??

Do you mean to display a custom gui depending on what the combobox selection is?

If so, would the gui for each case be very similar with just different text, or would it be a completely different gui (size, buttons, colour, etc) for each different selection?

Share this post


Link to post
Share on other sites
BJJ

I want make each GUI for any item frome combobox

If that be easy i can make one exemplary GUI for any item frome Combobox but use difrent background picture

Share this post


Link to post
Share on other sites
ResNullius

I want make each GUI for any item frome combobox

If that be easy i can make one exemplary GUI for any item frome Combobox but use difrent background picture

Well, depending on how dynamic you want the gui to be, I would look at something like this

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

Opt("GuiOnEventMode", 1)

Global $aCombo[1]
Dim $sY = 10

$hGUI = GUICreate("Test GUI", 350, 200)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Pic1 = GUICtrlCreatePic(@WindowsDir & "\Gone Fishing.bmp", 0, 0, 350, 200, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
GUICtrlSetState(-1, $GUI_DISABLE)

For $i = 0 To UBound($aCombo) - 1
    $aCombo[$i] = GUICtrlCreateCombo("", 50, $sY, 100, 20)
    GUICtrlSetData(-1, "Fishing|Rhododendron|Sumida", "Fishing")
    GUICtrlSetOnEvent(-1, "_GetCurSel")
    $sY += 30
Next

GUISetState()

While 1
    Sleep(10)
WEnd

Func _GetCurSel()
    Local $msgText

    Switch GUICtrlRead(@GUI_CtrlId)
        Case "Fishing"
            GUICtrlSetImage($Pic1, @WindowsDir & "\Gone Fishing.bmp")
        Case "Rhododendron"
            GUICtrlSetImage($Pic1, @WindowsDir & "\Rhododendron.bmp")
        Case "Sumida"
            GUICtrlSetImage($Pic1, @WindowsDir & "\River Sumida.bmp")
    EndSwitch

EndFunc  ;==>_GetCurSel

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc  ;==>_Exit

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  

×