Renderer

Desktop Clock

4 posts in this topic

#1 ·  Posted (edited)

Here's my litte desktop clock:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>
;

global $popup = GUICreate('DesktopClock',300,50,@DesktopWidth+(-330),@DesktopHeight+(-100),$WS_POPUP)
   GUISetBkColor(0x000000)
   global $clockLabel = GUICtrlCreateLabel('',30,5,450,30)
   GUICtrlSetFont($clockLabel,20,0,0,'Segoe UI')
   GUICtrlSetColor($clockLabel,0x32cd32)
   WinSetTrans($popup,"",190)
GUISetState()

While 1
   Switch GUIGetMsg()
   case -3
      ExitLoop
   EndSwitch

   _GetTime_()

WEnd



Func _GetTime_()
   GUICtrlSetData($clockLabel, 'Local time: ' & @Hour & ":" & @Min & ":" & @sec)
   Sleep(1000)
   _GetTime_()

EndFunc

There is a little problem. I cannot exit the program , because the _GetTime_() function is written once again into the _GetTime_() function definition. So the program only updates the date and time.

Edited by Renderer

Share this post


Link to post
Share on other sites



Here are a few quick suggestions:

  • 2 of your includes are not needed
  • AdlibRegister calls a specified function at specified intervals, so instead of having the _GetTime_ function call itself once the script starts (and then get stuck in it), AdlibRegister will just go there once a second
  • Call _GetTime_ after the AdlibRegister so the clock has a chance to display before the first 1-second interval passes
  • Run Tidy  :)  (CTRL-T)

 

Please see the modified code below, anything not needed I just commented out rather than deleted.

 

#include <WindowsConstants.au3>
;~ #include <GUIConstantsEx.au3>
;~ #include <misc.au3>

Global $popup = GUICreate('DesktopClock', 300, 50, @DesktopWidth + (-330), @DesktopHeight + (-100), $WS_POPUP)
GUISetBkColor(0x000000)
Global $clockLabel = GUICtrlCreateLabel('', 30, 5, 450, 30)
GUICtrlSetFont($clockLabel, 20, 0, 0, 'Segoe UI')
GUICtrlSetColor($clockLabel, 0x32cd32)
WinSetTrans($popup, "", 190)
GUISetState()

AdlibRegister("_GetTime_",1000)
_GetTime_()

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
    EndSwitch
;~  _GetTime_()
WEnd



Func _GetTime_()
    GUICtrlSetData($clockLabel, 'Local time: ' & @HOUR & ":" & @MIN & ":" & @SEC)
;~  Sleep(1000)
;~  _GetTime_()
EndFunc   ;==>_GetTime_

 

 

Ian


My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites

Here are a few quick suggestions:

  • 2 of your includes are not needed
  • AdlibRegister calls a specified function at specified intervals, so instead of having the _GetTime_ function call itself once the script starts (and then get stuck in it), AdlibRegister will just go there once a second
  • Call _GetTime_ after the AdlibRegister so the clock has a chance to display before the first 1-second interval passes
  • Run Tidy  :)  (CTRL-T)

 

Please see the modified code below, anything not needed I just commented out rather than deleted.

 

#include <WindowsConstants.au3>
;~ #include <GUIConstantsEx.au3>
;~ #include <misc.au3>

Global $popup = GUICreate('DesktopClock', 300, 50, @DesktopWidth + (-330), @DesktopHeight + (-100), $WS_POPUP)
GUISetBkColor(0x000000)
Global $clockLabel = GUICtrlCreateLabel('', 30, 5, 450, 30)
GUICtrlSetFont($clockLabel, 20, 0, 0, 'Segoe UI')
GUICtrlSetColor($clockLabel, 0x32cd32)
WinSetTrans($popup, "", 190)
GUISetState()

AdlibRegister("_GetTime_",1000)
_GetTime_()

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
    EndSwitch
;~  _GetTime_()
WEnd



Func _GetTime_()
    GUICtrlSetData($clockLabel, 'Local time: ' & @HOUR & ":" & @MIN & ":" & @SEC)
;~  Sleep(1000)
;~  _GetTime_()
EndFunc   ;==>_GetTime_

 

 

Ian

Thanks! This was helpfull. Exploring the functions may help me on the future.

Share this post


Link to post
Share on other sites

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