User Tools

Site Tools


limiting_20the_20size_20of_20a_20window

Differences

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

Link to this comparison view

limiting_20the_20size_20of_20a_20window [2018/03/31 13:19]
127.0.0.1 external edit
limiting_20the_20size_20of_20a_20window [2018/04/16 14:51] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Limiting the size of a window===== =====Limiting the size of a window=====
  
-//by Richard Russell, October 2007//\\ \\  Normally windows are either fully resizable by the user (by dragging a corner or edge), which is the default, or are a fixed size (see the Help documentation under [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwine.html#​fixwindowsize|Fixing the window size]]). However, occasionally you may want to allow the user to resize the window, but only within certain limits. You can do that by handling the **WM_SIZING** Windows message, which you can do using the **SUBCLASS** library.\\ \\  The code below illustrates how to restrict the maximum size of the window to 800 x 600 pixels. Firstly some initialisation:​\\ +//by Richard Russell, October 2007//\\ \\  Normally windows are either fully resizable by the user (by dragging a corner or edge), which is the default, or are a fixed size (see the Help documentation under [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwine.html#​fixwindowsize|Fixing the window size]]). However, occasionally you may want to allow the user to resize the window, but only within certain limits. You can do that by handling the **WM_SIZING** Windows message, which you can do using the **SUBCLASS** library.\\ \\  The code below illustrates how to restrict the maximum size of the window to 800 x 600 pixels. Firstly some initialisation:​ 
 + 
 +<code bb4w>
         INSTALL @lib$+"​SUBCLASS"​         INSTALL @lib$+"​SUBCLASS"​
         INSTALL @lib$+"​NOWAIT"​         INSTALL @lib$+"​NOWAIT"​
Line 10: Line 12:
         PROC_subclass(WM_SIZING,​ FN_wmsizing())         PROC_subclass(WM_SIZING,​ FN_wmsizing())
         ON ERROR PROC_unsubclass : SYS "​MessageBox",​ @hwnd%, REPORT$, 0, 48 : QUIT         ON ERROR PROC_unsubclass : SYS "​MessageBox",​ @hwnd%, REPORT$, 0, 48 : QUIT
-You should ensure that you are using version 1.3 or later of **SUBCLASS.BBC**.\\ \\  Now the program can perform whatever task it is designed for; for the purposes of the example this is just an empty loop:\\ +</​code>​ 
 + 
 +You should ensure that you are using version 1.3 or later of **SUBCLASS.BBC**.\\ \\  Now the program can perform whatever task it is designed for; for the purposes of the example this is just an empty loop: 
 + 
 +<code bb4w>
         PRINT "​Window size is limited to ";​MAXW%;"​ by ";​MAXH%         PRINT "​Window size is limited to ";​MAXW%;"​ by ";​MAXH%
         REPEAT         REPEAT
Line 16: Line 22:
         UNTIL FALSE         UNTIL FALSE
         END         END
-Note that while subclassing is in effect you must avoid statements which may take a long time to execute, such as **GET**, **INKEY**, **INPUT** and **WAIT** (WAIT should be avoided even if the delay is short). You should also be careful not to use **SOUND** when the sound queue is already full. You can find suitable replacements for these functions in the [[/​Libraries|NOWAIT library]].\\ \\  Finally here is the routine for handling the **WM_SIZING** messages:\\ +</​code>​ 
 + 
 +Note that while subclassing is in effect you must avoid statements which may take a long time to execute, such as **GET**, **INKEY**, **INPUT** and **WAIT** (WAIT should be avoided even if the delay is short). You should also be careful not to use **SOUND** when the sound queue is already full. You can find suitable replacements for these functions in the [[/​Libraries|NOWAIT library]].\\ \\  Finally here is the routine for handling the **WM_SIZING** messages: 
 + 
 +<code bb4w>
         DEF FN_wmsizing(msg%,​ side%, lprc%)         DEF FN_wmsizing(msg%,​ side%, lprc%)
         LOCAL rc{}         LOCAL rc{}
Line 34: Line 44:
         ENDIF         ENDIF
         = 1         = 1
-If you want to limit the //minimum// size of the window instead the //maximum// size the routine would be:\\ +</​code>​ 
 + 
 +If you want to limit the //minimum// size of the window instead the //maximum// size the routine would be: 
 + 
 +<code bb4w>
         DEF FN_wmsizing(msg%,​ side%, lprc%)         DEF FN_wmsizing(msg%,​ side%, lprc%)
         LOCAL rc{}         LOCAL rc{}
Line 52: Line 66:
         ENDIF         ENDIF
         = 1         = 1
 +</​code>​
 +
 I'm sure you can see how to limit both the minimum and maximum sizes, if desired. I'm sure you can see how to limit both the minimum and maximum sizes, if desired.
limiting_20the_20size_20of_20a_20window.txt · Last modified: 2018/04/16 14:51 by richardrussell