pda-ppc.com
 
MENU
Search
 Astronomy
 Business
 Calculator
 Clock/calendar
 Communication
 Database
 Docs
 Educational
 Financial
 Games
 Graphics
 Hobbies
 Medical
 Misc/fun
 Multimedia
 Quiz
 Religion
 Travel
 Utilities



AceShowbiz
Celebrity Mania
Wow Keren


Digg this - Post page to del.icio.us - Post page to Furl



FreeFormPPC
Freeware 
Latest update : Apr 04, 2009
File Size: 64.5 KB
Download: available


Author: dzolee
Info/description:

Modern applications often have a customized, "skinned" look. There are a lot of tools, libraries and tutorials on creating skinned apps for desktop Windows systems. Unfortunately this is not the case with WinCE or PocketPC. If you try to adapt ideas or code from Win32 programs, you will experience a lot of challenges, just as I had while creating the Skinnable Dialogs Framework. A very basic feature of a skinnable application is to have custom-shaped controls or main windows. Creating non-rectangular windows is a relatively easy task in the Win32 world. All you have to do is, create a region based on a bitmap mask and set it for your window with the SetWindowRgn API.

Creating a region is the first step towards a custom-shaped window.

Every region creator that I've seen so far uses the same idea:

* uses a bitmap mask to define the visible and transparent regions of a window
* calls the GetPixel funcion on the bitmap mask to see which areas of the window should be transparent
* then calls CreateRectRgn to create new rectangular regions based on pixels or pixel blocks
* and finally combines these smaller regions into the final, custom-shaped region with the CombineRgn function.

But have you tried this approach on PocketPC or WinCE? Well I have, and the results were very disappointing. The smiley bitmap above was parsed for several minutes!I found that region functions work well on WinCE only if you want to combine a couple of rectangular regions. But when it comes to hundreds of small regions (just as with a bitmap mask), CombineRgn becomes unacceptably slow.

In this article I'd like to present a much faster solution for custom region creation using the ExtCreateRegion API. The code works fine on WinCE/PocketPC and also on Win32. I've tested it with Embedded Visual C++ 4 and Visual Studio 2005, too.

The solution

The CRegionBuilder class (see files RegionBuilder.h and RegionBuilder.cpp) has only one public function, BuildRegion. It uses the ExtCreateRegion API to create a region from manually built region data. The region data consists of a header (a RGNDATAHEADER structure) and an array of RECT structures that make up the region.The BuildRegion function takes two parameters, a bitmap handle of a loaded bitmap and a pointer to store the resulting region handle:Collapse

RegionBuilderError BuildRegion(HBITMAP hBmp, HRGN *pDest);

The function includes every non-black pixel in the resulting region.Possible return values are: rbeOK, rbeNoMem and rbeGDIError as defined in RegionBuilder.h. If memory allocation fails, it returns rbeNoMem. If any of the used GDI functions return an error, it returns rbeGDIError. If all goes fine, the function return rbeOK and the resulting region handle will be copied to the destination.

Some tips:

* Do not call DeleteObject on the region handle until your window is visible, instead, free it in OnDestroy.
* Drawing custom-shaped windows on CE devices is considerably slower than drawing regular windows, so don't expect hyper-performance.
* If you use a very complicated bitmap mask that would result in a thousands of region RECTs (eg. 640x480 "random noise"), you might experience sudden device crashes or other drawing problems.

How it works

The BuildRegion function first gets bitmap dimensions with the GDI GetObject function. To avoid the slow GetPixel function, it reads bitmap bits directly. But the GetObject function does not return a pointer to the bitmap bits unless the bitmap was created with CreateDIBSection. So, BuildRegion creates a new, monochrome bitmap using this function and then copies the source bitmap to it with BitBlt. Using a monochrome version of the bitmap saves a lot of precious memory.

After the monochrome copy has been created, the function loops through the bitmap bits to see how much memory will be required for the RECT array. If there are horizontal lines in the bitmap, they will be packed into one RECT.

Then the function allocates a proper memory block for the rectangles and loops through the bits again to build the RECT array.

It loops twice through the bitmap, so it allocates only the required amount of memory. Despite this it's still pretty fast I think. A lot faster than the ordinary GetPixel + CombineRgn method.

Have fun!


Dead or Changed Link? Report This Listing


  News, Articles and Press Releases
 •  iambic Unveils First iPhone App, SnappySeeker (Dec 19, 2008)
 •  iSkysoft announces iMedia Converter 1.0.0.8 for Mac OS X (Dec 17, 2008)
 •  iDTRONIC will present at RFID Show 2008 in Paris its updated and expanded UHF Range of Products (Dec 17, 2008)
 •  With Mobile Learning technology a simple PDA or SmartPhone can take you away to another place and time. (Dec 16, 2008)
 •  Smartphones Don’t Care Much For Size (Dec 16, 2008)
 •  Sprint hopes to dominate with its Mogul device (Dec 16, 2008)
 •  Cooking in the Mobile Cloud (Dec 13, 2008)
 •  Happy 6th Birthday Mobilitysite/Aximsite (Dec 13, 2008)
 •  CompanionLink for Google Now Compatible with Lotus Notes (Dec 12, 2008)
 •  PenReader Touch, latest invention by Paragon Software Group (Dec 12, 2008)
 •  More News ...
  Latest software update
 •  Timeo for Mobile 2.00 (Nov 24, 2011)
 •  inCall ProxDispOff 1.10 (Nov 24, 2011)
 •  busGuide2 1.2 (Jun 29, 2011)
 •  Trip Reports 1.0 beta (Jun 29, 2011)
 •  LeTour 2011 Mobile 1.0 (Jun 29, 2011)
 •  TrailCompanion 1.9.8.0 (Jun 29, 2011)
 •  PHM Task Manager 0.1 (Jun 27, 2011)
 •  FunnySnake EasyTweak 0.1.2 (Jun 27, 2011)
 •  TI59ce 1.0.342.1 (Jun 27, 2011)
 •  PHM Registry Editor 0.7.0 (Jun 27, 2011)
 •  PicoWebServer 1.0 beta (Jun 24, 2011)
 •  PocketFeed 0.6.0 (Jun 24, 2011)
 •  PocketBlinds 1.0 (Jun 24, 2011)
 •  FreeMine 1.0.1 (Jun 24, 2011)
 •  Pocket Translator 1.0 (Jun 23, 2011)
 •  Silke Four 1.0 (Jun 23, 2011)
 •  vxShortCut 0.9.3 (Jun 23, 2011)
 •  SIManager 1.1 (Jun 23, 2011)
 •  Isitar 1.0 (Jun 20, 2011)
 •  Where is my RAM? 1.2 (Jun 20, 2011)
Add to Favorite Home Submit Freeware Send Mail