User Tools

Site Tools


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

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
non-rectangular_20windows.txt · Last modified: 2018/04/16 15:53 by richardrussell