Click here to Skip to main content
15,609,135 members
Articles / Desktop Programming / MFC
Posted 21 Jan 2000


89 bookmarked

The RGN Generator

Rate me:
Please Sign up or sign in to vote.
4.85/5 (15 votes)
21 Jan 2000
Creating non-rectangular dialog boxes

Sample Image - RGNCreator.gif

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")


  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 determining the font mode is: if (dc.GetDeviceCaps(LOGPIXELSX) == 120) then it's large, else it's small (dc.GetDeviceCaps(LOGPIXELSX)==96).


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


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.

Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralMy vote of 5 Pin
yiruirui4-Sep-11 20:18
yiruirui4-Sep-11 20:18 
QuestionWhat should be the transparent color if the bitmap is with a transparent background? Pin
n0nsenser11-May-08 23:17
n0nsenser11-May-08 23:17 
GeneralI do not clearly understand how to use it. Pin
beyondfun29-Dec-03 23:17
beyondfun29-Dec-03 23:17 
GeneralRe: I do not clearly understand how to use it. Pin
Tom Archer20-Jan-05 17:46
Tom Archer20-Jan-05 17:46 
GeneralBUG! BUG! BUG! Pin
Chessicus900015-Dec-03 23:41
Chessicus900015-Dec-03 23:41 
Question'RGN Generator ??????where?? Pin
starw20037-Nov-03 2:03
starw20037-Nov-03 2:03 
AnswerRe: 'RGN Generator where?? Pin
GAG [Jaguar]26-Nov-05 13:21
GAG [Jaguar]26-Nov-05 13:21 
GeneralTransform RGN into JPEG Pin
zarkov9-Feb-03 10:24
zarkov9-Feb-03 10:24 
Questionhow to generate a RGN out of a bitmap. Pin
GQ25-Nov-02 20:40
GQ25-Nov-02 20:40 
QuestionHow to change RGN after a timer, when my .exe is running ? Pin
candon17-Jun-02 8:17
candon17-Jun-02 8:17 
Questionhow to accumulate screen update rectangles? Pin
6-Jun-02 11:13
suss6-Jun-02 11:13 
GeneralHelp me please: AlwaysOnTop Pin
candon31-May-02 5:53
candon31-May-02 5:53 
GeneralFix: Icon and App name are not displayed in taskbar entry Pin
22-Mar-02 3:49
suss22-Mar-02 3:49 
GeneralHELP!!!!!!!!! Pin
Alberto Gattegno13-Jun-00 23:15
Alberto Gattegno13-Jun-00 23:15 
Generalwhat's the meaning of DESIGNX and DESIGNY Pin
Jae Hyeon Bae21-May-00 17:23
sussJae Hyeon Bae21-May-00 17:23 
GeneralButtons in RGN generator Pin
bogdan16-May-00 7:39
bogdan16-May-00 7:39 
GeneralRe: Buttons in RGN generator Pin
Mr.Schmendrik30-May-00 8:19
Mr.Schmendrik30-May-00 8:19 
GeneralRe: Buttons in RGN generator Pin
Peter26-Jun-00 18:23
Peter26-Jun-00 18:23 
GeneralNew Small/Large Font Scaling Solution Pin
Mark Swann12-May-00 7:52
Mark Swann12-May-00 7:52 
GeneralRe: New Small/Large Font Scaling Solution Pin
Vikash Dubey10-Jan-04 0:34
Vikash Dubey10-Jan-04 0:34 
GeneralSource code Pin
Philippe Lhoste26-Apr-00 5:13
Philippe Lhoste26-Apr-00 5:13 
GeneralWyh is it different. Pin
wind.wang29-Mar-00 16:33
susswind.wang29-Mar-00 16:33 
GeneralRGNDlg class in windows 95. Pin
Seokil, Park25-Feb-00 21:22
sussSeokil, Park25-Feb-00 21:22 
GeneralRegion Image Buttons Pin
Member 12246048-Feb-00 6:59
Member 12246048-Feb-00 6:59 
GeneralThe RGN resource Pin
Member 76531-Jan-00 4:15
Member 76531-Jan-00 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.