News:

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

Random Graphics Generator

Started by Bieb, February 27, 2005, 01:40:27 AM

Previous topic - Next topic

Bieb

Okay, I've been working on my random graphics generator, and I've mostly got the UI code finished.  It creates a static control from code, because I couldn't seem to make one I could draw on with the visual project editor.  So, now I have two problems with it.  The first is that upon starting, the static control shows whatever is behind the window.  The second is that when I draw on the static control, if the coordinates of anything being drawn exceed the bounds of the control, then it draws on the window itself.  When testing, please note that the bottom sliderbar must be moved past 0 in order for anything to be drawn.  And before anyone says it, I know the drawing algorithm is crap.  I'll be playing with that a lot once I've got these other bugs worked out.

[attachment deleted by admin]

Ramon Sala

Hi Bieb,

I have been looking at your interesting project and I think I have found the two problems you had. The first one (not drawing at startup) is due to BeginPaint function. Microsoft's documentation says the following about it:

An application should not call BeginPaint except in response to a WM_PAINT message. Each call to BeginPaint must have a corresponding call to the EndPaint function.


So, calling BeginPaint in the WM_PAINT message of the static control is okay, but you also call it for the static control in the WM_PAINT message of the main window (Window1) and that is the problem. Instead, use the GetDC and ReleaseDC functions there (lines 121 and 128), which solves the first problem.

The second problem (drawing beyond the bounds of the control) is solved by adding the WS_CLIPSIBLINGS style (line 48) to the static control created at run time.


Other considerations for visual projects are:

- You can always get the main window handle with the App object, through its member Main. So, you just write App.Main wherever you need the main window handle (in your project Window1).

- You can always get the instance handle with the App object, through its member Instance. So, you just write App.Instance wherever you need the instance handle.


Finally, I have modified the whole project in order to add a Static control in the visual editor instead of creating it at run time (I think it is easier in that way). So, I attach two projects. The first one (RGG.zip) is your project with the modifications said above and the second one (RGG2.zip) is also your project but using a Static control added at design time instead of creating it at run time.

Regards,

Ramon


[attachment deleted by admin]
Greetings from Catalonia

petezl

Further to Ramon's comments, I had a look at your code and in QE is difficult to read properly but a couple of things.
The WM_PAINT process for the static needs to be in the Static sub proc and use hWnd instead of hStatic in the BeginPaint and EndPaint (see a previous posted example "corrected.zip") This will avoid problems and keep the drawing to the static limits.
If I may offer a suggestion although it doesn't effect the code, If you identify your ID's and handles destinctively, Ie. RedBrushID / hRedBrush it will make it easier to avoid mistakes later on.
Peter.
Cats and women do as they please
Dogs and men should realise it.

Ramon Sala

I think Peter is right. Identifying variables, handles, ID's, etc., is really important in any programming language. I always try to use the Hungarian notation. Here are some examples:


byTemp        ;Byte variable
wTemp         ;Word variable
bTemp         ;BOOL variable
lTemp         ;LONG variable
dwTemp        ;DWord variable
hBrush        ;Handle to a Brush
hwndStatic    ;Handle to a Static control
lpszBuffer    ;LPSTR pointer to an effective address



Just a suggestion,

Ramon
Greetings from Catalonia

Bieb

Yeah, commenting and hungarian notation have always been two of my weaker points.  I'm planning on going to only two pens now.  A black one to draw the background, and one that will just be deleted and recreated over and over again with random colors.  Thanks for the help, everyone.

Ramon Sala

Yeah Bieb,

In my case, commenting is my weakest point. It's terrible!

Ramon
Greetings from Catalonia

pbrennick

Commenting is a hard habit to get into because mostof the time it interferes with the coding.  As time goes by you will realize the benefits of this discipline.

Paul

Bieb

It's coming along nicely now.  The biggest problem I have is overcoming the urge to play around with it for extended periods of time after any change.  Here are some screenshots of what I've done so far.

[attachment deleted by admin]

Ramon Sala

Good work Bieb, very good work!

Ramon
Greetings from Catalonia

Bieb

Here's the source for what could be called a beta version.  Does anyone know how I could save the contents of the static control to a bitmap?

[attachment deleted by admin]

pbrennick

Bieb,
I have a program I wrote a long time ago that captures the screen to a bitmap.  You could modify that to capture a region.  Do you want it?  It is prettycool in that it creates a small dialog box with a capture button.  When you click the button, the capture does not occur until the dialog is removed so it does not contaminate the process.

Paul

Manos

Quote from: pbrennick on March 05, 2005, 03:44:44 PM
Bieb,
I have a program I wrote a long time ago that captures the screen to a bitmap.  You could modify that to capture a region.  Do you want it?  It is prettycool in that it creates a small dialog box with a capture button.  When you click the button, the capture does not occur until the dialog is removed so it does not contaminate the process.

Paul


Paul,

Send me this program.

Regards,
Manos.

Bieb

Please send it to me, too.  It should definately help.

pbrennick

Manos and Bieb,
I am sorry for the delay, sometimes it is not easy...

Anyway, here is the program as an attachment, enjoy.

Paul


[attachment deleted by admin]

Manos

Thank you Paul.

Very nice work. :U

Manos.