Sign in to follow this  
Followers 0
rootx

[SOLVED] _GDIPlus_GraphicsDrawString how to Update?

5 posts in this topic

#1 ·  Posted (edited)

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <file.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include<ComboConstants.au3>
#include <GUIComboBox.au3>

$Form1 = GUICreate("Form1", 300, 200, -1, -1)
$Combo1 = GUICtrlCreateCombo("Select Font", 25, 64, 250, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_DROPDOWNLIST))

$s_FontList = _FileListToArray(@WindowsDir & "\Fonts\","*.ttf")
$NFontList = UBound($s_FontList)-1

For $ff = 1 to $NFontList
    GUICtrlSetData($Combo1, StringTrimRight($s_FontList[$ff],4))
Next
Global $hGraphic
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1

    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $combo1, $hWndCombo
            Switch $iCode
                    ; no return value
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    _GDIPlus_Startup()
                    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
                    _GDIPlus_GraphicsDrawString($hGraphic, "Hello world", 10, 10,GUICtrlRead($Combo1),10)
                    ; Clean up resources
                    _GDIPlus_GraphicsDispose($hGraphic)
                    _GDIPlus_Shutdown()

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND functia de autocomplete la combo

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

When I change the font I would also update the gui, but the fonts are overwritten without refreshing the gui, could someone tell me what is wrong.

THX

Cattura.PNG

Edited by rootx

Share this post


Link to post
Share on other sites



_GDIPlus_GraphicsClear($form1, 0xFFF0F0F0)

 

Will clear the image you already drew and then allow you to draw on a blank canvas.

Share this post


Link to post
Share on other sites

_GDIPlus_GraphicsClear($form1, 0xFFF0F0F0)...

APPCRASH
autoit3.exe
3.3.14.2
gdiplus.dll
6.3.9600.18123

I tried but I get the following error.

THX InunoTaishou

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You are disposing the old graphic handle which causes the crash!

Try this:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <file.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include<ComboConstants.au3>
#include <GUIComboBox.au3>

$Form1 = GUICreate("Form1", 300, 200, -1, -1)
$iPic = GUICtrlCreatePic("", 0, 0, 300, 60)
$hPic = GUICtrlGetHandle($iPic)
$Combo1 = GUICtrlCreateCombo("Select Font", 25, 64, 250, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_DROPDOWNLIST))

$s_FontList = _FileListToArray(@WindowsDir & "\Fonts\","*.ttf")
$NFontList = UBound($s_FontList)-1

For $ff = 1 to $NFontList
    GUICtrlSetData($Combo1, StringTrimRight($s_FontList[$ff],4))
Next
Global $hGraphic
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hPic)
_GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ; Clean up resources
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            Exit
        Case $Combo1

    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $combo1, $hWndCombo
            Switch $iCode
                    ; no return value
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    $sFont = GUICtrlRead($Combo1)
                    $sFontname = _WinAPI_GetFontResourceInfo(@WindowsDir & "\Fonts\" & $sFont & ".ttf")
                    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
                    _GDIPlus_GraphicsDrawString($hGraphic, $sFontname, 10, 10, $sFontname, 24)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND functia de autocomplete la combo

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

 

Edited by UEZ
1 person likes this

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

THX, UEZ.... always the best answer!

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