User Tools

Site Tools


non-rectangular_20windows

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

non-rectangular_20windows [2018/03/31 13:19]
127.0.0.1 external edit
non-rectangular_20windows [2018/04/16 14:53] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Non-rectangular windows===== =====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:\\ \\ +//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: 
 + 
 +<code bb4w>
         MODE 8         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:\\ \\ +</​code>​ 
 + 
 +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: 
 + 
 +<code bb4w>
         GWL_STYLE = -16         GWL_STYLE = -16
         SYS "​GetWindowLong",​ @hwnd%, GWL_STYLE TO ws%         SYS "​GetWindowLong",​ @hwnd%, GWL_STYLE TO ws%
         SYS "​SetWindowLong",​ @hwnd%, GWL_STYLE, ws% AND NOT &C40000         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:\\ \\ +</​code>​ 
 + 
 +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: 
 + 
 +<code bb4w>
         SYS "​CreateRoundRectRgn",​ 0, 0, 640, 480, 200, 200 TO hrgn%         SYS "​CreateRoundRectRgn",​ 0, 0, 640, 480, 200, 200 TO hrgn%
         SYS "​SetWindowRgn",​ @hwnd%, hrgn%, 1         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:\\ \\ +</​code>​ 
 + 
 +(see Microsoft'​s documentation for **CreateRoundRectRgn** for what the parameters mean).\\ \\  Other simple shapes you can use are an ellipse: 
 + 
 +<code bb4w>
         SYS "​CreateEllipticRgn",​ 0, 0, 640, 480 TO hrgn%         SYS "​CreateEllipticRgn",​ 0, 0, 640, 480 TO hrgn%
         SYS "​SetWindowRgn",​ @hwnd%, hrgn%, 1         SYS "​SetWindowRgn",​ @hwnd%, hrgn%, 1
-or even a polygon:\\ \\ +</​code>​ 
 + 
 +or even a polygon: 
 + 
 +<code bb4w>
         vertices% = 5         vertices% = 5
         DIM poly{(vertices%-1)x%,​y%}         DIM poly{(vertices%-1)x%,​y%}
Line 24: Line 42:
         SYS "​CreatePolygonRgn",​ poly{(0)}, vertices%, 1 TO hrgn%         SYS "​CreatePolygonRgn",​ poly{(0)}, vertices%, 1 TO hrgn%
         SYS "​SetWindowRgn",​ @hwnd%, hrgn%, 1         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:\\ \\ +</​code>​ 
 + 
 +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: 
 + 
 +<code bb4w>
         SYS "​CreateEllipticRgn",​ 0, 0, 480, 480 TO hrgn%         SYS "​CreateEllipticRgn",​ 0, 0, 480, 480 TO hrgn%
         SYS "​CreateEllipticRgn",​ 160, 0, 640, 480 TO hrgn2%         SYS "​CreateEllipticRgn",​ 160, 0, 640, 480 TO hrgn2%
         SYS "​CombineRgn",​ hrgn%, hrgn%, hrgn2%, 2         SYS "​CombineRgn",​ hrgn%, hrgn%, hrgn2%, 2
         SYS "​SetWindowRgn",​ @hwnd%, hrgn%, 1         SYS "​SetWindowRgn",​ @hwnd%, hrgn%, 1
 +</​code>​
 +
 Consult Microsoft'​s documentation for further details of shapes available and how they may be combined. Consult Microsoft'​s documentation for further details of shapes available and how they may be combined.
non-rectangular_20windows.txt · Last modified: 2018/04/16 14:53 by richardrussell