News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A Binary Clock : Zigomar

Started by chlankboot, March 31, 2008, 07:10:32 PM

Previous topic - Next topic

chlankboot

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:

  • visually better binary clock (smaller leds) with three color themes (red, green & blue)
  • clock visible while dragging
  • Added the day (of the month) in the tray icon (instead of a static icon)
  • only one instance of the prog. is allowed (was not in the original package)

Complete source is included


[attachment deleted by admin]

thomas_remkus


chlankboot

forgot about shortcuts :

  • double click on the clock to hide it
  • double click on the tray icon to toggle hide/show clock
  • right click on icon or clock to show the context menu
  • context menu : self explaning


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

u

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).
Please use a smaller graphic in your signature.

chlankboot

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?

Tedd

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.)
No snowflake in an avalanche feels responsible.

Tedd

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
No snowflake in an avalanche feels responsible.

chlankboot

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.

u

Ha, layered windows are fun :D

[attachment deleted by admin]
Please use a smaller graphic in your signature.

Tedd

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)
No snowflake in an avalanche feels responsible.

chlankboot

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

chlankboot

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

chlankboot

hi guys,

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


  • visually better binary clock (smaller leds) with three color themes (red, green & blue)
  • clock visible while moving
  • Added the day (date) in the tray icon (instead of a static icon)
  • only one instance of the prog. is allowed (was not in the original package)

Complete source is attached.

[attachment deleted by admin]