The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: chlankboot on March 31, 2008, 07:10:32 PM

Title: A Binary Clock : Zigomar
Post by: chlankboot on March 31, 2008, 07:10:32 PM
just finished a binary clock project (old concept but still a nice idea) and here is the source (winasm project but easily convertible, just put the right path to incs and libs).

the code contains many win32 techniques (gdi, transparency [regions], timers, context menus, form dragging in the client area ...) and the clock looks nice.

of course all the comments or optimization tips are welcome (especially for the messy graphic routines).

19-04-2008 update:

Complete source is included


[attachment deleted by admin]
Title: Re: A Binary Clock : Zigomar
Post by: thomas_remkus on March 31, 2008, 07:36:14 PM
that's cool.
Title: Re: A Binary Clock : Zigomar
Post by: chlankboot on March 31, 2008, 08:34:38 PM
forgot about shortcuts :


the on / off leds are simple 15*15 px bmps, so they can be easily changed to match your favorite color (red is included in the zip)
the exe size (94Kb) is mainly due to the icon size (85Kb)
sorry for the very few comments on the code
Title: Re: A Binary Clock : Zigomar
Post by: u on April 01, 2008, 02:54:00 AM
It's nice :) .
The BitBlt sequence is ok, otherwise the best way is to put that code in a loop, with X/Y/data-src being controlled by an array or algorithmically. But that way is only about making your code take less space in your text-editor :). (and a bit easier to maintain).
Title: Re: A Binary Clock : Zigomar
Post by: chlankboot on April 01, 2008, 07:23:39 AM
Quote from: Ultrano on April 01, 2008, 02:54:00 AM
otherwise the best way is to put that code in a loop, with X/Y/data-src being controlled by an array or algorithmically. But that way is only about making your code take less space in your text-editor :). (and a bit easier to maintain).

got it, and, in fact that will give more readable code, thanks.

by the way i have another concern and i want to share it :
inside timer event handler, the InvalidateRect is used to invalidate the whole client area that is repainted each second. because cells are drawn individually, dont you think that replacing it by InvalidateRgn inside the timer proc (if the value of a cell changes, we invalidate only the region corresponding to that cell) will improve performance?
Title: Re: A Binary Clock : Zigomar
Post by: Tedd on April 01, 2008, 10:55:39 AM
Yeah, try using InvalidateRect (not region) giving the rectangles for the bitmaps. You could either do one big rect enclosing all digits, all separate rects each second, or only those individuals that changed - it depends how much spare space there is and how quickly you can check they changed (obviously it's fast here.)
Title: Re: A Binary Clock : Zigomar
Post by: Tedd on April 02, 2008, 11:17:24 AM
Just a thought..

Unless you're specifically wanting backwards compatibility with earlier windows versions, I would suggest you use a 'layered' window instead of regions. It's much faster and more efficient.
And easy! All you need to do is add the WS_EX_LAYERED ex-style to CreateWindowEx, and call SetLayeredWindowAttributes (on WM_CREATE) - you can specify a masking colour (anything that colour is invisible) and/or a window alpha value. Then you just draw on your window as normal.

Also, for window dragging, you can simply return HTCAPTION in response to WM_NCHITTEST and it works nicely :wink
Title: Re: A Binary Clock : Zigomar
Post by: chlankboot on April 02, 2008, 08:11:49 PM
Quote from: Tedd on April 02, 2008, 11:17:24 AM
Unless you're specifically wanting backwards compatibility with earlier windows versions, I would suggest you use a 'layered' window instead of regions. It's much faster and more efficient.
And easy! All you need to do is add the WS_EX_LAYERED ex-style to CreateWindowEx, and call SetLayeredWindowAttributes (on WM_CREATE) - you can specify a masking colour (anything that colour is invisible) and/or a window alpha value. Then you just draw on your window as normal.
thanks Tedd, will try it right now :U

Quote from: Tedd on April 02, 2008, 11:17:24 AM
Also, for window dragging, you can simply return HTCAPTION in response to WM_NCHITTEST and it works nicely :wink

that was my first try, but i don't know why, with WM_NCHITTEST it works but the other mouse events are ignored (double click or right click), that's why i changed. but anyway i'm interested to know why using WM_NCHITTEST would be better, thanks again dude.
Title: Re: A Binary Clock : Zigomar
Post by: u on April 03, 2008, 12:01:14 AM
Ha, layered windows are fun :D

[attachment deleted by admin]
Title: Re: A Binary Clock : Zigomar
Post by: Tedd on April 03, 2008, 09:47:25 AM
Aaah, well the effect of returning HTCAPTION is to tell the window-manager that the pointer is currently over the caption (i.e. titlebar at the top of the window.) So, then the clicks are interpreted as being on the titlebar instead of the client area.
You could still get it to work by checking the state of the mouse buttons in WM_NCHITTEST and returning the appropriate value to say when it's on the 'caption' or the client-area. (Not sure how effective it would be though - I haven't tested it :lol)
Title: Re: A Binary Clock : Zigomar
Post by: chlankboot on April 04, 2008, 08:31:11 PM
Quote from: Tedd on April 03, 2008, 09:47:25 AM
You could still get it to work by checking the state of the mouse buttons in WM_NCHITTEST and returning the appropriate value to say when it's on the 'caption' or the client-area. (Not sure how effective it would be though - I haven't tested it :lol)

Tedd tested and working :thumbu

Thanks Ultrano for yout sDraw lib: really a great job, will use it for sure
by the way i tested it on vista and it works perfect / 0% CPU
Title: Re: A Binary Clock : Zigomar
Post by: chlankboot on April 04, 2008, 08:46:06 PM
just added some code to allow only one instance of the program :


.data
MutexAtt  SECURITY_ATTRIBUTES <SIZEOF SECURITY_ATTRIBUTES,NULL,TRUE>


and changed startup as follows:


.code
start:
invoke GetModuleHandle, NULL
mov    hInstance,eax
invoke OpenMutex,MUTEX_ALL_ACCESS,FALSE,addr AppName
.if eax==NULL
invoke CreateMutex,addr MutexAtt,TRUE, addr AppName
invoke WinMain, hInstance,NULL,NULL, SW_SHOWDEFAULT
.endif
invoke ExitProcess,eax
Title: Re: A Binary Clock : Zigomar
Post by: chlankboot on April 19, 2008, 08:21:25 AM
hi guys,

i finished this new version of zigomer, new features are:


Complete source is attached.

[attachment deleted by admin]