Sign in to follow this  
Followers 0
UEZ

[Solved] Scale label

6 posts in this topic

#1 ·  Posted (edited)

Is there a better and smoother way to scale label as I did in the code below?

#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))
Global $group = GUICtrlCreateGroup("", 224, 0, 569, 92)
Global $title = GUICtrlCreateLabel("Scale this label dynamically ", 228, 14, 559, 75)
 
GUICtrlSetColor(-1, 0x000080)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
 
Resize_Font()
 
Global $aWDim = WinGetPos($hGUI)
Global $w = $aWDim[2], $h = $aWDim[3]
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
 
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
 
Func Resize_Font()
    $aPOS = ControlGetPos("", "", $group)
    GUICtrlSetFont($title, $aPOS[2] / 16, 400, 0, "Impact")
EndFunc
 
Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    Resize_Font()
    Return "GUI_RUNDEFMSG"
EndFunc
 
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

What I want is when I resize the window the label should be scaled appropriately with group control size that it fits to the group control as when starting the code.

Any suggestions?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ignore, I got it wrong! Sorry.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Did not understand 100%, did you mean something like

GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

I tried it also with GUI_DOCK* but is not working properly.

The width and height of label will become larger than the group control size and further it is not scaling smoothly.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hell if i know what i am dooing

#include <GUIConstantsEx.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
Global $hGUI = GUICreate("Test", 900, 250, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX))
Global $group = GUICtrlCreateGroup("", 224, 0, 600, 100)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM) 

Global $title = GUICtrlCreateLabel("Scale this label dynamically ", 226, 14, 589, 75)
GUICtrlSetResizing(-1,$GUI_DOCKTOP+$GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM) 

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

Resize_Font()

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

While 1
    $pos = ControlGetPos($hGUI, "", $group)
    $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

Func Resize_Font()
    $aPOS = ControlGetPos("", "", $group)
    If $aPOS[2] / $aPOS[3] < 6 Then
        GUICtrlSetFont($title, $aPOS[2] / 16, 400, 0, "Impact")
    Else
        GUICtrlSetFont($title, (($aPOS[2] / 16)-(($aPOS[2] / $aPOS[3])-6)*6)-(($aPOS[2]-600)*0.0025)+0.0025, 400, 0, "Impact")
    EndIf
EndFunc

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

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

At least il get order for bravery even if thats not it :)

I did change some sizes and positions

Edit: your problem is that font is ower the limit?

or only not scaling smoothly is problem?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks bogQ for you version! I will have a closer look tomorrow.

Meanwhile I got a new idea but the scaling within the group control is not working properly:

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

_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)

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


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

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

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

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

If I could position the label (pic) within the group control it would be great.

This was what I was looking for!

Last little issue is the ugly looking label... Now it looks better but can it be still look better?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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  
Followers 0