The MASM Forum

General => The Campus => Topic started by: digelo on January 20, 2013, 01:23:58 AM

Title: Graphic Static
Post by: digelo on January 20, 2013, 01:23:58 AM
Hi
(http://img.ir/gyn.png)
I wanna make that static controls in my application and be able to change its colors and size, Can somebody help me in this?
Title: Re: Graphic Static
Post by: xandaz on January 20, 2013, 01:59:09 AM
    You must subclass it or use your own user defined class and process the messages needed to show those  counters. I'm going to work something out and post later. Ok? Thanks for letting me help. Got to get my hands back on ASM.
Title: Re: Graphic Static
Post by: digelo on January 20, 2013, 05:08:56 AM
Thank you , any help would be most welcome
Title: Re: Graphic Static
Post by: MichaelW on January 20, 2013, 07:14:02 AM
For a 7-segment style display, without a scalable 7-segment font the size change will be difficult.
Title: Re: Graphic Static
Post by: jj2007 on January 20, 2013, 08:04:16 AM
Quote from: MichaelW on January 20, 2013, 07:14:02 AM
For a 7-segment style display, without a scalable 7-segment font the size change will be difficult.

Sounds like a nice little project. LUTs, CreatePolygon, FillRgn, ... ;-)
Title: Re: Graphic Static
Post by: dedndave on January 20, 2013, 08:09:28 AM
i would probably use StretchBlt and draw my own   :P
Title: Re: Graphic Static
Post by: MichaelW on January 20, 2013, 08:55:57 AM
I doubt that StretchBlt would produce good results. I think drawing the digits as a collection of polygons could produce good results, but doing so would be difficult.
Title: Re: Graphic Static
Post by: dedndave on January 20, 2013, 10:43:10 AM
well - it isn't quite clear what he wants
he says he wants "...able to change its colors and size"
but, he doesn't really say if he wants that on the fly or case-by-case

even so - StretchBlt will do fairly well if you SetStretchBltMode to HALFTONE and SetBrushOrgEx
Title: Re: Graphic Static
Post by: MichaelW on January 20, 2013, 01:07:45 PM
For a Windows program I would not bother with any sort of N-segment display. They were a good development in their time, and there are still good reasons to use them for certain applications, but why accept their limitations when you don't have to.
Title: Re: Graphic Static
Post by: Farabi on January 20, 2013, 01:36:51 PM
If you want to draw to the static control you have to use GetWindowLong and change the default procedure address. I cant find any easy way to that directly without changing the control procedure.
Title: Re: Graphic Static
Post by: qWord on January 20, 2013, 05:39:45 PM
That was fiddly ... in the attachment an example (GDI) that may be used as a base.

qWord

EDIT upload: some changes to reduce CPU usage . Also WM_DESTROY was not process by the control.
EDIT2: Further improvements
Title: Re: Graphic Static
Post by: MichaelW on January 20, 2013, 05:58:38 PM
Quote from: dedndave on January 20, 2013, 10:43:10 AM
StretchBlt will do fairly well if you SetStretchBltMode to HALFTONE and SetBrushOrgEx

The attachment contains a quick and dirty test app. I can't see any effect from SetStretchBltMode and SetBrushOrgEx, perhaps because I'm doing something wrong, but even so StretchBlt does much better than I thought it would.

Correction, I can see an effect, but I have to capture the window and zoom it up. The effect does improve the image quality, but it is present only when the size is reduced, and for the best quality you need to be working with a 24-bit bitmap. So it looks like the way to do this is to create the digit bitmap at the largest size, and reduce the size as necessary. The second attachment contains a sample of the result.



Title: Re: Graphic Static
Post by: jj2007 on January 20, 2013, 06:21:00 PM
Quote from: qWord on January 20, 2013, 05:39:45 PM
That was fiddly

That is a great example :t
Title: Re: Graphic Static
Post by: Farabi on January 20, 2013, 07:08:11 PM
Quote from: qWord on January 20, 2013, 05:39:45 PM
That was fiddly ... in the attachment an example (GDI) that may be used as a base.

qWord

Did it drawn on each static control like he want? I see you use a timer for trigering the drawing.
Title: Re: Graphic Static
Post by: Gunther on January 20, 2013, 11:15:49 PM
Hi qWord,

well written example.  :t

Gunther
Title: Re: Graphic Static
Post by: dedndave on January 21, 2013, 01:06:12 AM
one thing you may have noticed, Michael
HALFTONE mode is a lot slower than COLORONCOLOR - lol

nice examples, guys   :t
Title: Re: Graphic Static
Post by: digelo on January 21, 2013, 01:55:07 AM
Thank you guys for your helps specially Qword and Michael.
I just imported Qword's nice example to my application , and now im working on changing its colors while my program is running.
Title: Re: Graphic Static
Post by: MichaelW on January 21, 2013, 06:54:52 AM
Quote from: dedndave on January 21, 2013, 01:06:12 AM
one thing you may have noticed, Michael
HALFTONE mode is a lot slower than COLORONCOLOR – lol

I could not see the difference, but in my crude test looping the code 1000 times directly in the WM_PAINT handler and measuring the loop time with GetTickCount, I get:

~900ms for COLORONCOLOR
~3200ms for HALFTONE
Title: Re: Graphic Static
Post by: Farabi on January 21, 2013, 09:54:09 AM
qWord example a bit compilicated but he is right by using SetWindowLong. You have to create your own procedure for each control and intercept the message.
Title: Re: Graphic Static
Post by: hfheatherfox07 on January 23, 2013, 10:32:01 AM
Quote from: qWord on January 20, 2013, 05:39:45 PM
That was fiddly ... in the attachment an example (GDI) that may be used as a base.

qWord

EDIT upload: some changes to reduce CPU usage . Also WM_DESTROY was not process by the control.
EDIT2: Further improvements


Hey qWord,
I seem to get errors with the Ampersand  "&"
Why ? :(

DigitalClock.asm(63) : error A2008: syntax error : &
fn(5): Macro Called From

DigitalClock.asm(87) : error A2008: syntax error : &
fn(5): Macro Called From


same in the Cntrl.asm

Thank you !
Title: Re: Graphic Static
Post by: digelo on January 23, 2013, 10:57:01 AM
Quote from: hfheatherfox07 on January 23, 2013, 10:32:01 AM
I seem to get errors with the Ampersand  "&"

Replace "&" with "addr"
Title: Re: Graphic Static
Post by: qWord on January 23, 2013, 11:17:02 AM
Quote from: hfheatherfox07 on January 23, 2013, 10:32:01 AMI seem to get errors with the Ampersand  "&"
use MASM32 v11
Title: Re: Graphic Static
Post by: hfheatherfox07 on January 23, 2013, 11:17:49 AM
Quote from: digelo on January 23, 2013, 10:57:01 AM
Quote from: hfheatherfox07 on January 23, 2013, 10:32:01 AM
I seem to get errors with the Ampersand  "&"

Replace "&" with "addr"

Thank you that did it !

@echo off
C:\masm32\bin\ml /c /coff DigitalClock.asm
C:\masm32\bin\ml /c /coff Cntrl.asm
C:\masm32\bin\\link.exe /subsystem:windows DigitalClock.obj Cntrl.obj

pause
Title: Re: Graphic Static
Post by: hfheatherfox07 on January 23, 2013, 11:20:26 AM
lol
never mind too many windows open at one time  :icon_redface:
Title: Re: Graphic Static
Post by: xandaz on January 27, 2013, 12:56:04 PM
   Sorry i took so long. Some nice stuff already. Gotta catchup. Here's my shit example. I think that this is more or less what was intended. Thanks
Title: Re: Graphic Static
Post by: xandaz on January 27, 2013, 12:59:12 PM
   Hey.... btw. Theres some problems with that example. I think it has to do with the memory allocated by the controls. It doesn't seem to free. is it still WM_DESTROY WM_CLOSE for child windows?
Title: Re: Graphic Static
Post by: xandaz on January 27, 2013, 02:03:39 PM
   It's fixed.
Title: Re: Graphic Static
Post by: jj2007 on January 27, 2013, 07:23:05 PM
Works fine :t
You can close a child window by sending WM_CLOSE, 0, 0 - the destroy is automatic then.
Title: Re: Graphic Static
Post by: xandaz on January 28, 2013, 07:39:34 AM
   That's not what i meant. For example, ... in this case you have a child window - the counter. The Counter has more children and allocates memory to allow independece of use, so you can create more than one control. When you click the close button on the top-right corner you get the WM_DESTROY. What does the child window get? i need to get the that memory freed. Anyway i used Heap Functions and then it seems to work.
Title: Re: Graphic Static
Post by: qWord on January 28, 2013, 08:04:07 AM
All windows receive WM_DESTROY/WM_NCDESTROY - that is the place which can be used to free resources.
Also, the common way to remove a child control is to call DestroyWindow() and not sending WM_CLOSE - this is message is send when the X-Button or Alt-F4 (...) of a TLW is pressed.
Title: Re: Graphic Static
Post by: jj2007 on January 28, 2013, 08:06:49 AM
Messages = child
Messages MAIN = parent

Messages MAIN
chg:msgCount    132
uMsg            16
# debChgMsg #   WM_SYSCOMMAND <<<< the click in the upper right corner

Messages MAIN
chg:msgCount    133
uMsg            70
# debChgMsg #   WM_CLOSE

...
Messages
chg:msgCount    140
uMsg            641
# debChgMsg #   WM_KILLFOCUS

...
Messages
chg:msgCount    144
uMsg            130
# debChgMsg #   WM_DESTROY

Messages MAIN
chg:msgCount    145
uMsg            130
# debChgMsg #   WM_DESTROY
Title: Re: Graphic Static
Post by: dedndave on January 28, 2013, 08:08:37 AM
well - the destroy operation is not quite automatic for WM_CLOSE

when a window receives a WM_CLOSE message, the default processing is to call DestroyWindow
if the WndProc for that window processes the WM_CLOSE message without calling DefWindowProc,
and without calling DestroyWindow, then it may not be destroyed
this gives the coder an opportunity to offer an "ok to close" message box or something similar

WM_CLOSE is sent to "ask" a window to shut down
WM_DESTROY is sent to tell a window it is being destroyed
when WM_DESTROY is sent, the window has already been removed from the screen
but - WndProc is obviously still handling this one message
Title: Re: Graphic Static
Post by: xandaz on February 04, 2013, 10:51:35 AM
   thanks... been away for a while. Thanks for the replies. Yeah beacause i was getting errors. But i used HeapAllocs and there was no need for freeing.
Title: Re: Graphic Static
Post by: jj2007 on February 04, 2013, 10:59:16 AM
Quote from: xandaz on February 04, 2013, 10:51:35 AMBut i used HeapAllocs and there was no need for freeing.

Even Microsoft believes that ExitProcess does that job. My practical experience is that if a proggie that made a huge HeapAlloc crashes, the system can become so slow that you are forced to reboot. Remember that HeapAlloc passes huge requests on to VirtualAlloc.
Title: Re: Graphic Static
Post by: xandaz on February 08, 2013, 10:58:05 AM
   well jj... i haven't experienced anything of the sort but it's useful information. thanks
Title: Re: Graphic Static
Post by: xandaz on February 19, 2013, 10:30:26 AM
   well , my brothers and sisters. After having made that counter i tried to make the as if it could be reused several times in different controls but it doesn't seem to work. only the first two are visible and the second misses the titlles and the other two, well.... the windows were created but i can't see them.
Title: Re: Graphic Static
Post by: dedndave on February 19, 2013, 11:14:19 AM
            invoke  CreateWindowEx,WS_EX_STATICEDGE,addr CounterClass,addr ci,WS_VISIBLE+WS_CHILD+WS_CLIPSIBLINGS,\
                        0,0,rect.right,rect.bottom,hWnd,0,hInstance,0
            mov     hCounter1,eax
            invoke  CreateWindowEx,WS_EX_STATICEDGE,addr CounterClass,addr ci2,WS_VISIBLE+WS_CHILD+WS_CLIPSIBLINGS,\
                        rect.right,0,rect.right,rect.bottom,hWnd,0,hInstance,0
            mov     hCounter2,eax
            invoke  CreateWindowEx,WS_EX_CLIENTEDGE,addr CounterClass,addr ci3,WS_VISIBLE+WS_CHILD+WS_CLIPSIBLINGS,\
                         rect.right,rect.bottom,rect.right,rect.bottom,hWnd,0,hInstance,0
            mov     hCounter3,eax
            invoke  CreateWindowEx,WS_EX_CLIENTEDGE,addr CounterClass,addr ci4,WS_VISIBLE+WS_CHILD+WS_CLIPSIBLINGS,\
                       0,rect.bottom,rect.right,rect.bottom,hWnd,0,hInstance,0
            mov     hCounter4,eax


1) i think you intend the first 2 to use StaticClass
2) notice the positions x,y,width,height - some of them are outside the main client
the first one fills the client area   :P
3) i think it's a good idea to assign unique control identifiers for child windows (hMenu parm)

for testing, just put constants in there for position and size - then put some vars when you have it working
Title: Re: Graphic Static
Post by: xandaz on July 01, 2013, 09:33:20 PM
    sure thing dave. it was just a rough example...