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]
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]
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.
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
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.
Yeah Bieb,
In my case, commenting is my weakest point. It's terrible!
Ramon
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
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]
Good work Bieb, very good work!
Ramon
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]
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
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.
Please send it to me, too. It should definately help.
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]
Thank you Paul.
Very nice work. :U
Manos.
Excellent Gene! Your screen capture program is really good. Thank you.
Ramon
That's going to help a lot. Thanks!
Bieb,
No problem, this, and any other code I make, can be preely used and/or modified any way you see fit. I don't require a mention or any other restrictions; but a mention is sometimes nice.
Paul
I'll be sure to put you in the credits.
Great. I like it. But I cannot run it. Where is the exe file? And how to rotate arround X Y and Z axis?
Okay, now I'm at that really annoying stage where the program is so close to completion that you can almost smell it, but there are just a few annoying bugs in your way. The code I've uploaded has rudimentary bitmap saving capabilities, but with two problems. I decided that I didn't have time to thoroughly learn how to deal with bitmap headers, so I ended up just making a 24 bit bitmap in paint with the same dimensions as mine and stealing it's headers. Then I just write the color data after them. Anyways, I end up with two big problems. The first is that the process of creating the bitmap takes a few seconds, and if another window comes in front of the edit control during that time, it's contents will end up in the bitmap file. The second is that the bitmap files it generates don't seem quite right. They look just fine if you open them up in paint, but if you open it in Windows Picture and Fax Viewer, or if Windows tries to make a preview of it, it just comes up with a little text string that says "drawing failed".
This is the bitmap saving loop itself
.data
JackedHeader DB 42H, 4DH, 0F6H, 76H, 8H, 0, 0, 0, 0, 0, 36H, 0, 0, 0, 28H, 0, 0, 0, 0ACH, 01H, 0, 0 , 0B0H, 01H, 0, 0, 01H, 0, \
18H, 0, 0, 0, 0, 0, 76H, 08H
DB 17 Dup(0)
FilePath DB "C:\RGG.bmp", 0
...
SaveBitmap Proc Private
Local StaticFileHDC:DWord
Local GarbageDW:DWord
Local FileHandle:DWord
Local LoopTemp1:DWord
Local LoopTemp2:DWord
Local RGBholder:DWord
Local AdressHolder:DWord
Invoke GetDC, StaticHandle
Mov StaticFileHDC, Eax
Invoke CreateFile, Addr FilePath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
Mov FileHandle, Eax
Invoke WriteFile, FileHandle, Addr JackedHeader, 35H, Addr GarbageDW, NULL
Mov LoopTemp1, 432
Loop1:
.If LoopTemp1 == 0
Jmp ExitLoop
.EndIf
Mov LoopTemp2, 0
Loop2:
Invoke GetPixel, StaticFileHDC, LoopTemp2, LoopTemp1
Mov RGBholder, Eax
Lea Eax, RGBholder
Add Eax, 0
Mov AdressHolder, Eax
Mov AdressHolder, Eax
Invoke WriteFile, FileHandle, AdressHolder, 1, Addr GarbageDW, NULL
Lea Eax, RGBholder
Add Eax, 2
Mov AdressHolder, Eax
Invoke WriteFile, FileHandle, AdressHolder, 1, Addr GarbageDW, NULL
Lea Eax, RGBholder
Add Eax, 1
Mov AdressHolder, Eax
Invoke WriteFile, FileHandle, AdressHolder, 1, Addr GarbageDW, NULL
Inc LoopTemp2
.If LoopTemp2 == 428
Dec LoopTemp1
Jmp Loop1
.Else
Jmp Loop2
.EndIf
ExitLoop:
Invoke ReleaseDC, StaticHandle, StaticFileHDC
Invoke CloseHandle, FileHandle
Ret
SaveBitmap EndP
[attachment deleted by admin]
Quote from: Farabi on March 12, 2005, 02:18:49 AM
Great. I like it. But I cannot run it. Where is the exe file? And how to rotate arround X Y and Z axis?
Paul's screen capture or the random graphics generator? The random graphics generator is supposed to be completely uncontrollable, so you can't rotate it. It doesn't even have a Z axis, since there isn't any 3D rendering going on. Everything you see is 2D vector graphics. If it's Paul's program you're talking about, the EXE is right in the ZIP file. In mine, I've only included source code, since it isn't a general release yet.
Scratch the second problem. Problem is that I was making the headers one byte too short. Now that I've got that taken care of, how shall I deal with the problem of interference? Here's a revised SaveBitmap proc.
SaveBitmap Proc Private
Local StaticFileHDC:DWord
Local GarbageDW:DWord
Local FileHandle:DWord
Local LoopTemp1:DWord
Local LoopTemp2:DWord
Local RGBholder:DWord
Local AdressHolder:DWord
Invoke GetDC, StaticHandle
Mov StaticFileHDC, Eax
Invoke CreateFile, Addr FilePath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
Mov FileHandle, Eax
Invoke WriteFile, FileHandle, Addr JackedHeader, 36H, Addr GarbageDW, NULL
Mov LoopTemp1, 432
Loop1:
.If LoopTemp1 == 0
Jmp ExitLoop
.EndIf
Mov LoopTemp2, 0
Loop2:
Invoke GetPixel, StaticFileHDC, LoopTemp2, LoopTemp1
Mov RGBholder, Eax
Lea Eax, RGBholder
Add Eax, 2
Mov AdressHolder, Eax
Mov AdressHolder, Eax
Invoke WriteFile, FileHandle, AdressHolder, 1, Addr GarbageDW, NULL
Lea Eax, RGBholder
Add Eax, 1
Mov AdressHolder, Eax
Invoke WriteFile, FileHandle, AdressHolder, 1, Addr GarbageDW, NULL
Lea Eax, RGBholder
Add Eax, 0
Mov AdressHolder, Eax
Invoke WriteFile, FileHandle, AdressHolder, 1, Addr GarbageDW, NULL
Inc LoopTemp2
.If LoopTemp2 == 428
Dec LoopTemp1
Jmp Loop1
.Else
Jmp Loop2
.EndIf
ExitLoop:
Invoke ReleaseDC, StaticHandle, StaticFileHDC
Invoke CloseHandle, FileHandle
Ret
SaveBitmap EndP
All the problems are solved, and I've finally finished version 1.0 (http://filehost.bieberworks.net/RGG.zip). Now I'm working on an animated version, for a school technology fair.
I might have downloaded the wrong thing, but I didn't get an executable or any .asm code...
I got a c/c++ header file, something called window1.ecw, and two icons in other directories.
How should I start in making your random graphics generator...
??
later,
jeff c
:dazzled:
Hi OceanJeff32,
The RGG.zip file contains an Easy Code project. The .ecw file is a window file which contains the window properties and the assembly code. To load and build the project, you need the Easy Code IDE which is available for free at this forum. See the Get the last version of Easy Code here topic.
Regards,
Ramon
Here's a link to the executable, if you want it:
http://filehost.bieberworks.net/RGG.exe
And here's the animated version (warning, it's a major CPU hog):
http://filehost.bieberworks.net/RGGa.exe
I never did release the source code for the animated version. Does anyone want it?
:U I like that RGGa.