Click here to Skip to main content
Click here to Skip to main content

The RGN Generator

, 21 Jan 2000
Rate this:
Please Sign up or sign in to vote.
Creating non-rectangular dialog boxes
  • Download demo project - 320 Kb
  • Download source files - 18 Kb
  • Sample Image - RGNCreator.gif

    <!-- Article Starts -->

    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.

    License

    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

    About the Author

    Richard de Oude

    United States United States
    No Biography provided

    Comments and Discussions

     
    GeneralMy vote of 5 Pinmemberyiruirui4-Sep-11 20:18 
    QuestionWhat should be the transparent color if the bitmap is with a transparent background? Pinmembern0nsenser11-May-08 23:17 
    GeneralI do not clearly understand how to use it. Pinmemberbeyondfun29-Dec-03 23:17 
    Would someone please to give me a real example?thanks ahead
     
    Beyond Forever!
    GeneralRe: I do not clearly understand how to use it. PinmemberTom Archer20-Jan-05 17:46 
    GeneralBUG! BUG! BUG! PinmemberChessicus900015-Dec-03 23:41 
    Question'RGN Generator ??????where?? Pinmemberstarw20037-Nov-03 2:03 
    AnswerRe: 'RGN Generator where?? PinmemberGAG [Jaguar]26-Nov-05 13:21 
    GeneralTransform RGN into JPEG Pinmemberzarkov9-Feb-03 10:24 
    Questionhow to generate a RGN out of a bitmap. PinmemberGQ25-Nov-02 20:40 
    QuestionHow to change RGN after a timer, when my .exe is running ? Pinmembercandon17-Jun-02 8:17 
    Questionhow to accumulate screen update rectangles? PinmemberAnonymous6-Jun-02 11:13 
    GeneralHelp me please: AlwaysOnTop Pinmembercandon31-May-02 5:53 
    GeneralFix: Icon and App name are not displayed in taskbar entry PinmemberAnonymous22-Mar-02 3:49 
    GeneralHELP!!!!!!!!! PinsussAlberto Gattegno13-Jun-00 23:15 
    Generalwhat's the meaning of DESIGNX and DESIGNY PinsussJae Hyeon Bae21-May-00 17:23 
    GeneralButtons in RGN generator PinsussBogdan16-May-00 7:39 
    GeneralRe: Buttons in RGN generator PinsussRonen Magid30-May-00 8:19 
    GeneralRe: Buttons in RGN generator PinsussPeter26-Jun-00 18:23 
    GeneralNew Small/Large Font Scaling Solution PinsussMark Swann12-May-00 7:52 
    GeneralRe: New Small/Large Font Scaling Solution PinsussVikash Dubey10-Jan-04 0:34 
    GeneralSource code PinsussPhilippe Lhoste26-Apr-00 5:13 
    GeneralWyh is it different. Pinsusswind.wang29-Mar-00 16:33 
    GeneralRGNDlg class in windows 95. PinsussSeokil, Park25-Feb-00 21:22 
    GeneralRegion Image Buttons PinsussAndrew Bos8-Feb-00 6:59 
    GeneralThe RGN resource PinsussBruno Vais31-Jan-00 4:15 

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

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

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140709.1 | Last Updated 22 Jan 2000
    Article Copyright 2000 by Richard de Oude
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid