logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Irregular Forms and Region Clipping by Brian Yule

Posted on
7/31/2002
Author:
Brian Yule
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
5, 6



Author: Brian Yule (byule at PembrokeTechnology.com)
Note: if all this region clipping stuff is old hat to you,
check out Part II of this article, which features really advanced features.

Download... the project. (61 kb)

Forms that don't have the regular rectangular shape can differentiate your application from others. In addition, irregular forms can be used to call attention to an issue in your application. Windows has provided a way to create an irregular form since 1995 via region clipping. Nevertheless, it is not exactly easy to create these things well. Despite the promise, there are issues with the way these forms look: absense of anti-aliasing require that exquisite graphic work be done on the background of the form.

Brian Yule created an attractive circular clock, where the absense of anti-aliasing more than compensated by a well-done graphic. In addition, it demonstrates GDI graphics programming, by drawing and erasing hour/minute/second hand lines

Clock

Actually, to create a circular form is quite simple, by pasting the code below using the code below into your form:

Option Explicit

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, _
    ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, _
    ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Sub Form_Activate()
    Dim hndRgn As Long
    
    hndRgn = CreateEllipticRgn(0, 0, 175, 175)
    Call SetWindowRgn(Me.hWnd, hndRgn, True)
    Call DeleteObject(hndRgn)
End Sub

This was pretty simple but your form will look ridiculous:

Ridiculously looking irregular form

In particular the jagged edges of the circle look unforgiving. So as you can see, there is more to do. So one of the first things to do is to set the BorderStyle should be set to None to get rid of the title bar. Then draw a graphics that will fill in or obscure the edges. If you look closely at the clock app at the top of the page, you will see that the jagged edges are there too, but they are obscured by the soft yellowish color.

See the download for more information.

Download... the project. (61 kb)

To get in touch with the author of this example, email Brian Yule at byule at PembrokeTechnology.com

If you grokked this article, it is time for a look at a truly advanced region clipping features such as image adaptation technology, which allows you to specify an image and create a form out of its outline. Check out part II.





Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Bill. Posted on 12/2/2006 9:01:22 PM
Very sad that part II was unavailable. This is a very cool trick.

#2. By Author. Posted on 12/3/2006 1:15:07 AM
Link is now fixed. Part II is available.

#3. By Talat_Dhandhuka_India. Posted on 6/1/2007 10:29:22 PM
I had long been looking for a way to make a circular clock. Rectangular and Squre Clocks I have made so many. So, I think this download will fulfil my long awaited desire to present my App in forms other than rectangle.
I always wondered how they manage to hide the corner of the form when they create something like a skin of media player or round clock. But, there was no one I could ask. Just a while ago,I read about XML but haven't got time to pay attention to it. Meanwhile I came across this page. That's it.
Thanking in anticipation of everything going well.