Jump to content

making/spliting the text in the button


Luigi
 Share

Recommended Posts

Greetings,

I need automatizate a search text.

An message error's log from a system. The system does not matter.

But, it have many keywords and I need group this key words.

The first script to select and group this keywords is split the text, and transform each word in a button.

If you click in any word, this word is selected, if you click again, this is unselcted.

It's simple

Bellow, a example script, but the words is not well sized in the buttons...

Sometimes miss space, other times so much space after/before word in the button.

I unknow how search (keyword) a script similar to do it, if exist...

If you know a better example (of mine), please, share with me.

Or if you have time and knowlodment, help to improve it.

 

Regards,

Luigi

 

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

OnAutoItExitRegister("OnExit")
Global $texto = "I have big eyes and oftentimes" & _
        "I let my mouth droop open to reveal" & _
        "my front teeth. It is the look of dumb. " & _
        "I see how they process my looks. My" & _
        "teachers nervously confront my face" & _
        "when they fear someone may get left behind," & _
        "after introducing x and y."

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGuiSize[2] = [800, 600]
Global $sGuiTitle = "GuiTitle"
Global $hGui

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetFont(11, 400, 0, "Courier New", $hGui)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
Words($texto)

GUISetState(@SW_SHOW, $hGui)

Func Words($input)
    Local $iHeight = 20
    Local $iChar = 13
    Local $iLen = 0
    Local $iMax = 10, $iLine = 0
    While StringInStr($input, "  ")
        $input = StringReplace($input, "  ", " ")
    WEnd
    Local $aWords = StringSplit($input, " ", 2)
;~  _ArrayDisplay($aWords)
    For $ii = 0 To UBound($aWords, 1) - 1
        $iLen = StringLen($aWords[$ii])
        If $iMax > 700 Then
            $iMax = 10
            $iLine += $iHeight + 2
        EndIf
        GUICtrlCreateButton($aWords[$ii], $iMax, 10 + $iLine, $iLen * $iChar, $iHeight, $BS_FLAT)
        GUICtrlSetTip(-1, $iLen)
        $iMax += $iLen * $iChar
    Next
EndFunc   ;==>Words

While Sleep(25)
WEnd

Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit

 

Visit my repository

Link to comment
Share on other sites

You can do something like this.

#include <WinAPI.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>

Global $sStory = 'AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and ' & _
'general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in ' & _
'order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt ' & _
'is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!'

Global $aWords = StringSplit($sStory, " ")
;~ _ArrayDisplay($aWords)

Global $iLeft = 10
Global $iTop = 20
Global $aTextSize = 0
Global $aID[$aWords[0]][2] ;Id|Selected
Global $iGUIWidth = 400
Global $hGUI = GUICreate("Sample", $iGUIWidth, 200)
Global $aSpaceSize = _StringSize(" ", 12)



For $i = 1 To UBound($aWords) - 1
    $aTextSize = _StringSize($aWords[$i], 12)
    If $iLeft + $aTextSize[0] + $aSpaceSize[0] > $iGUIWidth Then
        $iLeft = 10
        $iTop += $aTextSize[1]
    EndIf
    $aID[$i - 1][0] = GUICtrlCreateLabel($aWords[$i], $iLeft, $iTop, $aTextSize[0], $aTextSize[1]) ; create label in calculated size
    $aID[$i - 1][1] = False
    GUICtrlSetFont(-1, 12)
    GUICtrlSetTip(-1, StringLen($aWords[$i]))
    $iLeft += $aTextSize[0] + $aSpaceSize[0]
Next


GUISetState(@SW_SHOW, $hGUI)


Local $iMsg = 0
Local $iIndex = 0
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $aID[0][0] To $aID[UBound($aID) - 1][0]
            ConsoleWrite(GUICtrlRead($iMsg) & @CRLF)
            $iIndex = $iMsg - $aID[0][0]

            If $aID[$iIndex][1] Then
                GUICtrlSetColor($iMsg, 0x000000) ;no selected
                $aID[$iIndex][1] = False
            Else
                GUICtrlSetColor($iMsg, 0xFF0080) ;Change Color selected
                $aID[$iIndex][1] = True
            EndIf

    EndSwitch
WEnd

GUIDelete($hGUI)
Exit


Func _StringSize($sText, $iSize = 8.5, $iWeight = 400, $iAttrib = 0, $sName = "", $iQuality = 2)
    Local Const $LOGPIXELSY = 90
    Local $fItalic = BitAND($iAttrib, 2)
    Local $hDC = _WinAPI_GetDC(0)
    Local $hFont = _WinAPI_CreateFont(-_WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * $iSize / 72, 0, 0, 0, $iWeight, $fItalic, BitAND($iAttrib, 4), BitAND($iAttrib, 8), 0, 0, 0, $iQuality, 0, $sName)
    Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
    Local $tSIZE
    If $fItalic Then $sText &= " "
    Local $iWidth, $iHeight
    Local $aArrayOfStrings = StringSplit($sText, @LF, 2)
    For $sString In $aArrayOfStrings
        $tSIZE = _WinAPI_GetTextExtentPoint32($hDC, $sString)
        If DllStructGetData($tSIZE, "X") > $iWidth Then $iWidth = DllStructGetData($tSIZE, "X")
        $iHeight += DllStructGetData($tSIZE, "Y")
    Next
    _WinAPI_SelectObject($hDC, $hOldFont)
    _WinAPI_DeleteObject($hFont)
    _WinAPI_ReleaseDC(0, $hDC)
    Local $aOut[2] = [$iWidth, $iHeight]
    Return $aOut
EndFunc   ;==>_StringSize

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Thank you DanFirex. Works fine.

 

WoW, it's nice! ^^

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>

OnAutoItExitRegister("OnExit")
Global $texto = "I have big eyes and oftentimes " & _
        "I let my mouth droop open to reveal" & _
        "my front teeth. It is the look of dumb. " & _
        "I see how they process my looks. My" & _
        "teachers nervously confront my face" & _
        "when they fear someone may get left behind, " & _
        "after introducing x and y."

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $_CtrlPlus_HandleGui, $_CtrlPlus_HandleGraphic, $_CtrlPlus_HandleFamily, $_CtrlPlus_HandleGDIFont, $_CtrlPlus_HandleFormat, $_CtrlPlus_sFontDefault, $_CtrlPlus_Height


Global $aGuiSize[2] = [800, 600]
Global $sGuiTitle = "GuiTitle"
Global $hGui

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
CtrlPlus_Start($hGui)
GUISetFont(11, 400, 0, "Courier New", $hGui)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
Words($texto)

GUISetState(@SW_SHOW, $hGui)

Func Words($input)
    Local $iHeight = 22
    Local $iChar = 13
    Local $iLen = 0
    Local $iMax = 10, $iLine = 0
    While StringInStr($input, "  ")
        $input = StringReplace($input, "  ", " ")
    WEnd
    Local $aWords = StringSplit($input, " ", 2)
;~  _ArrayDisplay($aWords)
    For $ii = 0 To UBound($aWords, 1) - 1
        $iLen = StringLen($aWords[$ii])
        If $iMax > 700 Then
            $iMax = 10
            $iLine += $iHeight + 2
        EndIf
        _GUICtrlCreateLabelEx($aWords[$ii], $iMax, 10 + $iLine)
        GUICtrlSetOnEvent(-1, "OnClick")
        $iMax += $_CtrlPlus_Height
    Next

    CtrlPlus_Redraw()
EndFunc   ;==>Words

Func OnClick()
    ConsoleWrite("OnClick[" & @GUI_CtrlId & "]" & @LF)

    If GUICtrlGetBkColor(@GUI_CtrlId) = 0xF0F0F0 Then
        GUICtrlSetBkColor(@GUI_CtrlId, 0xA0A0A0)
    Else
        GUICtrlSetBkColor(@GUI_CtrlId, 0xF0F0F0)
    EndIf
;~  #F0F0F0
EndFunc   ;==>OnClick

While Sleep(25)
WEnd

Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit


Func _GUICtrlCreateLabelEx($sText, $iLeft, $iTop, $sStyle = $SS_CENTER, $BkGndCol = $GUI_BKCOLOR_TRANSPARENT, $iSize = 10, _
        $iWeight = 400, $iAttribute = 0, $iPad = 0, $iMultiLineRectWidth = @DesktopWidth)

    Local $hControl, $tLayout, $aInfo, $hWdith, $hHeight

    $_CtrlPlus_HandleFamily = _GDIPlus_FontFamilyCreate($_CtrlPlus_sFontDefault)
    $_CtrlPlus_HandleGDIFont = _GDIPlus_FontCreate($_CtrlPlus_HandleFamily, $iSize, $iAttribute)
    $_CtrlPlus_HandleFormat = _GDIPlus_StringFormatCreate()
    $tLayout = _GDIPlus_RectFCreate($iLeft, $iTop, $iMultiLineRectWidth, @DesktopHeight)
    $aInfo = _GDIPlus_GraphicsMeasureString($_CtrlPlus_HandleGraphic, $sText, $_CtrlPlus_HandleGDIFont, $tLayout, $_CtrlPlus_HandleFormat)
    $hWdith = DllStructGetData($aInfo[0], 3)
    $hHeight = DllStructGetData($aInfo[0], 4) + 8
    If Mod($iAttribute, 2) = 1 Then $iAttribute = $iAttribute - 1
    $_CtrlPlus_Height = $hWdith + $iPad
    $hControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $_CtrlPlus_Height, $hHeight, $sStyle)

    GUICtrlSetBkColor($hControl, $BkGndCol)
    GUICtrlSetFont($hControl, $iSize, $iWeight, $iAttribute, $_CtrlPlus_sFontDefault)

    Return $hControl
EndFunc   ;==>_GUICtrlCreateLabelEx



Func CtrlPlus_Start($hGui)
    OnAutoItExitRegister("_CtrlPlus_Quit")
    $_CtrlPlus_sFontDefault = "Courier New"
    _GDIPlus_Startup()
    $_CtrlPlus_HandleGui = WinGetHandle($hGui)
    $_CtrlPlus_HandleGraphic = _GDIPlus_GraphicsCreateFromHWND($_CtrlPlus_HandleGui)
EndFunc   ;==>CtrlPlus_Start

Func CtrlPlus_Redraw()
    _WinAPI_RedrawWindow($_CtrlPlus_HandleGui, 0, 0, BitOR($RDW_ERASE, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN))
EndFunc   ;==>CtrlPlus_Redraw

Func CtrlPlus_SetFont($sFont)
    $_CtrlPlus_sFontDefault = $sFont
EndFunc   ;==>CtrlPlus_SetFont

Func CtrlPlus_GetFont()
    Return $_CtrlPlus_sFontDefault
EndFunc   ;==>CtrlPlus_GetFont

Func _CtrlPlus_Quit()
    _GDIPlus_FontDispose($_CtrlPlus_HandleGDIFont)
    _GDIPlus_FontFamilyDispose($_CtrlPlus_HandleFamily)
    _GDIPlus_StringFormatDispose($_CtrlPlus_HandleFormat)
    _GDIPlus_GraphicsDispose($_CtrlPlus_HandleGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_CtrlPlus_Quit

; #FUNCTION# ====================================================================================================================
; Name ..........: GUICtrlGetBkColor
; Description ...: Retrieves the RGB value of the control background.
; Syntax ........: GUICtrlGetBkColor($hWnd)
; Parameters ....: $hWnd                - Control ID/Handle to the control
; Return values .: Success - RGB value
;                  Failure - 0
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func GUICtrlGetBkColor($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, 0, 0)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

A other solution with hidden helper GUI for measuring:

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

OnAutoItExitRegister("OnExit")
Global $texto = "I have big eyes and oftentimes " & _
        "I let my mouth droop open to reveal " & _
        "my front teeth. It is the look of dumb. " & _
        "I see how they process my looks. My " & _
        "teachers nervously confront my face " & _
        "when they fear someone may get left behind, " & _
        "after introducing x and y."

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGuiSize[2] = [800, 600]
Global $sGuiTitle = "GuiTitle"
Global $hGui

Global $sFont = '24|800|0|Freestyle Script'
Global $aFont = StringSplit($sFont, '|', 3)
;Font must be in a array as the measurehelp GUI expected it this way

Global $iHeight

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetFont($aFont[0], $aFont[1], $aFont[2], $aFont[3], $hGui)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
Words($texto)

GUISetState(@SW_SHOW, $hGui)

Func Words($input)
    ;Local $iHeight = 20
    Local $iChar = 13
    Local $iLen = 0
    Local $iMax = 10, $iLine = 0
    While StringInStr($input, "  ")
        $input = StringReplace($input, "  ", " ")
    WEnd
    Local $aWords = StringSplit($input, " ", 2)
;~  _ArrayDisplay($aWords)
    For $ii = 0 To UBound($aWords, 1) - 1
        $iLen = _StringWidth($aWords[$ii])
        If $iMax > 700 Then
            $iMax = 10
            $iLine += $iHeight
        EndIf
        GUICtrlCreateButton($aWords[$ii], $iMax, 10 + $iLine, $iLen, $iHeight, $BS_FLAT)
        GUICtrlSetTip(-1, $iLen)
        $iMax += $iLen
    Next
EndFunc   ;==>Words

While Sleep(25)
WEnd

Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit

; #FUNCTION# ====================================================================================================================
; Name ..........: _StringWidth
; Description ...: Return the Width of a Label containing the given string
; Syntax ........: _StringWidth($sString)
; Parameters ....: $sString             - A string value.
; Return values .: Width in px
; Author ........: minx
; modified ......: autoBert
; ===============================================================================================================================
Func _StringWidth($sString)
    Local $hHGUI = GUICreate($sString, 0, 0)
    GUISetFont($aFont[0], $aFont[1], $aFont[2], $aFont[3], $hHGUI)
    GUISetState(@SW_HIDE, $hHGUI)
    Local $Ref = GUICtrlCreateButton($sString, 0, 0)
    Local $aPos = ControlGetPos($hHGUI, "", $Ref)
    ConsoleWrite($sString & ': ' & $aPos[2] + 8 & @CRLF)
    If Not $iHeight Then $iHeight = $aPos[3] ;initializing global height
    GUIDelete($hHGUI)
    Return $aPos[2] + 8 ;+8 is for borders
EndFunc   ;==>_StringWidth

Tooltip shows width in pixel.

Link to comment
Share on other sites

@AutoBert, its very interesting your example, it use low recurses! I liked too! Thank you! ^^

 

The new example, with word select...

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>
#include <GuiListView.au3>

;~ #include <Object_dump.au3>

OnAutoItExitRegister("OnExit")
Global Const $SD = "Scripting.Dictionary"
Func oo()
    Return ObjCreate($SD)
EndFunc   ;==>oo

Global $texto = "I have big eyes and oftentimes " & _
        "I let my mouth droop open to reveal" & _
        "my front teeth. It is the look of dumb. " & _
        "I see how they process my looks. My" & _
        "teachers nervously confront my face" & _
        "when they fear someone may get left behind, " & _
        "after introducing x and y."

;~ Global $texto = "um um dois três três três quatro quatro um cinco dois oito nome dez um"

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $_CtrlPlus_HandleGui, $_CtrlPlus_HandleGraphic, $_CtrlPlus_HandleFamily, $_CtrlPlus_HandleGDIFont, $_CtrlPlus_HandleFormat, $_CtrlPlus_sFontDefault, $_CtrlPlus_Height


Global $aGuiSize[2] = [1266, 600]
Global $sGuiTitle = "GuiTitle"
Global $hGui, $hListView
Global $aInput[1]

Global $oo = ObjCreate("Scripting.Dictionary")
$oo.Add("keyword", oo())
$oo.Item("keyword").Add("confront", 0xFF7979)
$oo.Item("keyword").Add("process", 0xFF7979)
$oo.Item("keyword").Add("eyes", 0xFF7979)

Global $oSel = oo()
Global $oWord = oo()

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
CtrlPlus_Start($hGui)
GUISetFont(11, 400, 0, "Courier New", $hGui)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
;~ $hListView = GUICtrlCreateListView("nome", 800, 10, 300, 580)
$hListView = _GUICtrlListView_Create($hGui, "Nome", 800, 10, 300, 580)
_GUICtrlListView_SetColumnWidth($hListView, 0, 299)

Words($texto)

GUISetState(@SW_SHOW, $hGui)

Func NewArr($index)
    Local $arr[1] = [$index]
    Return $arr
EndFunc   ;==>NewArr

Func Words($input)
    Local $iHeight = 22
    Local $iYY = 10, $iXX = 10
    While StringInStr($input, "  ")
        $input = StringReplace($input, "  ", " ")
    WEnd
    Local $aWords = StringSplit($input, " ", 2)
    Local $handle, $arr

    For $ii = 0 To UBound($aWords, 1) - 1
        If $iYY > 700 Then
            $iYY = 10
            $iXX += $iHeight
        EndIf

        If $oo.Item("keyword").Exists($aWords[$ii]) Then
            $handle = _GUICtrlCreateLabelEx($aWords[$ii], $iYY, $iXX, $SS_CENTER, $oo.Item("keyword").Item($aWords[$ii]))
;~          GUICtrlSetOnEvent(-1, "OnClick")
        Else
            $handle = _GUICtrlCreateLabelEx($aWords[$ii], $iYY, $iXX)
            If $oWord.Exists($aWords[$ii]) Then
                $arr = $oWord.Item($aWords[$ii])
                _ArrayAdd($arr, $handle)
                $oWord.Item($aWords[$ii]) = $arr
            Else
                $oWord.Add($aWords[$ii], NewArr($handle))
            EndIf

            _ArrayAdd($aInput, $handle)
            GUICtrlSetOnEvent(-1, "OnClick")
        EndIf


        $iYY += $_CtrlPlus_Height
    Next

    CtrlPlus_Redraw()
EndFunc   ;==>Words

Func OnClick()
    Local $arr, $id, $item


    Local $word = String(GUICtrlRead(@GUI_CtrlId))
    ConsoleWrite("OnClick[" & @GUI_CtrlId & "] word[" & $word & "]" & @LF)
    If $oSel.Exists($word) Then

        $item = _GUICtrlListView_FindInText($hListView, $word)


        _GUICtrlListView_DeleteItem($hListView, $item)
        $oSel.Remove($word)
        $arr = $oWord.Item($word)
        For $ii = 0 To UBound($arr, 1) - 1
            GUICtrlSetBkColor($arr[$ii], 0xF0F0F0)
        Next
    Else
        $item = _GUICtrlListView_AddItem($hListView, $word)

        $oSel.Add($word, $item)
        $arr = $oWord.Item($word)
        For $ii = 0 To UBound($arr, 1) - 1
            GUICtrlSetBkColor($arr[$ii], 0xA0A0A0)
        Next
    EndIf

    Local $BOOLEAN = False
    _GUICtrlListView_SimpleSort($hListView, $BOOLEAN, 0, True)
;~  dump($oSel)
EndFunc   ;==>OnClick

While Sleep(25)
WEnd

Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit

Func _GUICtrlCreateLabelEx($sText, $iLeft, $iTop, $sStyle = $SS_CENTER, $BkGndCol = $GUI_BKCOLOR_TRANSPARENT, $iSize = 10, _
        $iWeight = 400, $iAttribute = 0, $iPad = 0, $iMultiLineRectWidth = @DesktopWidth)

    Local $hControl, $tLayout, $aInfo, $hWdith, $hHeight

    $_CtrlPlus_HandleFamily = _GDIPlus_FontFamilyCreate($_CtrlPlus_sFontDefault)
    $_CtrlPlus_HandleGDIFont = _GDIPlus_FontCreate($_CtrlPlus_HandleFamily, $iSize, $iAttribute)
    $_CtrlPlus_HandleFormat = _GDIPlus_StringFormatCreate()
    $tLayout = _GDIPlus_RectFCreate($iLeft, $iTop, $iMultiLineRectWidth, @DesktopHeight)
    $aInfo = _GDIPlus_GraphicsMeasureString($_CtrlPlus_HandleGraphic, $sText, $_CtrlPlus_HandleGDIFont, $tLayout, $_CtrlPlus_HandleFormat)
    $hWdith = DllStructGetData($aInfo[0], 3)
    $hHeight = DllStructGetData($aInfo[0], 4) + 4
    If Mod($iAttribute, 2) = 1 Then $iAttribute = $iAttribute - 1
    $_CtrlPlus_Height = $hWdith + $iPad
    $hControl = GUICtrlCreateLabel($sText, $iLeft, $iTop, $_CtrlPlus_Height, $hHeight, $sStyle)

    GUICtrlSetBkColor($hControl, $BkGndCol)
    GUICtrlSetFont($hControl, $iSize, $iWeight, $iAttribute, $_CtrlPlus_sFontDefault)

    Return $hControl
EndFunc   ;==>_GUICtrlCreateLabelEx



Func CtrlPlus_Start($hGui)
    OnAutoItExitRegister("_CtrlPlus_Quit")
    $_CtrlPlus_sFontDefault = "Courier New"
    _GDIPlus_Startup()
    $_CtrlPlus_HandleGui = WinGetHandle($hGui)
    $_CtrlPlus_HandleGraphic = _GDIPlus_GraphicsCreateFromHWND($_CtrlPlus_HandleGui)
EndFunc   ;==>CtrlPlus_Start

Func CtrlPlus_Redraw()
    _WinAPI_RedrawWindow($_CtrlPlus_HandleGui, 0, 0, BitOR($RDW_ERASE, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN))
EndFunc   ;==>CtrlPlus_Redraw

Func CtrlPlus_SetFont($sFont)
    $_CtrlPlus_sFontDefault = $sFont
EndFunc   ;==>CtrlPlus_SetFont

Func CtrlPlus_GetFont()
    Return $_CtrlPlus_sFontDefault
EndFunc   ;==>CtrlPlus_GetFont

Func _CtrlPlus_Quit()
    _GDIPlus_FontDispose($_CtrlPlus_HandleGDIFont)
    _GDIPlus_FontFamilyDispose($_CtrlPlus_HandleFamily)
    _GDIPlus_StringFormatDispose($_CtrlPlus_HandleFormat)
    _GDIPlus_GraphicsDispose($_CtrlPlus_HandleGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_CtrlPlus_Quit

; #FUNCTION# ====================================================================================================================
; Name ..........: GUICtrlGetBkColor
; Description ...: Retrieves the RGB value of the control background.
; Syntax ........: GUICtrlGetBkColor($hWnd)
; Parameters ....: $hWnd                - Control ID/Handle to the control
; Return values .: Success - RGB value
;                  Failure - 0
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func GUICtrlGetBkColor($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, 0, 0)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

 

Edited by Luigi

Visit my repository

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...