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
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:
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.