Jump to content

String Length as Drawn


Recommended Posts

As a prelude, this is a question about GDI Plus.

I am attempting to figure out if I want to draw a string in a specific font and size, (like using _GDIPlus_GraphicsDrawString) how wide the string will be in Pixels.

I assume this has something to do with _GDIPlus_GraphicsMeasureString but I don't understand what a "$tagGDIPRECTF structure" is really. I understand it contains 4 Floating Point values but I'm at a loss to understand what the structure actually is ( I feel as though this is the fully spelled out version of the C++ equivalent STRUCT, but then there are also DLL STRUCTs?), how do I access its elements (if possible) and is that really what I even want to do?

Anyways, all the research I have done leads me to all kinds of dead ends... so if someone could please explain the following:

1. How do I get the width of a string in pixels as described above?

2. What is a "Structure" exactly?

Thanks!

 

Edited by XrrotonX
Grammar/Spelling corrections
Link to comment
Share on other sites

What is a struct?

Short: a struct is a sort of variables that can hold several data items of different kinds. Long: https://en.wikipedia.org/wiki/Struct_(C_programming_language)

Example:

#include <WinAPIDiag.au3>

;define a test struct
Global $sMyStruct = "int Amount;char Name[128];float Pi"
Global $tMyStruct = DllStructCreate($sMyStruct)

;fill the struct with some data
$tMyStruct.Amount = 10
$tMyStruct.Name = "AutoIt"
$tMyStruct.Pi = ACos(-1)


;display the struct
_WinAPI_DisplayStruct($tMyStruct, $sMyStruct)

Here the code from the help file modified to display a rectangle which represents the values calculated by _GDIPlus_GraphicsMeasureString.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI, $hGraphic, $hBrush, $hPen, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
    Local $sString = "Hello world"

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F)
    $hPen = _GDIPlus_PenCreate(0xFF000000)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 24, 2)
    $tLayout = _GDIPlus_RectFCreate(120, 110, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawRect($hGraphic, $aInfo[0].X, $aInfo[0].Y, $aInfo[0].Width, $aInfo[0].Height, $hPen)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenCreate($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Please read the help files for detailed description of each functions.

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Is it possible to have an array of Struct in AutoIt, and how would you declare it, and access the elements?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

You mean to save a struct into an array or declare a struct variable as an array?

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

both...

 

EDIT

Struct variable as an array

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Does this help?

#include <WinAPIDiag.au3>

;define a test struct
Global $sMyStruct = "byte Array[255]" ;only 8-bit values possible but struct array can be more than 255!
Global $tMyStruct = DllStructCreate($sMyStruct)

;fill struct with some 8-bit values
For $i = 1 To 255
    $tMyStruct.Array(($i)) = $i
Next

ConsoleWrite($tMyStruct.Array((50)) & @CRLF)

;display the struct
_WinAPI_DisplayStruct($tMyStruct, $sMyStruct)

;define an array
Global $aStruct[1] = [DllStructCreate("int Value")] ;pointer to struct is saved in $aStruct[0]
$aStruct[0].Value = 12345678 ;save value to struct
$tMyStruct = $aStruct[0] ;save pointer to variable (not needed - just to show possibility)
ConsoleWrite($tMyStruct.Value & @CRLF)
_WinAPI_DisplayStruct($tMyStruct, "int Value")

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I can see how this is going to come in handy - thanksj

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...