Jump to content
Sign in to follow this  
b8bboi

How Can I Tell If A Label Is Extended Past The Size Of The Control?

Recommended Posts

b8bboi

I'm using GuiCtrCreateLabel to try to simulate a text input control. The reason why I don't want to use a simple input control is that I want to have a transparent background. $GUI_BKCOLOR_TRANSPARENT doesn't work on Input boxes.

The label control is gonna have a fixed width. It also gets updated when user types into another (hidden) input box. The problem is I need to know when the text label is clipped so that I can trim the first few characters from the string. This way the right most characters are always visible.

I hope I'm clear enough. Appreciate any help.

Share this post


Link to post
Share on other sites
blindwig
b8bboi

So, did you ever figure out how to calculate the size of a text label?

Share this post


Link to post
Share on other sites
b8bboi

so, following Valik's advice, I've tried the following but it didn't work. The GetTextExtentPoint32 function always returns a false value and doesn't return the actual size fo the label.

#include <GUIConstants.au3>

$myGui = GUICreate("Test Label Size") 

$WM_GETFONT = 0x31

$text = "ABCDEFGHIJKLMN"

$hText = GUICtrlCreateLabel ($text,  10, 10, 100, 80, $SS_SIMPLE) 
GUICtrlSetFont(-1, 20, 600, "", "Arial Narrow")

GUISetState ()    

$MyHDC = DLLCall("user32.dll","int","GetDC","hwnd",$hText)

$hFont = DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hText, "int", $WM_GETFONT, "int", 0, "int", 0)
$hFont = $hFont[1]

$hOld = DllCall("gdi32.dll", "Hwnd", "SelectObject", "int", $MyHDC[0], "ptr", $hFont)

$res = DllStructCreate("long;long")

$ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $MyHDC[0], "str", $text, "long", StringLen($text), "ptr", DllStructGetPtr($res))

MsgBox(0, "Get Size", "Return Status="&$ret[0]&" | width="&DllStructGetData($res,0))

DLLCall("user32.dll","int","ReleaseDC","int",$MyHDC[0],"hwnd",$hText)

Could anyone see why? Thanks.

Share this post


Link to post
Share on other sites
Zedna

I know it's a bit late :shocked:

but now I need GetTextExtentPoint32 in my script so I searched forum and found also this post.

Here is corrected functional version of your script (tested with AutoIt 3.2.2.0 on WINXP SP2):

#include <GUIConstants.au3>

$WM_GETFONT = 0x31
$text = "ABCDEF"

$hGui = GUICreate("Test Label Size") 
$Label_1 = GUICtrlCreateLabel ($text,  10, 10, 100, 80);, $SS_SIMPLE) 
GUICtrlSetFont(-1, 20, 600, "", "Arial Narrow")
GUISetState ()      

$hText = ControlGetHandle($hGui, "", $Label_1)
$hDC = DLLCall("user32.dll","int","GetDC","hwnd",$hText)
$hDC = $hDC[0]
$hFont = DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hText, "int", $WM_GETFONT, "int", 0, "int", 0)
$hFont = $hFont[0]
$hOld = DllCall("gdi32.dll", "Hwnd", "SelectObject", "int", $hDC, "ptr", $hFont)
$struct_size = DllStructCreate("int;int")
$ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC, "str", $text, "long", StringLen($text), "ptr", DllStructGetPtr($struct_size))
$hOld = DllCall("gdi32.dll", "Hwnd", "SelectObject", "int", $hDC, "ptr", $hOld)

MsgBox(0, "Get Size", "Return Status=" & $ret[0] & " width=" & DllStructGetData($struct_size,1))

DLLCall("user32.dll","int","ReleaseDC","hwnd",$hText,"int",$hDC)
$struct_size = 0
Edited by Zedna

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  

×