The RGN Generator v1.00

The point of this program is to allow you to create non-rectangular dialog boxes. The program itself is an example of what can happen if this is taken a bit too far.

Creating your transparency region

  • 1. Create a mask image for the dialog box. One color will be the transparent part of the dialog. A transparent gif is a good method but many image formats are supported.
  • 2. Run the RGNerator
  • 3. Enter the filename of your mask. (as soon as a valid image file name is entered it will be automatically loaded) Browse for it if you cannot remember the name or where you put it.
  • 4. Enter the color that represents the transparent portion of the dialog. If you do not know the exact RGB color press the Pick button.

Picking Transparent Color

  • 1. Move the cursor over the transparent color. There are two color boxes on the right. The top one is the current transparent color and the bottom one is the color of the pixel the cursor is over. When the top color box contains the transparent color - right click the mouse.
  • 2. If it is difficult to select the pixel you can zoom the image.
  • 3. If the image is too large for the viewing area use the scroll bars - or simply hold the left mouse button and drag the image to the required position.
  • 4. When you have selected the color press OK.
  • 5. Press the create button. The time required to do this depends on the complexity of the transparent region.
  • 6. When it finishes you will be asked to enter the name of the file to store the rgn data in.

How to use your transparency region

I have included a demo project look at. Please look at this first as it will show you how simple this really is.

To use it in your own app -

  • 1. Insert the rgn file as a "RGN" resource.
  • 2. Insert the bitmap to be used as the background.
  • 3. Insert a dialog
  • 4. Set the dialog's border property to none.
  • 5. Insert a picture object into the dialog
  • 6. Set its type as a "Bitmap"
  • 7. Set the background bitmap as the image.
  • 8. (This is a bit annoying, as it must be the first in the tab order. Otherwise it will overwrite your other dialog controls when the dialog is displayed. Unfortunately it works the other way whilst editing the dialog! So just set it to first when you have finished the dialog box.)
  • 9. Create the dialog from the template.
  • 10. Base the dialog on the CRGNDlg class.
  • 11. Get the rgndlg.cpp and .h files from the demo project.
  • 12. In the dialog source code:
    In your constructor just add the RGN resource id.
    e.g. - CRGNDlg(CRgnDemoDlg::IDD, pParent,"BACKGROUND")

Notes

  • 1. The SetWindowRgn must be done before you call the base InitDialog function
  • 2. You cannot use the rgn used in the SetWindowRgn -it belongs to windows - don't even delete it.
  • 3. If the outline dragging is slow use the full invert. It isn't as nice but is faster for complex regions. It's in the Inverttracker function in rgndlg.cpp.
  • 4. The edges of your image should be a dark gray. Very black or very white edges show up if the background is the reverse color whereas gray edges look alright regardless of the background color.

 

"Small Fonts" and "Large Fonts"

The problem:

For example you have "small fonts" selected in your desktop display config. You happily create your dialog box , put in your bmp and insert all the required controls aligning them carefully to the background bmp. You then triumphantly send out your app and then get people complaining that things don't line up.

The cause:

These people have 'large fonts' selected. Windows scales the dialog box and its controls according to the font. The font in turn is dependent on the 'small/large' font setting - so Ms Sans Serif 8 is not the same 'size'. Since the image and the rgn are pixel based there is a problem.

The solution:

There are two possible solutions -

1. Scaling

This is what I have implemented in the demo app. The drawback of scaling is that it is not exact. E.g. Scaling from an app designed in "small fonts" is a bit blocky if scaled up for "large fonts".

(Look in the InitDialog function of rgndlg.cpp in the demo app).

2. Have two separate images and two RGN files.

Design your dialog and then base two dialogs on the original one and setup one to use large image and one to use the smaller image. A "reliable" way of determing the font mode is :

if (dc.GetDeviceCaps(LOGPIXELSX) == 120)

then its large, else its small (dc.GetDeviceCaps(LOGPIXELSX)==96)

Copyright

This program is provided courtesy of Data Dynamics. Feel free to copy it and distribute to anyone.

Download

Download source of demo app - 18 KB

Download RGN Creation exe - 320 KB

Changes since last update

  • Added demo project and new improved app. (25/04/1999)
  • Fixed RGN creation error and added scaling feature for the "Small Fonts"/"Large Fonts" problem.



Comments

  • So! Good But...

    Posted by Legacy on 09/16/2000 12:00am

    Originally posted by: Lim ji soon

    Nice Good!!

    This Program Shoots My Problem^^

    But It's so Slow , blink(When Dragging!)

    Reply
  • other solutions and examples

    Posted by Legacy on 09/01/2000 12:00am

    Originally posted by: Jerry Shaw

    Before I found this tool, I'd found another example of region generation/use, a solution to the "large font" problem, and a way to put regions into resources. All of these items are right here on code guru, and they have source code.
    For example, the large font problem (which resizes the dialog box so that it no longer fits the region) is solved very nicely here (it takes only a few lines of code):
    http://codeguru.earthweb.com/dialog/ChangeDefaultDialogFont.shtml
    To find the other example (with source) which generates and uses regions, go to:
    http://codeguru.earthweb.com/dialog/transparent_dialog.shtml
    And to use a region from resource, look at:
    http://codeguru.earthweb.com/bitmap/bmp2rgn_tool.shtml

    Reply
  • Help with implementing.

    Posted by Legacy on 05/26/2000 12:00am

    Originally posted by: Dan Dudley

    Hi, Great program! I've been looking for something like this for a while, but....
    I'm having problems trying to implement the code. I've read the readme.txt and studied the src but I can't get it.
    This is where I'm having my problems...

    5.Create the dialog from the template.
    Base the dialog on the CRGNDlg class.
    Get the rgndlg.cpp and .h files from the
    demo project.

    6.In the dialog source:
    In your constructor just add the RGN resource id.
    eg - CRGNDlg(CRgnDemoDlg::IDD, pParent,"BACKGROUND")

    I don't know how to get the class CRGNDlg in the wizard where I can base this on. CRGNDlg is not a choice. How do I get that in there? I copy the rgndlg.cpp and .h files to my dir, but just don't know how to chose CRGNDlg as the base clase.

    And where exactly do I put "CRGNDlg(CRgnDemoDlg::IDD, pParent,"BACKGROUND")"

    Thanks, for the great code. Looking forwared for a solution.
    Dan_Dudley@Hego.de

    Reply
  • If .... this work on ActiveX ?

    Posted by Legacy on 03/14/2000 12:00am

    Originally posted by: han

    Thankyou....

    but I have one question.....

    It work on ActiveX ?

    Reply
  • I think so!

    Posted by Legacy on 02/15/2000 12:00am

    Originally posted by: YoungTaek, An

    Very Cool & Very Useful!
    
    

    But,
    I have a question.

    Where is your source code(not demo)?

    Please, Let me know HOW TO GET IT....

    Very Thanks!!!

    Reply
  • very cool & useful program...

    Posted by Legacy on 01/12/2000 12:00am

    Originally posted by: Cho Ji hyun

    You're very good.

    In my program yours will work very useful

    thank you~

    then good bye~~^^

    Reply
  • You are great, Your program great.!!

    Posted by Legacy on 01/11/2000 12:00am

    Originally posted by: Kim Hyo Sub

    I'm korean. I'm afraid I can't write this letter very well.
    but I can say that your program is very very good.
    I'll study Visual C++ dillegently and I'll program good things like your program....

    Reply
  • You save me!!!Thank you very much

    Posted by Legacy on 01/05/2000 12:00am

    Originally posted by: jing

    I am from china.

    Reply
  • RGNCreator

    Posted by Legacy on 04/29/1999 12:00am

    Originally posted by: aashwina

    Great . It would have been nice to have the code of the creator itself.
    By the way how did you get the text to go around the button?

    Reply
  • Did you forget about Screen Resolution modes?

    Posted by Legacy on 04/28/1999 12:00am

    Originally posted by: Darryl Adams

    When I run RGNGen, the bitmaps stretch beyond the extent of the Region. That is, your application does not line things up well for my video resolution. (Look like you used Logical instead of Screen coordinates -- or is it the other way around? Hey, I frequently mess this up myself.) Anyhow, it means I cannot access most of the buttons.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds