Label Größe dynamisch anpassen

  • Gibt es eine Möglichkeit das Label dynamisch an die GUI bzw. ans Group Control anzupassen, so dass beim Vergrößern bzw. Verkleinern (inkl. maximieren/minimieren des Fensters) das Label enstprechend vergrößert / verkleinert wird?

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <StructureConstants.au3>
    #include <WindowsConstants.au3>
    Global $hGUI = GUICreate("Test", 800, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_TABSTOP))
    Global $group = GUICtrlCreateGroup("", 224, 0, 569, 92)
    Global $title = GUICtrlCreateLabel("Label soll sich dyn. anpassen", 228, 14, 559, 75)

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

    GUICtrlSetColor(-1, 0x000080)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState(@SW_SHOW)

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

    Resize_Font()

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

    Global $aWDim = WinGetPos($hGUI)
    Global $w = $aWDim[2], $h = $aWDim[3]
    GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    GUIDelete($hGUI)
    Exit
    Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
    Resize_Font()
    EndSwitch
    WEnd

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

    Func Resize_Font()
    $aPOS = ControlGetPos("", "", $group)
    GUICtrlSetFont($title, $aPOS[2] / 17, 400, 0, "Impact")
    EndFunc

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

    Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    Resize_Font()
    Return "GUI_RUNDEFMSG"
    EndFunc

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

    Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, $w) ; min X
    DllStructSetData($minmaxinfo, 8, $h) ; min Y
    Return "GUI_RUNDEFMSG"
    EndFunc ;==>WM_GETMINMAXINFO

    [/autoit]


    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    5 Mal editiert, zuletzt von UEZ (10. Februar 2011 um 16:51)

  • Hallo UEZ,

    du kannst doch auf die verschiedenen GUI_EVENTS reagieren:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    Global $hGUI = GUICreate("Test", 800, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_TABSTOP))
    Global $group = GUICtrlCreateGroup("", 224, 0, 569, 92)
    Global $title = GUICtrlCreateLabel("Label soll sich dyn. anpassen", 228, 14, 559, 75)
    GUICtrlSetColor(-1, 0x000080)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState(@SW_SHOW)
    $aPOS = ControlGetPos("", "", $group)
    GUICtrlSetFont($title, $aPOS[2] / 16, 400, 0, "Impact")

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

    Global $aWDim = WinGetPos($hGUI)
    Global $w = $aWDim[2], $h = $aWDim[3]
    GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    GUIDelete($hGUI)
    Exit
    Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
    MsgBox(0,"Hier","neuen Font berechnen und setzen")
    EndSwitch
    WEnd

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

    Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, $w) ; min X
    DllStructSetData($minmaxinfo, 8, $h) ; min Y
    Return "GUI_RUNDEFMSG"
    EndFunc ;==>WM_GETMINMAXINFO

    [/autoit]

    wobei dann WM_GETMINMAXINFO überflüsig sein sollte,

    mfg autoBert

  • oder meinst du

    [autoit]

    Global $title = GUICtrlCreateLabel("Label soll sich dyn. anpassen", 228, 14, 559, 75)
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO);ggf andere "Docking Values"

    [/autoit]
  • Die Schrift soll immer im Verhältnis zum Group Control stehen, so dass die Größe der Schrift sich mit dem Group Control beim Vergrößern / Verkleinern anpasst.

    Beispiel: wenn ich das Fenster maximiere, so vergrößert sich das Group Control, aber die Schrift bleibt gleich (kleiner)!

    Ich hoffe, dass es jetzt ein wenig klarer ist.

    Andy: das mit den GUICtrlSetResizing() Einstellungen funzt nicht, da nur das Label verschoben, aber nicht entsprechend skaliert wird.

    autoBert: danach habe ich auch gesucht. Danke!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Ich habe mal den Code aus meinem ersten Post angepasst.

    So ähnlich soll es sein, aber vielleicht etwas eleganter.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Das kommt der Sacher näher, aber die Schrift sieht nun mist aus:

    Spoiler anzeigen
    [autoit]


    #include <Array.au3>
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>

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

    _GDIPlus_Startup()
    Global $hGUI = GUICreate("Test", 800, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_MAXIMIZEBOX))
    Global $group = GUICtrlCreateGroup("", 224, 0, 569, 92)
    Global $pic = GUICtrlCreatePic("", 226, 8, 565, 82)
    GUICtrlSetResizing(-1, $GUI_DOCKVCENTER + $GUI_DOCKHCENTER)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $hBmp = CreateLogo("Label soll sich dyn. anpassen", "Impact")
    Global Const $STM_SETIMAGE = 0x0172
    GUICtrlSendMsg($Pic, $STM_SETIMAGE, 0, $hBmp)
    GUISetState(@SW_SHOW)

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

    Global $aWDim = WinGetPos($hGUI)
    Global $w = $aWDim[2], $h = $aWDim[3]
    GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _WinAPI_DeleteObject($hBmp)
    GUIDelete($hGUI)
    _GDIPlus_Shutdown()
    Exit
    Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
    EndSwitch
    WEnd

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

    Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, $w) ; min X
    DllStructSetData($minmaxinfo, 8, $h) ; min Y
    Return "GUI_RUNDEFMSG"
    EndFunc ;==>WM_GETMINMAXINFO

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

    Func CreateLogo($text, $fname, $fsize = 60, $brushcolor = 0xFF000080)
    Local $hBrush = _GDIPlus_BrushCreateSolid($brushcolor)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $tLayout = _GDIPlus_RectFCreate (0, 0, 0, 0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($fname)
    Local $hFont = _GDIPlus_FontCreate ($hFamily, $fsize, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $text, $hFont, $tLayout, $hFormat)
    Local $width = Floor(DllStructGetData($aInfo[0], "Width") * 0.98)
    Local $height = Floor(DllStructGetData($aInfo[0], "Height") * 0.925)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($width, $height)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    _GDIPlus_GraphicsClear($hContext, "0xFF" & Hex(_WinAPI_GetSysColor($COLOR_3DFACE), 6))
    _GDIPlus_GraphicsDrawStringEx ($hContext, $text, $hFont, $aInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hContext)
    Local $hImage = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_ImageDispose($hBitmap)
    Return $hImage
    EndFunc

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

    Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

    [/autoit]

    Vielleicht bekomme es auch noch hin, dass die Schrift "sauber" aussieht.

    Ich weiß nicht, ob das noch besser geht!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (8. Februar 2011 um 23:17)

  • Bin zwar kein Experte in GDI (und kann daher auf die schnelle keinen Code posten :) ), aber wie wäre es mit DoubleBuffering und das Zoomen dann per WM_SIZING zu triggern?

  • Ich wollte eigentlich mal kein GDI+ direkt verwenden.

    Alle anderen Controls werden auch entsprechend "gesized", also warum auch nicht ein Label Control? Anscheinend geht das nicht so einfach. Ich finde das optisch nicht schön, wenn man die Größe des Fensters verändert und nur das Label gleich bleibt.

    Suche weiter...

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯