User Tools

Site Tools


effect_20of_20menu_20bar_20on_20window_20size

Differences

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

Link to this comparison view

effect_20of_20menu_20bar_20on_20window_20size [2018/03/31 13:19]
127.0.0.1 external edit
effect_20of_20menu_20bar_20on_20window_20size [2018/04/16 14:23] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Effect of menu bar on window size===== =====Effect of menu bar on window size=====
  
-//by Richard Russell, May 2006//\\ \\  Adding a menu bar to your output window has the effect of reducing the size of the '​client area', i.e. the area available for your program'​s output. So, assuming for example that your program selects **MODE 8** (which would normally be 640 pixels wide by 512 pixels high), after creating the menu the available height will be reduced to something like 492 pixels.\\ \\  In practice, because Windows uses the top-left corner as its reference point, it's the bottom 20 pixels or so of the window that is '​lost',​ and anything drawn there will not be visible (in effect the bottom left-hand corner of the visible area will correspond to approximate graphics coordinates of 0,40 rather than 0,0). You can reset the graphics origin to the bottom left corner by executing a **VDU 26** but the height will still be reduced.\\ \\  If you want to add a menu bar without making the client area smaller it is necessary to increase the size of the output window. There are two ways of doing that, a rough-and-ready way and a better way!\\ \\  The rough-and-ready way is to assume that the menu bar will always be the same height, say 20 pixels. In that case you can simply set your window size accordingly,​ so to achieve the equivalent of **MODE 8** (640 x 512):\\ \\ +//by Richard Russell, May 2006//\\ \\  Adding a menu bar to your output window has the effect of reducing the size of the '​client area', i.e. the area available for your program'​s output. So, assuming for example that your program selects **MODE 8** (which would normally be 640 pixels wide by 512 pixels high), after creating the menu the available height will be reduced to something like 492 pixels.\\ \\  In practice, because Windows uses the top-left corner as its reference point, it's the bottom 20 pixels or so of the window that is '​lost',​ and anything drawn there will not be visible (in effect the bottom left-hand corner of the visible area will correspond to approximate graphics coordinates of 0,40 rather than 0,0). You can reset the graphics origin to the bottom left corner by executing a **VDU 26** but the height will still be reduced.\\ \\  If you want to add a menu bar without making the client area smaller it is necessary to increase the size of the output window. There are two ways of doing that, a rough-and-ready way and a better way!\\ \\  The rough-and-ready way is to assume that the menu bar will always be the same height, say 20 pixels. In that case you can simply set your window size accordingly,​ so to achieve the equivalent of **MODE 8** (640 x 512): 
 + 
 +<code bb4w>
         VDU 23,​22,​640;​532;​8,​16,​16,​0         VDU 23,​22,​640;​532;​8,​16,​16,​0
         SYS "​CreateMenu"​ TO hmenu%         SYS "​CreateMenu"​ TO hmenu%
Line 8: Line 10:
         SYS "​DrawMenuBar",​ @hwnd%         SYS "​DrawMenuBar",​ @hwnd%
         VDU 26         VDU 26
-However it is unwise to assume that the menu bar will always be a particular height. The better way of doing it is to use the AdjustWindowRect API function:\\ \\ +</​code>​ 
 + 
 +However it is unwise to assume that the menu bar will always be a particular height. The better way of doing it is to use the AdjustWindowRect API function: 
 + 
 +<code bb4w>
         GWL_STYLE = -16         GWL_STYLE = -16
         DIM rc{l%,​t%,​r%,​b%}         DIM rc{l%,​t%,​r%,​b%}
Line 21: Line 27:
         SYS "​DrawMenuBar",​ @hwnd%         SYS "​DrawMenuBar",​ @hwnd%
         VDU 4,20,26,12         VDU 4,20,26,12
 +</​code>​
 +
 An extended version of this code which also takes into account the presence of a toolbar and/or status bar, and the effect of different DPI (dots per inch) values, can be found [[/​Supporting%20different%20DPI%20values|here]]. An extended version of this code which also takes into account the presence of a toolbar and/or status bar, and the effect of different DPI (dots per inch) values, can be found [[/​Supporting%20different%20DPI%20values|here]].
effect_20of_20menu_20bar_20on_20window_20size.txt · Last modified: 2018/04/16 14:23 by richardrussell