Jump to content
Sign in to follow this  
Skitty

Clearing a GDI GUI background image?

Recommended Posts

Skitty

How do I get this to clear the GUI with the updated text? Preferably without having it flash and flicker.

#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Global Const $sTIME = '|00;12:AM|01;01:AM|02;02:AM|03;03:AM|04;04:AM' & _
       '|05;05:AM|06;06:AM|07;07:AM|08;08:AM|09;09:AM' & _
       '|10;10:AM|11;11:AM|12;12:PM|13;01:PM|14;02:PM' & _
       '|15;03:PM|16;04:PM|17;05:PM|18;06:PM|19;07:PM' & _
       '|20;08:PM|21;09:PM|22;10:PM|23;11:PM|'
_GDIPlus_Startup()
$kPen = _GDIPlus_BrushCreateSolid()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)
$hFormat = _GDIPlus_StringFormatCreate ()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$Display = GUICreate("temptext", 100, 25, -1, -1, BitOR($WS_POPUP,$WS_CLIPCHILDREN), $WS_EX_LAYERED+$WS_EX_TOPMOST)
GUISetBkColor(0x010101,$Display)
GUICtrlCreatePic("",0,0,100,24,-1,BitOR(0x00100000,0x00000020))
GUISetState(@SW_SHOW,$Display)
_WinAPI_SetLayeredWindowAttributes($Display, 0x010101)
$tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display)
$ttLayout = _GDIPlus_RectFCreate (0, 0, 100, 25)

Init()
Func Init()
While 1
  _GDIPlus_GraphicsDispose($tGraphic)
  $tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display)
  $ttLayout = _GDIPlus_RectFCreate (0, 0, 100, 25)
  _GDIPlus_GraphicsDrawStringEx($tGraphic, Time(), $hFont, $ttLayout, $hFormat, $kPen)
WEnd
EndFunc
Func Time()
Local $sHOUR = String(@HOUR), $TIME = StringRegExp($sTIME, "\|" & $sHOUR & ";(.*?):(.*?)\|", 3)
Return $TIME[0]&':'&@MIN&':'&@SEC& ' ' & $TIME[1]
EndFunc
Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
Beege

Still not perfect as far as flickering goes though...

#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Global Const $sTIME = '|00;12:AM|01;01:AM|02;02:AM|03;03:AM|04;04:AM' & _
        '|05;05:AM|06;06:AM|07;07:AM|08;08:AM|09;09:AM' & _
        '|10;10:AM|11;11:AM|12;12:PM|13;01:PM|14;02:PM' & _
        '|15;03:PM|16;04:PM|17;05:PM|18;06:PM|19;07:PM' & _
        '|20;08:PM|21;09:PM|22;10:PM|23;11:PM|'
_GDIPlus_Startup()
$kPen = _GDIPlus_BrushCreateSolid()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$Display = GUICreate("temptext", 100, 25, -1, -1, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetBkColor(0x010101, $Display)
GUICtrlCreatePic("", 0, 0, 100, 24, -1, BitOR(0x00100000, 0x00000020))
GUISetState(@SW_SHOW, $Display)
_WinAPI_SetLayeredWindowAttributes($Display, 0x010101)
$tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display)
$ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)

$sLast = ''
Init()
Func Init()
    While 1
        $sUpdate = Time()
        If $sLast <> $sUpdate Then
            _GDIPlus_GraphicsClear($tGraphic, 0xFF010101)
            _GDIPlus_GraphicsDispose($tGraphic)
            $tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display)
            $ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)
            _GDIPlus_GraphicsDrawStringEx($tGraphic, $sUpdate, $hFont, $ttLayout, $hFormat, $kPen)
            $sLast = $sUpdate
        EndIf
        Sleep(100)
    WEnd
EndFunc   ;==>Init

Func Time()
    Local $sHOUR = String(@HOUR), $TIME = StringRegExp($sTIME, "|" & $sHOUR & ";(.*?):(.*?)|", 3)
    Return $TIME[0] & ':' & @MIN & ':' & @SEC & ' ' & $TIME[1]
EndFunc   ;==>Time

Share this post


Link to post
Share on other sites
Skitty

Still not perfect as far as flickering goes though...

I'm trying to make a little alarm clock to help me remember things I've been missing every now and then, thank you! It's perfect for me and the flickering isn't noticeable as it was when I was doing something else to clear it.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
Skitty

Here's what I was making, my code still has unintended features such as the sound selection dialog repetitively popping up if you bring it up a second time, it's supposed to be an alarm thing to help me remember when I should pick up my cousin from school, which I keep forgetting when I'm really into something...

#include <WindowsConstants.au3>

#include <GDIPlus.au3>

Global Const $sTIME = '|00;12:AM|01;01:AM|02;02:AM|03;03:AM|04;04:AM' & _

'|05;05:AM|06;06:AM|07;07:AM|08;08:AM|09;09:AM' & _

'|10;10:AM|11;11:AM|12;12:PM|13;01:PM|14;02:PM' & _

'|15;03:PM|16;04:PM|17;05:PM|18;06:PM|19;07:PM' & _

'|20;08:PM|21;09:PM|22;10:PM|23;11:PM|'

Global $sound

Global $HOUR = StringRegExp($sTIME, "|" & @HOUR & ";(.*?):).*?)|", 3)

Global $AM_PM = $HOUR[1]

$HOUR = $HOUR[0]

Global $MIN = "00"

Global $SEC = "00"

Global $Recur = 1

;Global $hWnd = GUICreate("Time", 80, 15, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))

_GDIPlus_Startup()

Global $kPen = _GDIPlus_BrushCreateSolid(0xFFff0000)

Global $hFamily = _GDIPlus_FontFamilyCreate("Impact")

Global $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)

Global $hFormat = _GDIPlus_StringFormatCreate()

_GDIPlus_StringFormatSetAlign($hFormat, 1)

Global $hWnd = GUICreate("temptext", 100, 25, -1, -1, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED + $WS_EX_TOPMOST)

GUISetBkColor(0x010101, $hWnd)

GUICtrlCreatePic("", 0, 0, 100, 24, -1, BitOR(0x00100000, 0x00000020))

GUISetState(@SW_SHOW, $hWnd)

_WinAPI_SetLayeredWindowAttributes($hWnd, 0x010101)

Global $tGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)

Global $ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)

Global $sLast = ''

OnAutoItExitRegister("_Exit")

Init()

Func Init()

Opt("TrayMenuMode", 1)

Local $Set = TrayCreateItem("Set", -1, 1)

TrayCreateItem("")

Local $TrayExit = TrayCreateItem("Exit", -1, 2)

TraySetClick(16); set right clicking only

Local $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM

Local $oLS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM

Local $TmpTime = @HOUR

Local $TmpMin = @MIN

While 1

Switch TrayGetMsg()

Case $TrayExit

Exit

Case $Set, -13; -13 is a message sent when you double click the tray icon

$GUI = GUICreate("Configure", 130, 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))

GUICtrlCreateLabel("Time:", 0, 0, 30, 17)

$lTime = GUICtrlCreateLabel($HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM, 32, 0, 65, 17)

$Set2 = GUICtrlCreateButton("Set", 0, 15, 30, 30)

$1 = GUICtrlCreateButton("▲", 30, 15, 16, 15)

$2 = GUICtrlCreateButton("▼", 30, 30, 16, 15)

$3 = GUICtrlCreateButton("▲", 46, 15, 16, 15)

$4 = GUICtrlCreateButton("▼", 46, 30, 16, 15)

$5 = GUICtrlCreateButton("▲", 62, 15, 16, 15)

$6 = GUICtrlCreateButton("▼", 62, 30, 16, 15)

$7 = GUICtrlCreateButton("▲", 78, 15, 16, 15)

$8 = GUICtrlCreateButton("▼", 78, 30, 16, 15)

$snd = GUICtrlCreateIcon("snd.ico", -1, 96, 8, 32, 32)

GUISetState(@SW_SHOW)

While 1

Switch GUIGetMsg()

Case -3

GUIDelete($GUI)

$Recur = 0

ExitLoop

Case $snd

$sound = FileOpenDialog("Sound","","All(*.*)")

Case $1

$TmpTime += 1

If $TmpTime > 23 Then $TmpTime = 0

If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)

$HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?);).*?)|", 3)

$AM_PM = $HOUR[1]

$HOUR = $HOUR[0]

Case $2

$TmpTime -= 1

If $TmpTime < 0 Then $TmpTime = 23

If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)

$HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?);).*?)|", 3)

$AM_PM = $HOUR[1]

$HOUR = $HOUR[0]

Case $3

$TmpMin += 1

If $TmpMin > 59 Then

$TmpMin = 0

$TmpTime += 1

If $TmpTime > 23 Then $TmpTime = 0

If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)

$HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?):).*?)|", 3)

$AM_PM = $HOUR[1]

$HOUR = $HOUR[0]

EndIf

If StringLen($TmpMin) < 2 Then $TmpMin = "0" & String($TmpMin)

$MIN = $TmpMin

Case $4

$TmpMin -= 1

If $TmpMin < 0 Then

$TmpMin = 59

$TmpTime -= 1

If $TmpTime < 0 Then $TmpTime = 23

If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)

$HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?):D.*?)|", 3)

$AM_PM = $HOUR[1]

$HOUR = $HOUR[0]

EndIf

If StringLen($TmpMin) < 2 Then $TmpMin = "0" & String($TmpMin)

$MIN = $TmpMin

EndSwitch

$LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM

If $LS_TIME <> $oLS_TIME Then

$LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM

$oLS_TIME = $LS_TIME

GUICtrlSetData($lTime, $LS_TIME)

EndIf

WEnd

EndSwitch

If Number($TmpTime) = Number(@HOUR) And Number(@MIN) >= Number($MIN) And Not $Recur Then

Warn()

$Recur = 1

EndIf

$sUpdate = Time()

If $sLast <> $sUpdate Then

_GDIPlus_GraphicsClear($tGraphic, 0xFF010101)

_GDIPlus_GraphicsDispose($tGraphic)

$tGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)

$ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)

_GDIPlus_GraphicsDrawStringEx($tGraphic, $sUpdate, $hFont, $ttLayout, $hFormat, $kPen)

$sLast = $sUpdate

EndIf

If GUIGetMsg($hWnd) = -3 Then Exit

WEnd

EndFunc ;==>Init

Func Warn()

SoundPlay($sound)

EndFunc ;==>Warn

Func Time()

Local $sHOUR = String(@HOUR), $TIME = StringRegExp($sTIME, "|" & $sHOUR & ";(.*?):D.*?)|", 3)

Return Number($TIME[0]) & ':' & @MIN & ':' & @SEC & ' ' & $TIME[1]

EndFunc ;==>Time

Func _Exit()

_GDIPlus_FontFamilyDispose($hFamily)

_GDIPlus_FontDispose($hFont)

_GDIPlus_Shutdown()

EndFunc

[/autoit]

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
Skitty

Here's what I was making, my code still has unintended features such as the sound selection dialog repetitively popping up if you bring it up a second time, it's supposed to be an alarm thing to help me remember when I should pick up my cousin from school, which I keep forgetting when I'm really into something...

#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Global Const $sTIME = '|00;12:AM|01;01:AM|02;02:AM|03;03:AM|04;04:AM' & _
  '|05;05:AM|06;06:AM|07;07:AM|08;08:AM|09;09:AM' & _
  '|10;10:AM|11;11:AM|12;12:PM|13;01:PM|14;02:PM' & _
  '|15;03:PM|16;04:PM|17;05:PM|18;06:PM|19;07:PM' & _
  '|20;08:PM|21;09:PM|22;10:PM|23;11:PM|'
Global $sound
Global $HOUR = StringRegExp($sTIME, "\|" & @HOUR & ";(.*?)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />.*?)\|", 3)
Global $AM_PM = $HOUR[1]
$HOUR = $HOUR[0]
Global $MIN = "00"
Global $SEC = "00"
Global $Recur = 1
;Global $hWnd = GUICreate("Time", 80, 15, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
_GDIPlus_Startup()
Global $kPen = _GDIPlus_BrushCreateSolid(0xFFff0000)
Global $hFamily = _GDIPlus_FontFamilyCreate("Impact")
Global $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
Global $hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
Global $hWnd = GUICreate("temptext", 100, 25, -1, -1, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetBkColor(0x010101, $hWnd)
GUICtrlCreatePic("", 0, 0, 100, 24, -1, BitOR(0x00100000, 0x00000020))
GUISetState(@SW_SHOW, $hWnd)
_WinAPI_SetLayeredWindowAttributes($hWnd, 0x010101)
Global $tGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Global $ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)
Global $sLast = ''
OnAutoItExitRegister("_Exit")
Init()
Func Init()
Opt("TrayMenuMode", 1)
Local $Set = TrayCreateItem("Set", -1, 1)
TrayCreateItem("")
Local $TrayExit = TrayCreateItem("Exit", -1, 2)
TraySetClick(16); set right clicking only
Local $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
Local $oLS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
Local $TmpTime = @HOUR
Local $TmpMin = @MIN
While 1
  Switch TrayGetMsg()
   Case $TrayExit
    Exit
   Case $Set, -13; -13 is a message sent when you double click the tray icon
    $GUI = GUICreate("Configure", 130, 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
    GUICtrlCreateLabel("Time:", 0, 0, 30, 17)
    $lTime = GUICtrlCreateLabel($HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM, 32, 0, 65, 17)
    $Set2 = GUICtrlCreateButton("Set", 0, 15, 30, 30)
    $1 = GUICtrlCreateButton("▲", 30, 15, 16, 15)
    $2 = GUICtrlCreateButton("▼", 30, 30, 16, 15)
    $3 = GUICtrlCreateButton("▲", 46, 15, 16, 15)
    $4 = GUICtrlCreateButton("▼", 46, 30, 16, 15)
    $5 = GUICtrlCreateButton("▲", 62, 15, 16, 15)
    $6 = GUICtrlCreateButton("▼", 62, 30, 16, 15)
    $7 = GUICtrlCreateButton("▲", 78, 15, 16, 15)
    $8 = GUICtrlCreateButton("▼", 78, 30, 16, 15)
    $snd = GUICtrlCreateIcon("snd.ico", -1, 96, 8, 32, 32)
    GUISetState(@SW_SHOW)
    While 1
     Switch GUIGetMsg()
      Case -3
       GUIDelete($GUI)
       $Recur = 0
       ExitLoop
      Case $snd
       $sound = FileOpenDialog("Sound","","All(*.*)")
      Case $1
       $TmpTime += 1
       If $TmpTime > 23 Then $TmpTime = 0
       If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
       $HOUR = StringRegExp($sTIME, "\|" & $TmpTime & ";(.*?)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />.*?)\|", 3)
       $AM_PM = $HOUR[1]
       $HOUR = $HOUR[0]
      Case $2
       $TmpTime -= 1
       If $TmpTime < 0 Then $TmpTime = 23
       If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
       $HOUR = StringRegExp($sTIME, "\|" & $TmpTime & ";(.*?)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />.*?)\|", 3)
       $AM_PM = $HOUR[1]
       $HOUR = $HOUR[0]
      Case $3
       $TmpMin += 1
       If $TmpMin > 59 Then
        $TmpMin = 0
        $TmpTime += 1
        If $TmpTime > 23 Then $TmpTime = 0
        If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
        $HOUR = StringRegExp($sTIME, "\|" & $TmpTime & ";(.*?)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />.*?)\|", 3)
        $AM_PM = $HOUR[1]
        $HOUR = $HOUR[0]
       EndIf
       If StringLen($TmpMin) < 2 Then $TmpMin = "0" & String($TmpMin)
       $MIN = $TmpMin
      Case $4
       $TmpMin -= 1
       If $TmpMin < 0 Then
        $TmpMin = 59
        $TmpTime -= 1
        If $TmpTime < 0 Then $TmpTime = 23
        If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
        $HOUR = StringRegExp($sTIME, "\|" & $TmpTime & ";(.*?)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />.*?)\|", 3)
        $AM_PM = $HOUR[1]
        $HOUR = $HOUR[0]
       EndIf
       If StringLen($TmpMin) < 2 Then $TmpMin = "0" & String($TmpMin)
       $MIN = $TmpMin
     EndSwitch
     $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
     If $LS_TIME <> $oLS_TIME Then
      $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
      $oLS_TIME = $LS_TIME
      GUICtrlSetData($lTime, $LS_TIME)
     EndIf
    WEnd
  EndSwitch
  If Number($TmpTime) = Number(@HOUR) And Number(@MIN) >= Number($MIN) And Not $Recur Then
   Warn()
   $Recur = 1
  EndIf
        $sUpdate = Time()
        If $sLast <> $sUpdate Then
            _GDIPlus_GraphicsClear($tGraphic, 0xFF010101)
            _GDIPlus_GraphicsDispose($tGraphic)
            $tGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
            $ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)
            _GDIPlus_GraphicsDrawStringEx($tGraphic, $sUpdate, $hFont, $ttLayout, $hFormat, $kPen)
            $sLast = $sUpdate
        EndIf
  If GUIGetMsg($hWnd) = -3 Then Exit
WEnd
EndFunc   ;==>Init
Func Warn()
SoundPlay($sound)
EndFunc   ;==>Warn
Func Time()
Local $sHOUR = String(@HOUR), $TIME = StringRegExp($sTIME, "\|" & $sHOUR & ";(.*?)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />.*?)\|", 3)
Return Number($TIME[0]) & ':' & @MIN & ':' & @SEC & ' ' & $TIME[1]
EndFunc   ;==>Time
Func _Exit()
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_Shutdown()
EndFunc

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
UEZ

Here a modification of your code using back buffer technique to avoid flickering.

#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Global Const $sTIME = '|00;12:AM|01;01:AM|02;02:AM|03;03:AM|04;04:AM' & _
        '|05;05:AM|06;06:AM|07;07:AM|08;08:AM|09;09:AM' & _
        '|10;10:AM|11;11:AM|12;12:PM|13;01:PM|14;02:PM' & _
        '|15;03:PM|16;04:PM|17;05:PM|18;06:PM|19;07:PM' & _
        '|20;08:PM|21;09:PM|22;10:PM|23;11:PM|'
Global $sound
Global $HOUR = StringRegExp($sTIME, "|" & @HOUR & ";(.*?):(.*?)|", 3)
Global $AM_PM = $HOUR[1]
$HOUR = $HOUR[0]
Global $MIN = "00"
Global $SEC = "00"
Global $Recur = 1
;Global $hWnd = GUICreate("Time", 80, 15, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
_GDIPlus_Startup()
Global $kPen = _GDIPlus_BrushCreateSolid(0xFFff0000)
Global $hFamily = _GDIPlus_FontFamilyCreate("Impact")
Global $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
Global $hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
Global $hWnd = GUICreate("temptext", 100, 25, -1, -1, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetBkColor(0x010101, $hWnd)
GUICtrlCreatePic("", 0, 0, 100, 24, -1, BitOR(0x00100000, 0x00000020))
GUISetState(@SW_SHOW, $hWnd)
_WinAPI_SetLayeredWindowAttributes($hWnd, 0x010101)
Global $tGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 25, $tGraphic)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
Global $ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)
Global $sLast = ''
OnAutoItExitRegister("_Exit")

Init()

Func Init()
    Opt("TrayMenuMode", 1)
    Local $Set = TrayCreateItem("Set", -1, 1)
    TrayCreateItem("")
    Local $TrayExit = TrayCreateItem("Exit", -1, 2)
    TraySetClick(16); set right clicking only
    Local $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
    Local $oLS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
    Local $TmpTime = @HOUR
    Local $TmpMin = @MIN
    While 1
        Switch TrayGetMsg()
            Case $TrayExit
                Exit
            Case $Set, -13; -13 is a message sent when you double click the tray icon
                $GUI = GUICreate("Configure", 130, 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
                GUICtrlCreateLabel("Time:", 0, 0, 30, 17)
                $lTime = GUICtrlCreateLabel($HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM, 32, 0, 65, 17)
                $Set2 = GUICtrlCreateButton("Set", 0, 15, 30, 30)
                $1 = GUICtrlCreateButton("?", 30, 15, 16, 15)
                $2 = GUICtrlCreateButton("?", 30, 30, 16, 15)
                $3 = GUICtrlCreateButton("?", 46, 15, 16, 15)
                $4 = GUICtrlCreateButton("?", 46, 30, 16, 15)
                $5 = GUICtrlCreateButton("?", 62, 15, 16, 15)
                $6 = GUICtrlCreateButton("?", 62, 30, 16, 15)
                $7 = GUICtrlCreateButton("?", 78, 15, 16, 15)
                $8 = GUICtrlCreateButton("?", 78, 30, 16, 15)
                $snd = GUICtrlCreateIcon("snd.ico", -1, 96, 8, 32, 32)
                GUISetState(@SW_SHOW)
                While 1
                    Switch GUIGetMsg()
                        Case -3
                            GUIDelete($GUI)
                            $Recur = 0
                            ExitLoop
                        Case $snd
                            $sound = FileOpenDialog("Sound", "", "All(*.*)")
                        Case $1
                            $TmpTime += 1
                            If $TmpTime > 23 Then $TmpTime = 0
                            If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
                            $HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?):(.*?)|", 3)
                            $AM_PM = $HOUR[1]
                            $HOUR = $HOUR[0]
                        Case $2
                            $TmpTime -= 1
                            If $TmpTime < 0 Then $TmpTime = 23
                            If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
                            $HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?):(.*?)|", 3)
                            $AM_PM = $HOUR[1]
                            $HOUR = $HOUR[0]
                        Case $3
                            $TmpMin += 1
                            If $TmpMin > 59 Then
                                $TmpMin = 0
                                $TmpTime += 1
                                If $TmpTime > 23 Then $TmpTime = 0
                                If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
                                $HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?):(.*?)|", 3)
                                $AM_PM = $HOUR[1]
                                $HOUR = $HOUR[0]
                            EndIf
                            If StringLen($TmpMin) < 2 Then $TmpMin = "0" & String($TmpMin)
                            $MIN = $TmpMin
                        Case $4
                            $TmpMin -= 1
                            If $TmpMin < 0 Then
                                $TmpMin = 59
                                $TmpTime -= 1
                                If $TmpTime < 0 Then $TmpTime = 23
                                If StringLen($TmpTime) < 2 Then $TmpTime = "0" & String($TmpTime)
                                $HOUR = StringRegExp($sTIME, "|" & $TmpTime & ";(.*?):(.*?)|", 3)
                                $AM_PM = $HOUR[1]
                                $HOUR = $HOUR[0]
                            EndIf
                            If StringLen($TmpMin) < 2 Then $TmpMin = "0" & String($TmpMin)
                            $MIN = $TmpMin
                    EndSwitch
                    $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
                    If $LS_TIME <> $oLS_TIME Then
                        $LS_TIME = $HOUR & ":" & $MIN & ":" & $SEC & " " & $AM_PM
                        $oLS_TIME = $LS_TIME
                        GUICtrlSetData($lTime, $LS_TIME)
                    EndIf
                WEnd
        EndSwitch
        If Number($TmpTime) = Number(@HOUR) And Number(@MIN) >= Number($MIN) And Not $Recur Then
            Warn()
            $Recur = 1
        EndIf
        $sUpdate = Time()
        If $sLast <> $sUpdate Then
            _GDIPlus_GraphicsClear($hBackbuffer, 0xFF010101)
            $ttLayout = _GDIPlus_RectFCreate(0, 0, 100, 25)
            _GDIPlus_GraphicsDrawStringEx($hBackbuffer, $sUpdate, $hFont, $ttLayout, $hFormat, $kPen)
            _GDIPlus_GraphicsDrawImage($tGraphic, $hBitmap, 0, 0)
            $sLast = $sUpdate
        EndIf
        If GUIGetMsg($hWnd) = -3 Then Exit
    WEnd
EndFunc   ;==>Init

Func Warn()
    SoundPlay($sound)
EndFunc   ;==>Warn

Func Time()
    Local $sHOUR = String(@HOUR), $TIME = StringRegExp($sTIME, "|" & $sHOUR & ";(.*?):(.*?)|", 3)
    Return Number($TIME[0]) & ':' & @MIN & ':' & @SEC & ' ' & $TIME[1]
EndFunc   ;==>Time

Func _Exit()
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_GraphicsDispose($tGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_Exit

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
Skitty

Here a modification of your code using back buffer technique to avoid flickering.

Br, UEZ

Thanks, both examples are pretty informative :)


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

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  

×