Sign in to follow this  
Followers 0
erebus

GUICtrlCreateLabel

6 posts in this topic

Hello all,

I was wondering if there is any way to know when I exceed a label's limits on a GUI. For example, I use this dirty way to fill in a label with text:

$JPGFile = $Source & "\" & $GameID & "." & "JPG"
If FileExists($JPGFile) Then
    If StringLen($GameDesc) > "313" Then $GameDesc = StringLeft($GameDesc, 310) & "..."
    $gamepic = GUICtrlCreatePic($JPGFile, 240, 155, 150, 112)
    $lbl_desc = GUICtrlCreateLabel($GameDesc, 15, 155, 215, 180)
Else
    If StringLen($GameDesc) > "383" Then $GameDesc = StringLeft($GameDesc, 380) & "..."
    $lbl_desc = GUICtrlCreateLabel($GameDesc, 15, 155, 370, 130)
EndIf
GUICtrlSetFont(-1, 10, 400, -1, $fnt)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xffa200)

What I want is, if I exceed my label's limits (in height and width) to cut down my texts length and add three periods in the end. Until now I do this using the StringLen() function, however this is not that precise because other factors may change the visual length of my text (font, weight, spaces that make the words change line, words length among spaces, etc...). Is there a better way?

I hope you understand what my need is. Thank you all in advance.

Share this post


Link to post
Share on other sites



GUICtrlSetLimit()


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I didn't ask of this.

I don't want to limit the characters displayed in my Label.

I want to know how much characters exactly CAN BE displayed, depending on the other factors, as explained.

14 characters in a label can be fitted if you write the word "this-is-a-test" but may not if you write THIS IS A TEST (unlessif you use a fixed font).

Anyone?

Share this post


Link to post
Share on other sites

I think this is what you're looking for. You'll need Auto3Lib for the API calls...

#include <A3LWinAPI.au3>

Opt("MustDeclareVars", 1)

; Global variables
Global $hGUI, $iLabel, $hLabel, $hDC, $hFont, $hOld, $tSize

; Create a GUI with a label
$hGUI   = GUICreate('Text Width Demo', 208, 100)
$iLabel = GUICtrlCreateLabel("Text width to calculate", 4, 10, 200, 18, $SS_SUNKEN)
$hLabel = GUICtrlGetHandle($iLabel)
GUISetState()

; Get the device context of the label
$hDC   = _API_GetDC($hLabel)
; Get a handle to the label's font
$hFont = _API_SendMessage($hLabel, $WM_GETFONT, 0, 0)
; Select the label's font into the device context
$hOld  = _API_SelectObject($hDC, $hFont)
; Calculate the size of the text with one space of padding for the borders
$tSize = _API_GetTextExtentPoint32($hDC, GUICtrlRead($iLabel) & " ")
; Restore the original font
_API_SelectObject($hDC, $hOld)
; Release the device context
_API_ReleaseDC($hLabel, $hDC)

; Draw a secondary label with the appropriate size box
GUICtrlCreateLabel("Text width to calculate", 4, 30, _tagGetData($tSize, "X"), _tagGetData($tSize, "Y"), $SS_SUNKEN)

; Loop until user exits
do
until GUIGetMsg() = $GUI_EVENT_CLOSE

Regards,

Paul


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

I didn't ask of this.

I don't want to limit the characters displayed in my Label.

I want to know how much characters exactly CAN BE displayed, depending on the other factors, as explained.

14 characters in a label can be fitted if you write the word "this-is-a-test" but may not if you write THIS IS A TEST (unlessif you use a fixed font).

Anyone?

Ahh, I misread it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I think this is what you're looking for. You'll need Auto3Lib for the API calls...

Amazing... :whistle: I was totally unaware of this excellent piece of work...

I really appreciate your help and your job on this...

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