Click here to Skip to main content
6,822,123 members and growing! (17,141 online)
Email Password   helpLost your password?
Multimedia » GDI » Regions     Intermediate

The RGN Generator

By Richard de Oude

Creating non-rectangular dialog boxes
VC6, MFC, GDI, Dev
Posted:21 Jan 2000
Views:115,080
Bookmarked:65 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
55 votes for this article.
Popularity: 7.94 Rating: 4.56 out of 5
1 vote, 7.7%
1

2

3
1 vote, 7.7%
4
11 votes, 84.6%
5
  • Download demo project - 320 Kb
  • Download source files - 18 Kb
  • 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")

    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


    Member

    Location: United States United States

    Other popular GDI articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 25 of 30 (Total in Forum: 30) (Refresh)FirstPrevNext
    QuestionWhat should be the transparent color if the bitmap is with a transparent background? Pinmembern0nsenser0:17 12 May '08  
    GeneralI do not clearly understand how to use it. Pinmemberbeyondfun0:17 30 Dec '03  
    GeneralRe: I do not clearly understand how to use it. PinmemberTom Archer18:46 20 Jan '05  
    GeneralBUG! BUG! BUG! PinmemberChessicus90000:41 16 Dec '03  
    General'RGN Generator ??????where?? Pinmemberstarw20033:03 7 Nov '03  
    GeneralRe: 'RGN Generator where?? PinmemberGAG [Jaguar]14:21 26 Nov '05  
    GeneralTransform RGN into JPEG Pinmemberzarkov11:24 9 Feb '03  
    Generalhow to generate a RGN out of a bitmap. PinmemberGQ21:40 25 Nov '02  
    GeneralHow to change RGN after a timer, when my .exe is running ? Pinmembercandon9:17 17 Jun '02  
    Generalhow to accumulate screen update rectangles? PinmemberAnonymous12:13 6 Jun '02  
    GeneralHelp me please: AlwaysOnTop Pinmembercandon6:53 31 May '02  
    GeneralFix: Icon and App name are not displayed in taskbar entry PinmemberAnonymous4:49 22 Mar '02  
    GeneralHELP!!!!!!!!! PinsussAlberto Gattegno0:15 14 Jun '00  
    Generalwhat's the meaning of DESIGNX and DESIGNY PinsussJae Hyeon Bae18:23 21 May '00  
    I have a big bitmap file. I've created RGN file using your region creator. And I've trace the step you suggested to create nonrectangular dialog. But region and bitmap doesn't match exactly. How can I do that?

    I am guessing that I should control DESIGNX and DESIGNY. What's the meaning of DESIGNX and DESIGNY?

    Thank you in advance.
    GeneralButtons in RGN generator PinsussBogdan8:39 16 May '00  
    GeneralRe: Buttons in RGN generator PinsussRonen Magid9:19 30 May '00  
    GeneralRe: Buttons in RGN generator PinsussPeter19:23 26 Jun '00  
    GeneralNew Small/Large Font Scaling Solution PinsussMark Swann8:52 12 May '00  
    GeneralRe: New Small/Large Font Scaling Solution PinsussVikash Dubey1:34 10 Jan '04  
    GeneralSource code PinsussPhilippe Lhoste6:13 26 Apr '00  
    GeneralWyh is it different. Pinsusswind.wang17:33 29 Mar '00  
    GeneralRGNDlg class in windows 95. PinsussSeokil, Park22:22 25 Feb '00  
    GeneralRegion Image Buttons PinsussAndrew Bos7:59 8 Feb '00  
    GeneralThe RGN resource PinsussBruno Vais5:15 31 Jan '00  
    GeneralRe: The RGN resource PinsussRichard7:15 8 Feb '00  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

    PermaLink | Privacy | Terms of Use
    Last Updated: 21 Jan 2000
    Editor: Chris Maunder
    Copyright 2000 by Richard de Oude
    Everything else Copyright © CodeProject, 1999-2010
    Web11 | Advertise on the Code Project