Non-rectangular windows
by Richard Russell, December 2006
Ordinary windows are rectangular, with square corners (with the exception of XP-style windows which have slightly rounded top corners). However this need not be the case - windows can be any shape (within reason). This article describes how to create a shaped window.
To start with, initialise your window to the nominal dimensions required, for example using a MODE or VDU 23,22 statement:
MODE 8
Next you are likely to want to remove your window's title bar and borders (Windows isn't clever enough to adapt them to your new shape!). You can do that as follows:
GWL_STYLE = -16 SYS "GetWindowLong", @hwnd%, GWL_STYLE TO ws% SYS "SetWindowLong", @hwnd%, GWL_STYLE, ws% AND NOT &C40000
Remember that now your window has no title bar (and therefore no system menu) you must ensure you provide the user with a means of closing the window and quitting your application (he can still use Alt-F4, but may not realise that).
Finally change the shape of your window to that desired. The example below gives it rounded corners:
SYS "CreateRoundRectRgn", 0, 0, 640, 480, 200, 200 TO hrgn% SYS "SetWindowRgn", @hwnd%, hrgn%, 1
(see Microsoft's documentation for CreateRoundRectRgn for what the parameters mean).
Other simple shapes you can use are an ellipse:
SYS "CreateEllipticRgn", 0, 0, 640, 480 TO hrgn% SYS "SetWindowRgn", @hwnd%, hrgn%, 1
or even a polygon:
vertices% = 5 DIM poly{(vertices%-1)x%,y%} FOR vertex% = 0 TO vertices%-1 poly{(vertex%)}.x% = 320+240*SIN(vertex%/vertices%*2*PI) poly{(vertex%)}.y% = 240+240*COS(vertex%/vertices%*2*PI) NEXT SYS "CreatePolygonRgn", poly{(0)}, vertices%, 1 TO hrgn% SYS "SetWindowRgn", @hwnd%, hrgn%, 1
If you want a more complicated shape you can combine two or more of the simple shapes. For example the following code combines two circles:
SYS "CreateEllipticRgn", 0, 0, 480, 480 TO hrgn% SYS "CreateEllipticRgn", 160, 0, 640, 480 TO hrgn2% SYS "CombineRgn", hrgn%, hrgn%, hrgn2%, 2 SYS "SetWindowRgn", @hwnd%, hrgn%, 1
Consult Microsoft's documentation for further details of shapes available and how they may be combined.