Jump to content
Sign in to follow this  
momar33

Label Blinking with Pic for Background

Recommended Posts

momar33

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

Share this post


Link to post
Share on other sites
UEZ

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

Share this post


Link to post
Share on other sites
momar33

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

Share this post


Link to post
Share on other sites
UEZ

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

Share this post


Link to post
Share on other sites
momar33

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

Share this post


Link to post
Share on other sites
UEZ

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

Share this post


Link to post
Share on other sites
UEZ

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

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  

  • Similar Content

    • Sven-Seyfert
      By Sven-Seyfert
      Hi Community,

      I'm looking for a way to do a Video Overlay GUI or something like that. The idea is to create a GUI which plays a video loop (with transparency/alpha channel) in front of an other GUI. Before you asking why - because I don't believe that GDIPlus can do it out of the box. My skillset for that kind of graphical things isn't good enough to do that, but here are some specialist like @UEZ maybe who can help.

      Example alpha channel video (visualized as animated *.gif):

      I tried to do the light rays effect directly with GDIPlus, but honestly that's a bit too difficult for me. I would be very glad and grateful if there are some suggestions, ideas or recommendations.

      Code for the Video play:
       
      Example video "End.mpeg":
       
      The next challenge is that the overlay GUI should be not clickable. If I hover over the overlay area, I want to have the possibility to control the GUI or what ever, in the background. But if there is any chance to make it with GDIPlus as a Video Overlay for light rays, I would prefer that approach instead of my crazy work-around idea.

      Thanks for any suggestion - I'm grateful!
      Sven
    • b9k
      By b9k
      Hi, I am stuck on a GUI problem and would like your help to solve it.
      I am trying to automate the SoundWire Server app to match my current system volume level while it is minimized to the notification area (so no clicking or stealing focus),
      I can already get the handle and alter the tracker position by sending a WM_SETPOS message, but somehow the actual volume is not changed: I think I need to do something else to trigger the event handler for the value change and propagate it correctly.
      This is the control summary from Au3 info:
      >>>> Window <<<< Title: SoundWire Server Class: #32770 Position: 441, 218 Size: 566, 429 Style: 0x94CA00C4 ExStyle: 0x00050101 Handle: 0x0000000000510E12 >>>> Control <<<< Class: msctls_trackbar32 Instance: 4 ClassnameNN: msctls_trackbar324 Name: Advanced (Class): [CLASS:msctls_trackbar32; INSTANCE:4] ID: 6002 Text: Position: 51, 222 Size: 47, 126 ControlClick Coords: 1, 101 Style: 0x5001000A ExStyle: 0x00000000 Handle: 0x00000000001234C8 >>>> Mouse <<<< Position: 496, 567 Cursor ID: 2 Color: 0xF0F0F0 >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< Default multimedia device Tray on Start Static Server Address: 192.168.1.8 Status: Connected to B9K~OP3 Audio Output Audio Input Level Record to File Input Select: 44.1 kHz Minimize to Master Volume Mute >>>> Hidden Text <<<< Slider2 Mute OK Cancel Label Balance Slider1 Volume Front L/R Fr C/LFE Side L/R Back L/R
      I am attaching the program in question so you don't have to install it (i don't know if it is portable enough, tough): 

      SoundWire Server_files.zip

      Thanks in advance and I hope I didn't post in the wrong section
    • aiter
      By aiter
      I am trying to get an image showing through a edit box.  I am only successful in making the edit box totally transparent
      #include-once #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPISys.au3> #include <colorconstants.au3> ;WS_EX_TRANSPARENT $gui = GUICreate("", 1000, 800, -1, -1, -1 , $WS_EX_LAYERED) ; use layered to get _winapi_setlay... to work $pic = GUICtrlCreatePic("c:\Program Files (x86)\AutoIt3\Examples\GUI\Merlin.gif", 0,0,1000, 800) GUICtrlSetState(-1, $GUI_DISABLE) $edit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32,200,600) GUICtrlSetBkColor(-1,$COLOR_YELLOW) _WinAPI_SetLayeredWindowAttributes($gui,$COLOR_YELLOW,199) ; 199 is alpha (transparency level) GUISetState(@SW_SHOW,$gui) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Func Terminate() exit(0) EndFunc So I am making the edit box's background yellow then using the _WINAPI_SetLayeredWIndowAttributes command to make the yellow disappear (which it does), but the alpha level is supposed to give a bit of opaqueness to it, but its not, just making it totally transparent.  The alpha level is in fact affecting the window itself and not the edit box. I only want the edit box to be partially transparent.
      Help appreciated.
       
    • ISI360
      By ISI360
      Hi!
      I am searching for a way to display a transparent image (or Icon) over an Button. And the image should always stay on top.

      Here is what i have so far:
      At script start the picture is over the button..but if you move the mouse over the button it overlaps the image.
      And if i add $GUI_ONTOP to the picture, the transparency is gone

      Maybe someone has an idea..

      Thanks in advance!
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIIcons.au3> #include <WinAPIShellEx.au3> GUICreate("GUI", 300, 300) $hbutton = GUICtrlCreateButton("This is a button", 20, 40, 150, 30,$WS_CLIPSIBLINGS) $hpic = GUICtrlCreatePic("", 10, 10, 128, 128) _SetIconAlpha($hpic,"shell32.dll", 12,128,128) GUICtrlSetState(-1, $GUI_DISABLE) ;~ GUICtrlSetState(-1,$GUI_ONTOP) ;If you uncomment this..the picture is on top...but the transparency is gone :( GUISetState() While 1 $Msg = GUIGetMsg() If $Msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func _SetIconAlpha($hWnd, $sIcon, $iIndex, $iWidth, $iHeight) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If $hWnd = 0 Then Return SetError(1, 0, 0) EndIf EndIf If $iIndex <> 0 Then $iIndex = $iIndex - 1 Local $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) If $hIcon = 0 Then Return SetError(1, 0, 0) EndIf Local $hBitmap, $hObj, $hDC, $hMem, $hSv $hDC = _WinAPI_GetDC($hWnd) $hMem = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) $hSv = _WinAPI_SelectObject($hMem, $hBitmap) _WinAPI_DrawIconEx($hMem, 0, 0, $hIcon, $iWidth, $iHeight, 0, 0, 2) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_SelectObject($hMem, $hSv) _WinAPI_DeleteDC($hMem) _WinAPI_DestroyIcon($hIcon) _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0172, 0, 0)) _SendMessage($hWnd, 0x0172, 0, $hBitmap) $hObj = _SendMessage($hWnd, 0x0173) If $hObj <> $hBitmap Then _WinAPI_DeleteObject($hBitmap) EndIf Return 1 EndFunc ;==>_SetIconAlpha  
    • lenclstr746
      By lenclstr746
      HELLO GUYS
      I'm a work on a background see and click bot project 
      I can complete it if your help me
      (using imagesearch , gdi+ and  fastfind)
×