Important alert: (current site time 7/16/2013 2:40:48 AM EDT)
 

winzip icon

LaVolpe Window Shaper 3 w/Full Region Class

Email
Submitted on: 2/3/2006 8:08:21 AM
By: LaVolpe 
Level: Intermediate
User Rating: By 29 Users
Compatibility: VB 5.0, VB 6.0
Views: 21297
author picture
(About the author)
 
     (Updated w/more Functions) The attached code will shape a window around a bitmap faster than anything else I've seen on any other site. A simple modification to the code (really optional parameters), can produce the desired results up to 4x faster! Surprised I haven't considered it before. This time the code is moved into a class that has many region-related functions. If the only reason you download is to strip out the RegionFromBitmap function, I think you will also appreciate learning about those other functions. Oh, why is this one faster; cause it uses a method none of the others do -- documented in the code. Patched: 18Nov/1430. SaveRegionToFile fixed, added 1 more ImportRegion option, cleaned-up code, made IsRegion public, & minor touch ups, more comments. 31Jan06/1800z: correct calc errors for rare cases in RegionFromBitmap() & minor tweaks throughout. 1Feb/0200z. Added many more region functions, added more examples in sample project, commented the code to death. History of changes at top of the class module. 2Feb/2130z: Added all remaining functions I can think of and even threw in a Region Collision routine. Short of bugs or bone-head errors, this class is done and now contains 99% of all known functions that actually create, destroy or modify regions.

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 72 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
11/18/2005 3:51:11 AMLight Templer

Hi Keith, great class, a lot to learn from! That kind of stuff pushes VB's limits more and more. Thx and my ***** for. LiTe
(If this comment was disrespectful, please report it.)

 
11/18/2005 10:07:12 AMKenneth Foster

LaVolpe, I must be missing something.I've been trying to save the region created in your demo but its not saving anything.Can you give an example.The syntex I used is
SaveRegionToFile 0,"D:\Temp\ST1.bmp",,True
Thanks Ken
(If this comment was disrespectful, please report it.)

 
11/18/2005 10:27:16 AMLaVolpe

Minor bug in the SaveRegionToFile routine: if trying to overwrite a hidden or read-only file, it won't. Will upload simple patch later tonight.
(If this comment was disrespectful, please report it.)

 
11/18/2005 10:38:19 AMLaVolpe

Ken, the bug I just reported hasn't anything to do with your issue. You are passing a region handle (1st param) of zero; pass the region you created, or create a new one if needed.
(If this comment was disrespectful, please report it.)

 
11/18/2005 12:07:06 PMHeriberto Mantilla Santamaria

wow, you always surprise me with your codes, excellent work.
(If this comment was disrespectful, please report it.)

 
11/18/2005 12:19:19 PMD. Rijmenants

Great stuff. Such code always reminds me that there's still much to learn. Thanks for sharing!
(If this comment was disrespectful, please report it.)

 
11/18/2005 12:50:23 PMTerriTop

This is awesome! I always learn a ton from your submissions... Thanks for sharing this gem! TerriTop
(If this comment was disrespectful, please report it.)

 
11/18/2005 4:48:52 PMLaVolpe

Glad you enjoy it. Kinda became an expert with regions awhile back when I was looking for faster alternatives to pathfinding... ended up learning more than I wanted to trying to achieve something I never really achieved :(
(If this comment was disrespectful, please report it.)

 
11/18/2005 5:47:05 PMJames Miller

Great job, Keith!!! I'm always humbled by your work. Thanks for the submission. ~James
(If this comment was disrespectful, please report it.)

 
11/18/2005 7:13:45 PMOption Explicit

As you know I'm just making my first forays into region code, so this is perfect for me to learn from. Thanks!
(If this comment was disrespectful, please report it.)

 
11/18/2005 7:48:26 PMDr. Intel

Hi Keith,

This is a cool application. Like Mama always said "Qualit is as Quality Does". Great job !!!!
(If this comment was disrespectful, please report it.)

 
11/18/2005 11:11:09 PMLaVolpe

Dr. Intel? Didn't recognize you until I saw your email address. A few new/revised handles out there this year.
(If this comment was disrespectful, please report it.)

 
11/19/2005 12:23:27 AMRobert Rayment

Interesting. I put a label on to show result for EXE. Strange thing is 'with and w/o' exclusion rectangle times are sometimes the same and sometimes swap around. Maybe needs QueryPerformance,, timing for EXE.
(If this comment was disrespectful, please report it.)

 
11/19/2005 1:25:29 AMLaVolpe

Robert the routines are processing that image at about 1/20th of a second. Pretty fast & maybe too fast for poor GetTickCount. I'm not going to gripe; the routines are fast & if an incorrect timing occurs because of that? Oh well. Now if the timings were > 200ms, I'd be concerned. :)
(If this comment was disrespectful, please report it.)

 
11/19/2005 3:06:17 AMRobert Rayment

Keith: It's just that timing ratios in the IDE, I've found, are not necessarily a good guide to timings in an EXE.
(If this comment was disrespectful, please report it.)

 
11/19/2005 3:20:34 AMRichard Mewett

Superb submission as always! Lots to learn from :) 5 regions...
(If this comment was disrespectful, please report it.)

 
11/19/2005 11:53:28 AMLaVolpe

To all. Not clearly explained in the RegionFromBitmap function & will add more info next time updated. When you send a bitmap to create a rgn & apply it to a window, the function does not return the rgn handle. This is by design. Per MSDN, when a rgn is applied to a window, you are not to ref that rgn & are not to destroy it. So, how do you save a rgn you applied to a window, 2 ways: 1) return the rgn w/o applying it to the window, save it & then apply it or 2) save rgn after being applied by returning the rgn via ImportRegion function (rgn_FromWindow) and supplying the window hWnd for the 2nd parameter. Hope this helps.
(If this comment was disrespectful, please report it.)

 
11/19/2005 7:58:18 PMsilver_fox_vb

k its fast ( faster than the usual ) but its not very accurate it doesn't get the whole region i made a pic on PS made the bg color the same as the color u did loaded it it removed most of the color but it left some on the corners i donno if its cuz the color on the corners were a little diffrent ( cuz of the effects i applied ) so if u can thnk of something else that might have caused that tell me
(If this comment was disrespectful, please report it.)

 
11/19/2005 11:10:59 PMLaVolpe

^^ Replied off line -- want to see the picture. My guess is the color is not what is expected; rather "blended".
(If this comment was disrespectful, please report it.)

 
11/19/2005 11:16:13 PMLaVolpe

Silver Fox: as far as accuracy goes. I've tested this with single pixel lines to ensure it was accurate down to the pixel. But willing to entertain the idea that my logic could be off. We'll see after testing your sample image.
(If this comment was disrespectful, please report it.)

 
11/20/2005 3:49:40 AMsilver_fox_vb

k here is a link to the image http://www.almarwa.org/form.bmp nothing fancy just a RRectangle with bevel and a gradient overlay ( it was just to try cuz i was working with regions before and had the same problem ) so tell me wat the prob is

(If this comment was disrespectful, please report it.)

 
11/20/2005 9:10:44 AMLaVolpe

^^A blended bitmap. The routines are 100% ACCURATE. Blended bitmaps have blended pixels around the edges that are no longer the "transparent" color; therefore those pixels are not excluded from the region. This is same reason why GIFs are not ideal for shaping a window around.
(If this comment was disrespectful, please report it.)

 
11/21/2005 4:04:52 AMAvi

LaVolpe is right of course, I had my share of wasted time on those blended pixels that PS creates (rightfully and beautify for most purposes).

Anyway… SUPERB submission! Thanks for sharing.

(If this comment was disrespectful, please report it.)

 
11/21/2005 5:35:18 PMsilver_fox_vb

yeh i thought so even when i tried to get it in mspaint and filling the bg color it left the colors on the corners and i kinda found a sol for makin this stuff on ps just make an outline it would be 1px wide but it would do the job exactly thnx lavolpe for tryin it out and good submesion :D
(If this comment was disrespectful, please report it.)

 
12/10/2005 9:49:04 AMNathan A. Huebner

I wish I would have had this when I was doing web design two years ago. I had to shape 1700 furniture images for a web site just like you did, by hand. It took me around 3 days. This code is amazing, I gave it 5 globes.
(If this comment was disrespectful, please report it.)

 
2/1/2006 8:12:34 AMMatt DeKok

I don't get it. All this does is give the image a blue background.
(If this comment was disrespectful, please report it.)

 
2/1/2006 11:14:36 AMLaVolpe

^^ Replied off line. We may have a previoulsy undetected bug. Waiting.
(If this comment was disrespectful, please report it.)

 
2/1/2006 4:24:17 PMKenneth Foster

LaVolpe, Could you include a save region button. I'm not having any luck saving it on my end. Thanks.Yes I've read the above comments.
(If this comment was disrespectful, please report it.)

 
2/1/2006 8:40:07 PMLaVolpe

^^ Replied off line & will add an example when I re-upload this. Have added about every conceivable region function to the class now. Changes coming later tonight; early AM at the latest.
(If this comment was disrespectful, please report it.)

 
2/3/2006 12:10:32 PM_Merlin_

Nice going Keith! It sure took you a lot of work seeing you started the project on: 11/17/2005 and the last update was on: 2Feb/2130

But still I think it is worth the fivers you are getting ;)

Merlin is the name, and logic is my game...
(If this comment was disrespectful, please report it.)

 
2/3/2006 12:16:41 PMLaVolpe

Some old habits die hard. 2130 is military/European time :) BTW project actually started in 03 when I first began playing with regions.
(If this comment was disrespectful, please report it.)

 
2/3/2006 1:31:35 PMLaVolpe

Side note for gamers. If you try to use the region collision routine, keep in mind that it is pixel collision. So, let's say a ball is centered in a large star. No collision 'cause no pixel intersection. However, moving that ball through the star on a 2D plane will cause a collision as the 2 shapes meet.
(If this comment was disrespectful, please report it.)

 
2/4/2006 9:44:10 AMLaVolpe

^^ Should have explained it better. The above statement applies when the star is an outlined shape, but if the star was a solid shape, obviously you would have a collision.
(If this comment was disrespectful, please report it.)

 
3/17/2006 9:11:41 PMOption Explicit

Finally had a chance to spend a few hours looking at the latest version of this post. This should be recognized as one of the all time great contributions to PSC. What an incredible, exhaustive resource on a very important subject for a graphically-oriented programming language. The quality of this submission is something that brain-dead little imbeciles like NHGames, who voted one globe, will never be able to appreciate because they lack the mental capacity to comprehend its value. Thanks for this classic.

P.S. It would be interesting to write a routine to automatically calculate the exclusion rectangle for the RegionFromBitmap routine. Maybe I'll try my hand at it sometime :)
(If this comment was disrespectful, please report it.)

 
12/6/2006 9:16:50 PMbluewaterit

I keep getting 'No public user control detected' when I try and compile the OCX. What am I missing?
Thanks for an excellent piece of butonship. :-)
(If this comment was disrespectful, please report it.)

 
12/8/2006 11:38:01 AMLaVolpe

^^ Discussed off-line. Resolved.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.