Jump to content

GDI+ clock


PaulIA
 Share

Recommended Posts

This demo requires the latest version of Auto3Lib in order to run

I've been asked by several forum members how to do some advanced things with the Auto3Lib GDI+ functions. I worked up a clock demo that shows how to use the GDI and GDI+ functions to create layered windows without using PNG images. This demo uses 6 transparent windows to dynamically build a clock with digital and analog time displays. Even though there are 6 different windows (and AutoIt is no speed demon), the animation is smooth and flicker free.

This demo shows a variety of advanced techniques for working with GDI and GDI+ functions. It not only demonstrates how to use transparencies, but shows how to render text and graphics to an off screen buffer. It should be a good starting point for those of you who are interested in generating exotic GUI windows.

The code for the demo (Clock.au3) is in the Auto3Lib GDI+ folder. Auto3Lib can be downloaded here. Here's a screen shot of what the clock looks like:

Posted Image

Edit: I have put out a new version of this demo that reduces the CPU utilization that some people where seeing. Please download the new version of Auto3Lib if you were having this problem. Thanks to RazerM for the help in resolving this issue. This release also includes a new GDI+ demo that shows how to enlarge/zoom/magnify a portion of an image. Check out the Zoom demo in the Auto3Lib GDI+ folder.

Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

simply excellent

to draw multiline, do have i to set multiple objects (one per line) ?

nevermind, it works on multiline, just forgotten to increase the height of the rect |)

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Nice example, but CPU usage is quite high.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Geez, what are you guys running? I've got a 2.93 Ghz machine and when I run the demo it runs at 0% CPU utilization. If this demo pegs your CPU, I'm guessing you don't play many games. :rolleyes: You might try replacing the ClockLoop() function with this to see if it makes a difference:

Func ClockLoop()
  do
    Draw()
  until GUIGetMsg() = $GUI_EVENT_CLOSB[[
Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I have 2.8GHz processor and was using about 20% - 25% CPU. That change does make it significantly less though.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

I have 2.8GHz processor and was using about 20% - 25% CPU. That change does make it significantly less though.

How much less? I can't reproduce this on any of the machines that I have, so it'd be nice to know. I've run into problems before using AdLib, so I'll change the demo for the next release.

As a side note, the demo was written for clarity, not speed. I wanted users to be able to follow the logical flow and be able to use the code in other scripts, much like how the code that I wrote for lod3n got copied to several other scripts. The first version of this demo only used 3 windows and was not broken up into as many sub routines. It was much smaller/faster, but I didn't think anybody would be able to follow what I was doing. I think I'll clean that version up a little and include it in the next release, just so people have a comparison.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

CPU before change was about 20%-25% (with other apps running)

after change CPU usage stayed about 6% but peaked about 20% every so often (same apps running)

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

CPU before change was about 20%-25% (with other apps running)

after change CPU usage stayed about 6% but peaked about 20% every so often (same apps running)

Thanks for your help in resolving this problem. I believe the new code I just put out should get you down to an acceptable CPU utilization.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

really strange, for me the code keep the cpu utilization at 0% too :rolleyes:, and i've an AMD 2400+

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Don't know if new version released but PaulIA fixed a memory leak in Auto3Lib and CPU utilization issue was fixed.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

ok :rolleyes:

Paul, is is possible to play with image without via imagefile ?

for example, for the zoom script, i would like to know if it's possible to do so without a file

thanx !

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

ok :rolleyes:

Paul, is is possible to play with image without via imagefile ?

for example, for the zoom script, i would like to know if it's possible to do so without a file

thanx !

Here is a version of the Zoom.au3 script converted to use the bitmap from the screen capture instead of the file:

#include <A3LGDIPlus.au3>
#include <A3LScreenCap.au3>

Opt(&quoÓ]ÝXÛUÉ][ÝËJBÛØ[    ÌÍÚT ÌÍÚÕRLK ÌÍÚÕRL  3c¶&FÖÂb33c¶w&3Âb33c¶w&3  £²6GW&RF÷ÆVgB6÷&æW"öbÑ¡Íɸ(ÀÌØí¡   5@ô}Mɹ
Á}
ÁÑÕÉ ÅÕ½ÐìÅÕ½Ðì°À°À°ÐÀÀ°ÌÀÀ¤((ìCreate a GUI for the original image
$hGUI1 = GUICreate("Original&][ÝË
Ì
BÕRTÙ]Ý]J
BÈÜX]HHÕRHÜHÛÛYY[XYÙBb33c¶uT"ÒuT7&VFRgV÷Cµ¦ööÖVBgV÷C²ÂCÂ3ÂÂC¤uT6WE7FFR¤((ì%¹¥Ñ¥±¥é$¬±¥ÉÉä¹±½¥µ)}%A}MÑÉÑÕÀ ¤(ÀÌØí¡  ¥ÑµÀô_GDIP_BitmapCreateFromHBITMAP($hBMP)

; Draw original image
$hGraXÌHHÑÑTÑÜXÜÐÜX]QÛRÓ
    ÌÍÚÕRLJBÑÑTÑÜXÜÑ]Ò[XYÙJ 3c¶w&3Âb33c¶&FÖ £²G&r'¦ööÖVBÖvP¢b33c¶w&3"ô}%A}ÉÁ¡¥Í
ÉÑɽµ!]9 ÀÌØí¡U$Ȥ)}%A}ÉÁ¡¥ÍÉÝ%µIÑIÐ$hGraphic2, $hBitmap, 0, 0, 200, 200, 0, 0, 400, 300)

; Release ÛÝÙÂÑÑTÑÜXÜÑÜÜÙJ ÌÍÚÜXÌJBÑÑTÑÜXÜÑÜÜÙJ  ÌͶw&3"¥ôôFVÆWFTö&¦V7Bb33c¶&×¥ôtDõ6WFF÷vâ £²Æö÷VçFÂW6Èá¥ÑÌ)¼)չѥ°U%Ñ5Í ¤ôÀÌØíU%}Y9Q}
1=M
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

excellent, i tried with the wrong function ( i used _GDIP_GraphicsCreateFromHWND instead of _GDIP_BitmapCreateFromHBITMAP), erf :/

thx for your help !

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Replacing the ClockLoop() function just lowered the cpu usage little - it's now around 20-30% not 30-40. And the system is highly lagged. I mean everything _slows_ down... I have no background processes running - only the default system processes (+firefox, scite & pspad).

Even if I place Sleep(1000) inside ClockLoop do...until the system is still lagged and the CPU usage high.

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