GDIPlus MeasureString

  • Hallo!

    Ich würde gerne mit der Funktion _GDIPlus_GraphicsMeasureString die Breite eines Strings in Pixeln rausfinden, allerdings überschreitet der Rückgabewert nie die Breite des Graphics-Objekt im ersten Parameter der Funktion.
    Gibt es eine Möglichkeit, trotzdem die "wirkliche", ganze Breite rauszufinden?

    Gruß Syne

  • joa das geht :D


    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>

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

    $GUI = GUICreate("")

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

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($GUI)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "Ich bin ein string" , $hFont, $tLayout, $hFormat)
    $width = DllStructGetData($aInfo[0], "width")
    MsgBox(0, "", $width)

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

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()

    [/autoit]
  • Genau da liegt ja das Problem! :P
    Wenn "Ich bin ein string" länger wird und breiter als die GUI ist, steht im Struct trotzdem nur ungefähr die Breite der GUI, obwohl der String offensichtlich darüber rausgeht.. :O

  • aso dan hab ich das falsch verstanden :D
    muss ich ma probieren

    hmm bei mir is das nich so

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>

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

    $GUI = GUICreate("", 300, 300)
    GUISetState()

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

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($GUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "Ich bin ein string :DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" , $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, "Ich bin ein string :DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", $hFont, $aInfo[0], $hFormat, $hBrush)

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

    $width = DllStructGetData($aInfo[0], "width")
    MsgBox(0, "", $width)

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

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()

    [/autoit]


    änder mal die breite der gui
    da verändert sich nix
    hast du das vll über nen buffer laufen?

  • yxyx: Richtig, das Ganze läuft über nen Buffer, allerdings bleibt der Wert auch gleich, wenn ich ein anderes Graphicsobjekt nehme.

    Komisch, der TextMeter gibt mir die richtige Größe für den Text aus..