Sign in to follow this  
Followers 0
h711

What is the best way to check UI truncation?

6 posts in this topic

#1 ·  Posted (edited)

Truncation is caused by a text string that is larger/longer than the box/button size. What is the best way to let the script check them? Thanks for the help!

Edited by h711

Share this post


Link to post
Share on other sites



Truncation is caused by a text string that is larger/longer than the box/button size. What is the best way to let the script check them? Thanks for the help!

You can try _WinAPI_GetTextExtentPoint32(). Complicated and hard to use, though, at least for me.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Truncation is caused by a text string that is larger/longer than the box/button size. What is the best way to let the script check them? Thanks for the help!

I agree with PsaltyDS.

The function _WinAPI_GetTextExtentPoint32 should help although it probably uses an average character width an isn't very accurate as this demo shows.

#include <winapi.au3>
$gui = GUICreate("text width demo", 200, 200, 200, 200)
$input1 = GUICtrlCreateInput("", 30, 30, 120, 20);120 wide so text wider than 120 won't fit
GUICtrlCreateLabel("width of text in edit =", 30, 60, 120, 20)
$Lab2 = GUICtrlCreateLabel("",60,90,80,20)
GUISetState()
$text = ''
While 1
    
    $hdc = _WinAPI_GetDC($gui)

    If GUIGetMsg() = -3 Then Exit

    If GUICtrlRead($input1) <> $text Then
    $text = GUICtrlRead($input1)
    
    $res = _WinAPI_GetTextExtentPoint32($hdc, $text)
    GUICtrlSetData($lab2, DllStructGetData($res, 1))
    EndIf
WEnd

But it might do what you want.

The above is assuming that the font in the edit is the same as the gui font. I don't quite understand it though because if you change the gui font size the reported width doesn't get affected. It seems to be based on the default font and size. The default size is 8 so you get an approximate width by saying width = Ceiling($res * $fontsize/8)

The return from the function is in logical units and I checked the MapMode and it is 1 which is MM_TEXT which means the result is the same as pixels.

Maybe the difference is because it's a GDI function and GDI draws text differently.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks! I tried few times but didn't get the thing I wanted. I have trouble deal with the returned struct. Could you please help me by give me an example? How about the "Welcome to the Autoit v3.2.12.1 Setup Wizard" on the first page of the Autoit installer?

Thanks a lot for the help!!!

Share this post


Link to post
Share on other sites

Some help please. Thanks a lot!

Share this post


Link to post
Share on other sites

Thanks! I tried few times but didn't get the thing I wanted. I have trouble deal with the returned struct. Could you please help me by give me an example? How about the "Welcome to the Autoit v3.2.12.1 Setup Wizard" on the first page of the Autoit installer?

Thanks a lot for the help!!!

I had already posted an example for you so you need to explain why that didn't help you otherwise how can I decide what to do?

If you tried something that doesn't work then post that.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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