Jump to content

Label Blinking with Pic for Background


Go to solution Solved by UEZ,

Recommended Posts

I have a program that has a large label acting as a count down timer.
I have set the background color of the label to $GUI_BKCOLOR_TRANSPARENT.
 
This program has a picture for a background.
In the below example the gui's background color is set to yellow.
 
Occasionally when the timer updates you can see the yellow background color in the shape of the label.
 
i have looked at many posts about blinking labels, but the all appear to find a way around the blinking problem instead of fixing it and none of them use a background picture.
 
Does anyone know how this problem can be fixed?
Or perhaps just a work around for my situation?

As you can see by my commented out code, I have tried ControlSetText and GUISetState LOCK/UNLOCK.

ControlSetText results in each new number being written over whatever was in the label instead of replacing it

GUISetState LOCK/UNLOCK cause the issue to happen to the whole gui instead of just the label.
 
 I have attached the background I was using.

Thanks in advance.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Const $BKGND_FILE = "C:\Users\sjraisbe\Pictures\poker bkgd.jpg"

Global $seconds = 60

$hMain = GUICreate("Timer", 800, 600, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
   GUISetBkColor(0xFFFF00, $hMain)
   GUICtrlSetDefBkColor($GUI_BKCOLOR_TRANSPARENT, $hMain)

$pic = GUICtrlCreatePic($BKGND_FILE, 0, 0, 1920, 1080)
   GUICtrlSetState(-1,$GUI_DISABLE)

$lblTime = GUICtrlCreateLabel("01:00", 192, 222, 424, 156, $SS_CENTER)
   GUICtrlSetFont($lblTime, 100, 400, 0, "Arial")
   GUICtrlSetColor($lblTime, 0xFFFFFF)

AdlibRegister("UpdateTime", 1000)

GUISetState(@SW_SHOW, $hMain)

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then
      ExitLoop
   EndIf

WEnd


Func UpdateTime()
   ;GUISetState(@SW_LOCK)
   Local $sec, $min, $hr
   $sec = Mod($seconds, 60)
   $min = Mod($seconds / 60, 60)
   GUICtrlSetData($lblTime, StringFormat("%02i:%02i", $min, $sec))
   ;ControlSetText($hMain, "", $lblTime, StringFormat("%02i:%02i", $min, $sec))
    

   $seconds -= 1
   ;GUISetState(@SW_UNLOCK)
EndFunc

post-24647-0-19432700-1393965568_thumb.j

Link to post
Share on other sites

Have a look here for a start: 

There should a lot of code snippets flying around how to update a control without flickering using GDI+.

Br,

UEZ

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 post
Share on other sites

UEZ,

I looked at the GDI script in your linked post and played with it a bit.

When I add a background to the gui, the time label/graphic is not transparent so it ends up having a grey rectangle around the time.

I was unable to figure out if it's possible to make the background transparent.

I believe I ran across this before, GDI looked like a good solution until I realized that none of the example scripts use a background and transparency.

Can GDI be used to create a label with a transparent background?

Thanks,

momar33

Link to post
Share on other sites

Try this:
 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()

Const $BKGND_FILE = @ScriptDir & "\poker bkgd.jpg"
Local $hImage_Bg = _GDIPlus_ImageLoadFromFile($BKGND_FILE)
Local $hTexture = _GDIPlus_TextureCreate($hImage_Bg)
Global $seconds = 60
Global Const $iW = 800, $iH = 600
$hMain = GUICreate("Timer", $iW, $iH)
GUISetBkColor(0x2C6135)
$lblTime = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
UpdateTime()
GUISetState(@SW_SHOW, $hMain)

AdlibRegister("UpdateTime", 1000)


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        _GDIPlus_BrushDispose($hTexture)
        _GDIPlus_ImageDispose($hImage_Bg)
        _GDIPlus_Shutdown()
        GUIDelete()
        Exit
    EndIf
WEnd


Func UpdateTime()
    Local $sec, $min, $hr
    $sec = Mod($seconds, 60)
    $min = Mod($seconds / 60, 60)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4 + (@OSBuild > 5999))
    _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 3)
    _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iW, $iH, $hTexture)
    Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local Const $hFont = _GDIPlus_FontCreate($hFamily, 100)
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hGfx, StringFormat("%02i:%02i", $min, $sec), $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGfx)
    Local Const $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($lblTime, 0x0172, 0x0000, $hBitmap_GDI)) ;$STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
    _WinAPI_DeleteObject($hBitmap_GDI)
    $seconds -= 1
    If $seconds < 0 Then AdlibUnRegister("UpdateTime")
EndFunc   ;==>UpdateTime

Br,

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 post
Share on other sites

UEZ,

That script was very helpful.

It looks like it is still not using a transparent background though, instead just making the label and background all in the same pic.

The program I intend to use this timer in has several other labels being displayed at the same time.

Based on what I have learned from the script, and assuming there is no way to make the pic background transparent, it seems that either the GDI pic will either overwrite everything, or if i adjust the position and size, the GDI pic background will not match up with the GUI background.

It seems the only way I can proceed is to make all the information on my program using GDI.

Thanks,

momar33

Link to post
Share on other sites

There is a way with GDI+ to exclude the areas where the controls are placed.

I will modify the example appropriately later.

Br,

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 post
Share on other sites
  • Solution

Then try something like this here:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()

Const $BKGND_FILE = @ScriptDir & "\poker bkgd.jpg"
Global Const $hImage_Bg = _GDIPlus_ImageLoadFromFile($BKGND_FILE)
Global Const $hTexture = _GDIPlus_TextureCreate($hImage_Bg)
Global $seconds = 60
Global Const $iW = 800, $iH = 600

Global $sec, $min, $hr

$hMain = GUICreate("Timer", $iW, $iH)
GUISetBkColor(0x2C6135)

$iBtn = GUICtrlCreateButton("Hit me", 700, 500, 80, 60)
$iLbl = GUICtrlCreateLabel("This is a label", 20, 500, 250, 45)
GUICtrlSetFont(-1, 30)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW, $hMain)

Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hMain)

_GDIPlus_RegionExcludeContorls($hGraphic, $hMain)

UpdateTime()

AdlibRegister("UpdateTime", 1000)

GUIRegisterMsg($WM_PAINT, "Draw")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $iBtn
            _GDIPlus_BrushDispose($hTexture)
            _GDIPlus_ImageDispose($hImage_Bg)
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $iLbl
            MsgBox(0, "Test", "Label was clicked")
        Case @SW_RESTORE
            Draw()
   EndSwitch
WEnd

Func _GDIPlus_RegionExcludeContorls($hGraphic, $hGUI)
    Local Const $aHWND_Info = WinGetClientSize($hGUI)
    Local Const $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $aHWND_Info[0], $aHWND_Info[1])
    Local $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD), $aRect
    Do
        $aRect = ControlGetPos($hChild, "", 0)
        _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    Until Not $hChild
    _GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
    _GDIPlus_RegionDispose($hRegion)
EndFunc

Func UpdateTime()
    $sec = Mod($seconds, 60)
    $min = Mod($seconds / 60, 60)
    Draw()
    $seconds -= 1
    If $seconds < 0 Then AdlibUnRegister("UpdateTime")
EndFunc   ;==>UpdateTime

Func Draw()
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4 + (@OSBuild > 5999))
    _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 3)
    _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iW, $iH, $hTexture)
    Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local Const $hFont = _GDIPlus_FontCreate($hFamily, 100)
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hGfx, StringFormat("%02i:%02i", $min, $sec), $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
    _GDIPlus_BitmapDispose($hBitmap)
    Return "GUI_RUNDEFMSG"
EndFunc

Br,

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By XGamerGuide
      I'm trying to assign a faint text in the background to an input field that disappears after the input has started. This should have a certain color such as gray.
    • By XGamerGuide
      I'm trying to display a GIF. However, the GUI should not be visible. Here is an attempt that doesn't work:
      $sGIF = "MyGIF.gif" #Include <IE.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WINAPI.au3> #include <SendMessage.au3> Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{ESC}", "_Exit") $hGui = GUICreate("Test", 400, 300, -1, -1, $WS_POPUP, $WS_EX_LAYERED) GUISetBkColor(0xABCDEF) $oIE = _IECreateEmbedded() GUICtrlCreateObj($oIE, 10, 10, 380, 280) _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250) _IENavigate($oIE, $sGIF) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch WEnd Func _Exit() Exit  
    • By MASKED
      hi guys
      i am using imagesearch2015 library. (used another one before)
      but transparency parameter doesn't working. how i can solve this problem.
       
      here's my code
      #include "ImageSearch2015.au3" #include <Date.au3> ; Script Start - Add your code below here Global $x = 0 Global $y = 0 HotKeySet("{UP}","hey") HotKeySet("{DOWN}","heyo") Func hey() $balikcisaniye = _Date_Time_GetTickCount() $array = _ImageSearchArea("bul.bmp", 1, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, 2,0x000000) if($array = True) Then $balikcisaniye1 = _Date_Time_GetTickCount() MouseMove($x,$y) MsgBox(1,"","Found." & $x & "-" & $y & " / " & $balikcisaniye1-$balikcisaniye) Else MsgBox(1,"","Not Found.") EndIf EndFunc Func heyo() exit EndFunc while 1 WEnd when i disable transparency parameter, it work normal. but with parameter, this function is always returning false.
      please help.
       
      here's library i use :
       
       
    • By Schuster
      Hey there,
      i need your help guys. I am working in the QA department of my company. A little part of or software produces hints (like little popups) which needs to be tested every release. I wrote scripts to trigger those hints and i also implemented the imagesearch.dll to find those hints on the screen. My goal now is it to let the machine work over night, so when i come back to work i only get a report which says 130/140 hints were found successfully. This already works, aslong as my pc is not locked, but i want/need to lock my pc because of security concerns.
      My general question. Is it possible to run my scripts on my locked PC and still find an image that i provide which will open sooner or later in the background?
       
      Thanks in advance
    • By nooneclose
      Good morning, I have been thinking about trying to make my Autoit script run in the background. I found out today that it is impossible due to the UIA and mouseclick functions that I use. However, while reading other posts about running Autoit scripts in the background I saw a reply mentioning how a script like mine might be able to run on a VM while still giving me the ability to work on my Host OS. Can someone confirm this? 
      Here is a link to the thread where I saw VM mentioned. 
      the person who mentioned it was @ViciousXUSMC 
×
×
  • Create New...