Jump to content



Photo

Control Resize


  • Please log in to reply
13 replies to this topic

#1 PhoenixXL

PhoenixXL

    be what you are, its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,337 posts

Posted 23 May 2012 - 12:34 PM

Hey Every1

Is it Possible to Resize a Label
Reason: Using GuiCtrlSetData when the Text is Too Long it Doesn't Fit the Label and is not Displayed
If its possible to Resize the Label a Offset Could be Created and The Text Would Also be Able to get Displayed

Thnx for Your Time ;)

Regards
Phoenix XL

Edited by PhoenixXL, 23 May 2012 - 12:36 PM.

PredictText: Predict Text of an Edit Control Like Scite. | Remote Gmail: Execute your Scripts through Gmail. | StringRegExp: Share and learn RegExp. | Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). | Database: An easier approach for _SQ_LITE beginners. | MathsEx: A UDF for Fractions and LCM, GCF/HCF. | FloatingText: An UDF for make your text floating. | Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead.







#2 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,877 posts

Posted 23 May 2012 - 01:00 PM

Look at Melba23's StringSize UDF in the Example Scripts section, with that you send it the text you want to display, the font and size of the font and it will return a value to be used for a control.

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#3 UEZ

UEZ

    Never say never

  • MVPs
  • 3,619 posts

Posted 23 May 2012 - 02:58 PM

I don't know whether this is a good approach here:
AutoIt         
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI = GUICreate("Test", 800, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX), $WS_EX_COMPOSITED) Global $idGroup = GUICtrlCreateGroup("", 224, 0, 569, 92) Global $sLabel = "Scale this label dynamically" Global $fFontsize, $sFont = "Impact" Global $idLabel = GUICtrlCreateLabel($sLabel, 228, 14,  563, 76, $SS_CENTER) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetColor(-1, 0x000080) Global $idLabelDummy = GUICtrlCreateLabel("", 228, 14,  563, 76) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) Resize_Font() GUISetState(@SW_SHOW) Global $aWDim = WinGetPos($hGUI) Global $w = $aWDim[2], $h = $aWDim[3] GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             GUIRegisterMsg($WM_GETMINMAXINFO, "")             GUIRegisterMsg($WM_SIZE, "")             GUIDelete($hGUI)             _GDIPlus_Shutdown()             Exit         Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE             Resize_Font()     EndSwitch WEnd Func Resize_Font()     $aPOS = ControlGetPos($hGUI, "", $idLabelDummy)     GUICtrlSetPos($idLabel, $aPOS[0] + 2, $aPOS[1] + 8, $aPOS[2] - 6, $aPOS[3] - 12)     $fFontsize = CalcFontSize($sLabel, $aPOS[2] - 6, $aPOS[3] - 12, $sFont)     GUICtrlSetFont($idLabel, $fFontsize, 400, 0, $sFont, 5) EndFunc Func CalcFontSize($sString, $iW, $iH, $sFont)     Local $aResult, $hFont, $i, $iLen = StringLen($sString)     Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))     Local $tRectF = DllStructCreate($tagGDIPRECTF)     Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)     Local $hFormat = _GDIPlus_StringFormatCreate()     Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)     $i = 1     Do         $hFont = _GDIPlus_FontCreate($hFamily, $i, 0)         $aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", "handle", $hGfx, "wstr", $sString, "int", -1, "handle", $hFont, "struct*", $tLayout, "handle", $hFormat, "struct*", $tRectF, "int*", 0, "int*", 0)         _GDIPlus_FontDispose($hFont)         If $aResult[8] <  $iLen Or $aResult[9] = 2 Or $i > $iH / 1.45 Then ExitLoop         $i += 1     Until False     _GDIPlus_FontFamilyDispose($hFamily)     _GDIPlus_StringFormatDispose($hFormat)     _GDIPlus_GraphicsDispose($hGfx)     $tLayout  = 0     Return $i 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 W         DllStructSetData($minmaxinfo, 8, $h) ; min H     Return "GUI_RUNDEFMSG" EndFunc   ;==>WM_GETMINMAXINFO


But you can try it.

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#4 JScript

JScript

    Goodbye everybody, I got tired of this system adopted here!

  • Active Members
  • PipPipPipPipPipPip
  • 1,062 posts

Posted 23 May 2012 - 03:15 PM

Probably what he wants is this:
AutoIt         
; ##### JScript - 23/05/2012 ##### #include <GUIConstantsEx.au3> Example() Func Example()     Local $msg, $iLabel     GUICreate("My GUI", 360, 240) ; will create a dialog box that when displayed is centered     $iLabel = GUICtrlCreateLabel("Initial text...", 10, 30)     GUISetState() ; will display an empty dialog box     Sleep(2000)     _GUILabelSetText($iLabel, "This is the second text into the label control, fit!")     Sleep(2000)     _GUILabelSetText($iLabel, "This is the third text will be fully visible in label control, Autoit is the best!")     ; Run the GUI until the dialog is closed     Do         $msg = GUIGetMsg()     Until $msg = $GUI_EVENT_CLOSE EndFunc   ;==>Example Func _GUILabelSetText($iCtrlID, $sText)     Local $asSize     $asSize = _StringSize($sText)     ControlMove("", "", $iCtrlID, Default, Default, $asSize[0], $asSize[1])     Return GUICtrlSetData($iCtrlID, $sText) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _StringSize ; Description ...: Returns the size (in pixels) of an string. ; Syntax.........: _StringSize( "string" [, size [, weight [, fontname ]]] ) ; Parameters ....: string   - The string to evaluate the size. ;                 Size   - [Optional] Fontsize (default is 9). ;                 Weight     - [Optional] Font weight (default 400 = normal). ;                 FontName  - [Optional] Font to use (OS default GUI font is used if the font is "" or is not found). ; Requirement(s).: ; Return values .: Success   - Returns a 2-element array containing the following information: ;                           $array[0] = Width ;                           $array[1] = Height ;                  Failure   - Returns the same array with 0 and sets @error to 1. ; Author ........: jscript ; Example .......: _StringSize( "Text" ) ; =============================================================================================================================== Func _StringSize($sString, $iSize = 9, $iWeight = 400, $sFontName = "")     Local $hWnd, $hGuiSwitch, $iCtrlID, $aCtrlSize, $aRetSize[2] = [0, 0]     $hWnd = GUICreate("StringExInternalWin", 0, 0, 0, 0, BitOR(0x80000000, 0x20000000), BitOR(0x00000080, 0x00000020))     $hGuiSwitch = GUISwitch($hWnd)     If $iSize = 65535 Then ; Used by _ImageSize         $iCtrlID = GUICtrlCreatePic($sString, 0, 0, 0, 0)     Else         GUISetFont($iSize, $iWeight, -1, $sFontName, $hWnd)         $iCtrlID = GUICtrlCreateLabel($sString, 0, 0)     EndIf     $aCtrlSize = ControlGetPos($hWnd, "", $iCtrlID)     GUIDelete($hWnd)     GUISwitch($hGuiSwitch)     If IsArray($aCtrlSize) Then         $aRetSize[0] = $aCtrlSize[2]; Width         $aRetSize[1] = $aCtrlSize[3]; Height         Return SetError(0, 0, $aRetSize)     EndIf     Return SetError(1, 0, $aRetSize) EndFunc   ;==>_StringSize

Regards,

João Carlos.

Edited by JScript, 23 May 2012 - 03:15 PM.

http://notebook.forumais.com (Forum Maintenance Notebooks and Desktop)http://autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Spoiler

Posted Image Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!       


#5 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,323 posts

Posted 23 May 2012 - 03:23 PM

@PhoenixXL

What about decapitalizing?

#6 UEZ

UEZ

    Never say never

  • MVPs
  • 3,619 posts

Posted 23 May 2012 - 03:35 PM

@JScript: you are probably right but the code can be adjusted easily:

AutoIt         
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI = GUICreate("Test", 800, 200) Global $sLabel = "This is the 1st text" Global $fFontsize, $sFont = "Arial" Global $idLabel = GUICtrlCreateLabel($sLabel, 228, 14,  563, 76, $SS_CENTER) GUICtrlSetColor(-1, 0x000080) Resize_Font($sLabel, $idLabel) GUISetState(@SW_SHOW) Sleep(2000) $sLabel =  "And the one is the 2nd label text which is longer!" Resize_Font($sLabel, $idLabel) GUICtrlSetData($idLabel, $sLabel) While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             GUIDelete($hGUI)             _GDIPlus_Shutdown()             Exit     EndSwitch WEnd Func Resize_Font($sLabel, $idControl)     $aPOS = ControlGetPos($hGUI, "", $idControl)     $fFontsize = CalcFontSize($sLabel, $aPOS[2], $aPOS[3], $sFont)     GUICtrlSetFont($idLabel, $fFontsize, 400, 0, $sFont, 5) EndFunc Func CalcFontSize($sString, $iW, $iH, $sFont)     Local $aResult, $hFont, $i, $iLen = StringLen($sString)     Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))     Local $tRectF = DllStructCreate($tagGDIPRECTF)     Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)     Local $hFormat = _GDIPlus_StringFormatCreate()     Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)     $i = 1     Do         $hFont = _GDIPlus_FontCreate($hFamily, $i, 0)         $aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", "handle", $hGfx, "wstr", $sString, "int", -1, "handle", $hFont, "struct*", $tLayout, "handle", $hFormat, "struct*", $tRectF, "int*", 0, "int*", 0)         _GDIPlus_FontDispose($hFont)         If $aResult[8] <  $iLen Or $aResult[9] = 2 Or $i > $iH / 1.45 Then ExitLoop         $i += 1     Until False     _GDIPlus_FontFamilyDispose($hFamily)     _GDIPlus_StringFormatDispose($hFormat)     _GDIPlus_GraphicsDispose($hGfx)     $tLayout  = 0     Return $i EndFunc


Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#7 PhoenixXL

PhoenixXL

    be what you are, its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,337 posts

Posted 24 May 2012 - 03:35 AM

thanks UEZ JScript Brewman and Zedna now it works


@Zedna I have didnt start any project for decapitalization i think i would not do it anymore (hope so ;))

Edited by PhoenixXL, 24 May 2012 - 03:35 AM.

PredictText: Predict Text of an Edit Control Like Scite. | Remote Gmail: Execute your Scripts through Gmail. | StringRegExp: Share and learn RegExp. | Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). | Database: An easier approach for _SQ_LITE beginners. | MathsEx: A UDF for Fractions and LCM, GCF/HCF. | FloatingText: An UDF for make your text floating. | Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead.

#8 JScript

JScript

    Goodbye everybody, I got tired of this system adopted here!

  • Active Members
  • PipPipPipPipPipPip
  • 1,062 posts

Posted 24 May 2012 - 11:33 AM

You just forgot to tell us which of the examples helped you...

Regards,

João Carlos.
http://notebook.forumais.com (Forum Maintenance Notebooks and Desktop)http://autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Spoiler

Posted Image Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!       


#9 PhoenixXL

PhoenixXL

    be what you are, its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,337 posts

Posted 24 May 2012 - 05:37 PM

Yeah the code of UEZ
AutoIt         
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI = GUICreate("Test", 800, 200) Global $sLabel = "This is the 1st text" Global $fFontsize, $sFont = "Arial" Global $idLabel = GUICtrlCreateLabel($sLabel, 228, 14,  563, 76, $SS_CENTER) GUICtrlSetColor(-1, 0x000080) Resize_Font($sLabel, $idLabel) GUISetState(@SW_SHOW) Sleep(2000) $sLabel =  "And the one is the 2nd label text which is longer!" Resize_Font($sLabel, $idLabel) GUICtrlSetData($idLabel, $sLabel) While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             GUIDelete($hGUI)             _GDIPlus_Shutdown()             Exit     EndSwitch WEnd Func Resize_Font($sLabel, $idControl)     $aPOS = ControlGetPos($hGUI, "", $idControl)     $fFontsize = CalcFontSize($sLabel, $aPOS[2], $aPOS[3], $sFont)     GUICtrlSetFont($idLabel, $fFontsize, 400, 0, $sFont, 5) EndFunc Func CalcFontSize($sString, $iW, $iH, $sFont)     Local $aResult, $hFont, $i, $iLen = StringLen($sString)     Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))     Local $tRectF = DllStructCreate($tagGDIPRECTF)     Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)     Local $hFormat = _GDIPlus_StringFormatCreate()     Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)     $i = 1     Do         $hFont = _GDIPlus_FontCreate($hFamily, $i, 0)         $aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", "handle", $hGfx, "wstr", $sString, "int", -1, "handle", $hFont, "struct*", $tLayout, "handle", $hFormat, "struct*", $tRectF, "int*", 0, "int*", 0)         _GDIPlus_FontDispose($hFont)         If $aResult[8] <  $iLen Or $aResult[9] = 2 Or $i > $iH / 1.45 Then ExitLoop         $i += 1     Until False     _GDIPlus_FontFamilyDispose($hFamily)     _GDIPlus_StringFormatDispose($hFormat)     _GDIPlus_GraphicsDispose($hGfx)     $tLayout  = 0     Return $i EndFunc

gave me this error
C:UsersabhishekDesktopPresentationAbhishekSCriptsMy_Doubt.au3 (48) : ==> Subscript used with non-Array variable.: If $aResult[8] <  $iLen Or $aResult[9] = 2 Or $i > $iH / 1.45 Then ExitLoop If $aResult^ ERROR ->23:05:20 AutoIT3.exe ended.rc:1 >Exit code: 1    Time: 2.183


But the code of JScript(yours ;) )
worked flawlessly and i was able to do with it
thnx

Regards
Phoenix XL
PredictText: Predict Text of an Edit Control Like Scite. | Remote Gmail: Execute your Scripts through Gmail. | StringRegExp: Share and learn RegExp. | Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). | Database: An easier approach for _SQ_LITE beginners. | MathsEx: A UDF for Fractions and LCM, GCF/HCF. | FloatingText: An UDF for make your text floating. | Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead.

#10 UEZ

UEZ

    Never say never

  • MVPs
  • 3,619 posts

Posted 24 May 2012 - 07:15 PM

Very strange that it crashes for you! It works for me on Win7 x64, WinXP x86 (vm).

What os are you using?

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#11 PhoenixXL

PhoenixXL

    be what you are, its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,337 posts

Posted 25 May 2012 - 08:53 AM

I'm Using Win7 32Bit 2GB Ram and Build 7600
PredictText: Predict Text of an Edit Control Like Scite. | Remote Gmail: Execute your Scripts through Gmail. | StringRegExp: Share and learn RegExp. | Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). | Database: An easier approach for _SQ_LITE beginners. | MathsEx: A UDF for Fractions and LCM, GCF/HCF. | FloatingText: An UDF for make your text floating. | Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead.

#12 UEZ

UEZ

    Never say never

  • MVPs
  • 3,619 posts

Posted 25 May 2012 - 06:50 PM

I don't know why "GdipMeasureString" call is not working for you. How you are calling the function?

Further the error check is not implemented yet.

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#13 JScript

JScript

    Goodbye everybody, I got tired of this system adopted here!

  • Active Members
  • PipPipPipPipPipPip
  • 1,062 posts

Posted 25 May 2012 - 07:28 PM

Thanks @PhoenixXL !

The @UEZ code works normal in my Windows 7 x86!!!

Regards,

João Carlos.

Edited by JScript, 25 May 2012 - 07:28 PM.

http://notebook.forumais.com (Forum Maintenance Notebooks and Desktop)http://autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Spoiler

Posted Image Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!       


#14 PhoenixXL

PhoenixXL

    be what you are, its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,337 posts

Posted 14 June 2012 - 06:08 AM

Updated the Autoit to the latest version
and now UEZ's code also works ;)

Thnx Guys
PredictText: Predict Text of an Edit Control Like Scite. | Remote Gmail: Execute your Scripts through Gmail. | StringRegExp: Share and learn RegExp. | Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). | Database: An easier approach for _SQ_LITE beginners. | MathsEx: A UDF for Fractions and LCM, GCF/HCF. | FloatingText: An UDF for make your text floating. | Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users