Jump to content

Changing from one GUI to another seamlessly - need critical input about my script


timmy2
 Share

Recommended Posts

The following simple test script, cobbled together from examples, accomplishes what I want, which is to show a series of text windows without any flicker or other artifacts during changes from one window to the next.  My PC is fairly powerful so I wonder if it will work well on other systems with a lesser GPU. I'm also relatively new to using GDI+ so I'm unsure what lines of code are needed, and what are not.

Seeking comments.  Thank you.

 

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

GLOBAL $sString

$sString = "Testing 123" & @CRLF & "I've got info for you"  & @CRLF & @CRLF & "And that is not all!"

Example($sString)

$sString = "Another page" & @CRLF & "this is more text."  & @CRLF & "More to come."

Example ($sString)

$sString = "The last page" & @CRLF & @CRLF & "this is more text."  & @CRLF & "And that IS all."

Example ($sString)

Func Example($sString)
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    Local $aInfo

    ; Create GUI
    $hGUI = GUICreate("", 400, 300,-1,-1,$WS_POPUP)
    GUISetBkColor(0xFF000000) ; will change background color
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 20, 0)
    $tLayout = _GDIPlus_RectFCreate(50, 50, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)

    Sleep (2000)

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

 

 

Link to comment
Share on other sites

If you want to avoid a flicker and use GDI+ you would normally use what's called a buffer (it's an object [graphic object] linked to a bitmap). When you draw on the graphic you're drawing on the bitmap, then you draw the bitmap on your main graphic.

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

HotKeySet("{Esc}", Close)

Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
Local $iString = 0
Local $aStrings[3] = ["Testing 123" & @CRLF & "I've got info for you" & @CRLF & @CRLF & "And that is not all!", _
        "Another page" & @CRLF & "this is more text." & @CRLF & "More to come.", _
        "The last page" & @CRLF & @CRLF & "this is more text." & @CRLF & "And that IS all."]

; Create GUI
$hGUI = GUICreate("", 400, 300, -1, -1, $WS_POPUP)
GUISetBkColor(0xFF000000) ; will change background color
GUISetState(@SW_SHOW)

; Draw a string
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic)
Local $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 20, 0)
$tLayout = _GDIPlus_RectFCreate(50, 50, 0, 0)

While (True)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $aStrings[$iString], $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsClear($hBuffer)
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $aStrings[$iString], $hFont, $aInfo[0], $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    Sleep(200)
    $iString += 1
    If ($iString > 2) Then $iString = 0
WEnd


; Clean up resources

Func Close()
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Close

 

Link to comment
Share on other sites

I would change func header to

Func Example($sString, $iTime=2000)

and use $iTime in the sleep.  So it's possible to varying the displaying time for the GUI:

$sString = "Testing 123" & @CRLF & "I've got info for you"  & @CRLF & @CRLF & "And that is not all!"

Example($sString)   ;default time is used 

$sString = "Another page" & @CRLF & "this is more text."  & @CRLF & "More to come."

Example ($sString, 3500)

$sString = "The last page" & @CRLF & @CRLF & "this is more text."  & @CRLF & "And that IS all."

Example ($sString, 2500)

 

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