Jump to content

Recommended Posts

Posted (edited)

Hey there,

I have got a problem with a Combobox with $CBS_DROPDOWNLIST Style...

If i read it in a while for adding another year the value of the combobox is already changed if "add" is hovered and the inputbox appears, but i want it even when i pressed on "add"

any suggestions?

#include <GUIConstantsEx.au3>
#include<ComboConstants.au3>
    $GUI = GUICreate("blah", @DesktopWidth-200, @DesktopHeight-100, -1, -1)
    $YEAR_LABEL_1 = GUICtrlCreateLabel("year",(@DesktopWidth-200) / 2 - 120 , 8,60, 32)
    $year_combo = GUICtrlCreateCombo(@YEAR ,(@DesktopWidth-200) / 2 - 50 , 5, 80, 32, $CBS_DROPDOWNLIST )
    GUICtrlSetData (-1,"2018|2017|add" )
        GUISetState(@SW_SHOW, $GUI)

    While 1
    If GUICtrlRead ( $year_combo ) = "add" Then InputBox("new","","" )
    $nmsg = GUIGetMsg ()
    Switch $nmsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $YEAR_LABEL_1
    EndSwitch
    WEnd

 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Posted

@FrancescoDiMuro

Yea i'm actually trying, but i fail to get the text. I just see in the helpfile:

Quote

Remarks

If the message is sent to a ComboBox with the $CBS_DROPDOWN or $CBS_DROPDOWNLIST style the Function will fail.

 

So how can i get it ?

 

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
Global $g_hCombo

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
    $g_hCombo = _GUICtrlComboBox_Create($hGUI, "2019|2018|2017|add", 2, 2, 396, 296,$CBS_DROPDOWNLIST)
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    Do
;~  MsgBox ( 64,"",GUICtrlRead ( $g_hCombo ) & @CRLF & _GUICtrlComboBox_GetEditText ( $g_hCombo ) )
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $g_hCombo
            Switch $iCode
                Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list
                    If  _GUICtrlComboBox_GetEditText ( $g_hCombo ) = "add" Then InputBox ( "","" )
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

why do i get garbage when i buy garbage bags? <_<

Posted

So complicated - what the hell :hyper: so sad i can't use simply 

_GUICtrlComboBox_GetEditText ( $g_hCombo )

well but i got it

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
Global $g_hCombo

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
    $g_hCombo = _GUICtrlComboBox_Create($hGUI, "2019|2018|2017|add", 2, 2, 396, 296,BitOR($CBS_DROPDOWNLIST,$CBS_SORT ))
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF)
    $iCode = BitShift($wParam, 16)
    Switch $hWndFrom
        Case $g_hCombo
            Switch $iCode
                Case $CBN_SELENDOK
                    $sText = _GUICtrlCombobox_GetCurSel ( $g_hCombo )
                    $count = _GUICtrlComboBox_GetCount ( $g_hCombo )
                    If $sText = $count -1  Then
                        $new = InputBox ( "","" )
                        _GUICtrlComboBox_BeginUpdate ( $g_hCombo )
                        _GUICtrlComboBox_AddString ( $g_hCombo,$new )
                        _GUICtrlComboBox_EndUpdate ( $g_hCombo )
                    EndIf

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

that works for me as long i have the $CBS_SORT Style...

Thank You :) 

why do i get garbage when i buy garbage bags? <_<

Posted (edited)

@Aelc
Use _GUICtrlComboBox_GetLBText() instead of the For...Loop:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
Global $g_hCombo

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
    $g_hCombo = _GUICtrlComboBox_Create($hGUI, "2019|2018|2017|add", 2, 2, 396, 296,$CBS_DROPDOWNLIST)
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    Do
;~  MsgBox ( 64,"",GUICtrlRead ( $g_hCombo ) & @CRLF & _GUICtrlComboBox_GetEditText ( $g_hCombo ) )
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $strComboBoxText = "", $strNewComboBoxItem = ""
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $g_hCombo
            Switch $iCode
                Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list

                    ; Get the current selected text
                    _GUICtrlComboBox_GetLBText($g_hCombo, _GUICtrlComboBox_GetCurSel($g_hCombo), $strComboBoxText)

                    ; Compairing the text (case-sensitive)
                    If $strComboBoxText == "add" Then

                        ; Set the current selection to display the previous item of the latest one in the ComboBox (to prevent display "add")
                        _GUICtrlComboBox_SetCurSel($g_hCombo, _GUICtrlComboBox_GetCount($g_hCombo) - 2)

                        ; New item text to add at the ComboBox
                        $strNewComboBoxItem = InputBox("Insert New ComboBox Item: ", "")

                        ; If the user doesn't press "Cancel"
                        If Not @error Then
                            _GUICtrlComboBox_AddString($g_hCombo, $strNewComboBoxItem)                      ; Add the string
                            _GUICtrlComboBox_DeleteString($g_hCombo, _GUICtrlComboBox_GetCurSel($g_hCombo)) ; The string "add" is deleted to be added again at the end of the list of ComboBox items
                            _GUICtrlComboBox_SetCurSel($g_hCombo, _GUICtrlComboBox_GetCount($g_hCombo) - 1) ; Set the current selection to display the latest item in the ComboBox
                            _GUICtrlComboBox_AddString($g_hCombo, "add")                                    ; Insert again the string "add" to let the user to add another string
                        EndIf
                    EndIf


            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted (edited)

Hmm your script looks like an easier way

but it doesn't delete the add string and there are multiple 'add' strings in the combo in my test :o. I actually don't even know why because there is already a _deletestring...

this works in my test :

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#include <FontConstants.au3>
#include <StaticConstants.au3>

Global $g_hCombo

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF) ComboBox Create", 800, 296)
    $YEAR_LABEL_1 = GUICtrlCreateLabel("Year",2 , 8,60, 32, BitOR ( $SS_RIGHT,$SS_CENTERIMAGE) )
    GUICtrlSetFont(-1, 20, 1200, 0, "Arial", 5)
    $g_hCombo = _GUICtrlComboBox_Create($hGUI, "2019|2018|2017|add",70, 4, 100, 296,$CBS_DROPDOWNLIST)
    _GUICtrlComboBox_SetCurSel ( $g_hCombo,0 )
    $font = _WinAPI_CreateFont ( 32,13,0,0,900,False,False,False,$DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS,$CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'ComboArial' )
    _WinAPI_SetFont ( $g_hCombo,$font)
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    Do
;~  MsgBox ( 64,"",GUICtrlRead ( $g_hCombo ) & @CRLF & _GUICtrlComboBox_GetEditText ( $g_hCombo ) )
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $strComboBoxText = "", $strNewComboBoxItem = ""
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $g_hCombo
            Switch $iCode
                Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list

                    ; Get the current selected text
                    _GUICtrlComboBox_GetLBText($g_hCombo, _GUICtrlComboBox_GetCurSel($g_hCombo), $strComboBoxText)

                    ; Compairing the text (case-sensitive)
                    If $strComboBoxText == "add" Then

                        ; Set the current selection to display the previous item of the latest one in the ComboBox (to prevent display "add")
;~                         _GUICtrlComboBox_SetCurSel($g_hCombo, _GUICtrlComboBox_GetCount($g_hCombo) - 2)

                        ; New item text to add at the ComboBox
                        $strNewComboBoxItem = InputBox("Insert New ComboBox Item: ", "")

                        ; If the user doesn't press "Cancel"
                        If Not @error Then
                            _GUICtrlComboBox_DeleteString($g_hCombo, _GUICtrlComboBox_GetCount($g_hCombo))
                            _GUICtrlComboBox_AddString($g_hCombo, $strNewComboBoxItem)                      ; Add the string
                            _GUICtrlComboBox_DeleteString($g_hCombo, _GUICtrlComboBox_GetCurSel($g_hCombo)) ; The string "add" is deleted to be added again at the end of the list of ComboBox items
                            _GUICtrlComboBox_SetCurSel($g_hCombo, _GUICtrlComboBox_GetCount($g_hCombo) - 1) ; Set the current selection to display the latest item in the ComboBox
                            _GUICtrlComboBox_AddString($g_hCombo, "add")                                    ; Insert again the string "add" to let the user to add another string
                        EndIf
                    EndIf


            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

But at least it doesn't really matter because i have to sort it - it shall be chronological.

I'm trying now, to get the same font on it like my label that stands before. And it's actually a header in my main GUI

And because GUICtrlsetfont don't work i have to _winapi_createfont right? or is there another way ? i mean it works but it takes a long time to adjust the font and compare them....

 

Still thank you :):D 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...