Irregularly Shaped Forms & Forms With Holes

Forms that have shapes that do not resemble the standard rectangular shape are known as Irregular forms. Irregular forms may be round, elliptical, have holes in them or may be shaped like an n-sided polygon. Irregular forms can be used as attention grabbers or to create hot spots on forms.

This sample illustrates how to create several irregular forms and controls. As shown, you can make your form look like an ellipse with elliptical buttons and textboxes or you can round the corners of your form or even create holes in your forms.

Elliptical form with Elliptical controls

To create the elliptical form and controls the CreateEllipticRgn API function is used. Simply pass in the handle of the form or control and specify the top, left, right and bottom coordinates of the ellipse. Then call SetWindowRgn to set the window region. The window region is the area within the window (form or control) where the operating system permits drawing. The operating system does not display any portion of a window that lies outside of this region.

Form with rounded corners and a hole in the center.

To round the corners of the form the CreatePolygonRgn API is utilized. This function takes in an array of points (x and y coordinates) and plays connect the dots. The array of points can specify just about any shape - just let your imagination be your guide. Windows must be able to trace the points in a continuous fashion.

With a little trial and error you can even create holes in your forms. The above form was over an Explorer window. To create a hole begin on the outside of the form and then set a point inside the form. Now begin tracing the shape of the hole. When you are done with the hole make sure you return to the outside of the form along the exact same path you used to enter the hole. Once back on the outside of the form, continue specifying points around the form's perimeter. You should set the form's ScaleMode property to vbPixel. Remember, the top left corner of the form is at point (0,0).

Once you have your array of points, call the SetWindowRgn API to tell Windows how to draw the form.

For added flash, you can flash the title bar of your form. If you are running Windows 95 or NT 4 I use the FlashWindow API to toggle the title bar from activated to non-activated and vice versa. To continuously toggle the caption, a timer is used. If you are running Windows 98 or 2000 you will see a yellow circle between the form's two button. Clicking on the circle (really a round frame control) will display a popup menu. You will have choices to flash the title 5 times or continuously. To do this the FlashWindowEx funtion is used.

For the "mother of all attention grabbers," you can create forms that look like this. Here are nine forms in the shape of letters. To make them look a little fancier, I made their backgrounds a gradient color which changes every second or so. You can use this technique to make eye catching splash screens. I turned of the title bars on these forms to enhance their look. If you need to move a form with no title bar, see my Move a Form With No Title Bar example.

Irregular forms created with CreatePolygonRgn

DownLoad Source Code for Elliptical Forms/Forms with Holes
DownLoad Source Code for TheScarms

Applies To

The FlashWindowEx function (yellow circle on the form) is only available if you are running Windows 98 or 2000.

Instructions

Download the source and run it. The form, the command buttons and textbox will be elliptically shaped. Click on the Round Corners button to display a rectangular form with rounded corners. Next, click the Create Hole button to have a hole appear in the center of the form. Now position the form over another running application and click in the hole. You are actually clicking through the form and onto the underlying application.

On Win98 or 2000 PCs a yellow circle will be displayed between the 2 buttons. Click on the circle to bring up a popup menu. Select the different options to experiment with flashing the title.




About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page


© Copyright 2024 TheScarms
Goto top of page