Array Problem

  • Hallo,

    ich muß eine Nr. auslesen.
    Jeder klick auf den Button zeigt mir die Nr. des Controls. OK!

    Folgendes:
    Wenn ich bei dem Button (Beispiel: die Main() Funktion
    aktiviere, bekomme ich keine Nummer sondern True.

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    Global $aLabel[1], $Label
    $x = 140
    $y = 110

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    $Button1 = GUICtrlCreateButton("Label Nr", 408, 352, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Case $Button1
    ;_Main()
    $aLabel[UBound($aLabel) - 1] = GUICtrlCreateLabel("Test", $x, $y, 146, 89)
    $Label = $aLabel[UBound($aLabel) - 1]
    Msgbox(0,"$Label",$Label)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Main()
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    Local $sString = "Hello world", $aInfo

    [/autoit] [autoit][/autoit] [autoit]

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ; Draw a string
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid (0xFF00007F)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate (140, 110, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $aLabel[UBound($aLabel) - 1] = _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    $Label = $aLabel[UBound($aLabel) - 1]
    Msgbox(0,"$Label GDI",$Label)
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit] [autoit][/autoit] [autoit]

    ; Clean up resources
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_Main

    [/autoit]

    Ich glaube hier liegt irgendwo der Fehler

    [autoit]


    $aLabel[UBound($aLabel) - 1] = _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    $Label = $aLabel[UBound($aLabel) - 1]
    Msgbox(0,"$Label GDI",$Label)

    [/autoit]

    Ich brauche später den Zahlenwert damit ich die Strings v. GDI ermitteln kann.
    Zum testen einfach ;_Main() aktivieren


    Grüße
    Ilse ;)

    Einmal editiert, zuletzt von Ilse (3. August 2012 um 16:51)

    • Offizieller Beitrag

    1. Dein Array mit den Controlids wird immer nur 1 Element haben, weil du nirgends das Array erweiterst.
    2. Du Überschreibst die Ctrlid im Array mit dem Rückgabewert von _GDIPlus_GraphicsDrawStringEx , wenn die Funktion
    erfolgreich war ist dessen Rückgabe = TRUE.