August 18, 2019, 03:31:03 pm

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How to: Manage window sizes

Started by ZeroDog, July 26, 2012, 03:55:24 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ZeroDog

Code Select




' How to: Manage window sizes
' By ZeroDog
' ----------------------------------------------------------------------------------
' This tutorial describes how to manage various aspects of your window sizes
' such as limiting the minimum and maximum sizes a window can be resized by dragging
' the window border, and controlling the size and position of maximized windows.
' ----------------------------------------------------------------------------------

' The first thing we need to do is define our variables, constants, and types.

' This constant is the window message we need to intercept in order to manage the
' various sizes and positions of the window.  The WM_GETMINMAXINFO message is sent
' to a window when the size or position of the window is about to change. 
const WM_GETMINMAXINFO = 0x24

' When a WM_GETMINMAXINFO message is sent, a MINMAXINFO structure is passed as
' the @LPARAM.  By default, the system will fill in this structure when the window
' is created, however, we can change this structure when the WM_GETMINMAXINFO is sent,
' overriding the default settings for the window.
type MINMAXINFO
def ptReserved as POINT
' ptReserved - Reserved; do not use.
def ptMaxSize as POINT
' ptMaxSize - Specifies the maximized width (point.x) and the maximized height (point.y) of the window.
def ptMaxPosition as POINT
' ptMaxPosition - Specifies the position of the left side of the maximized window (point.x) and the position of the top of the maximized window (point.y).
def ptMinTrackSize as POINT
' ptMinTrackSize - Specifies the minimum tracking width (point.x) and the minimum tracking height (point.y) of the window.
'  The minimum tracking size is the smallest window size that can be produced by using the borders to size the window.
def ptMaxTrackSize as POINT
' ptMaxTrackSize - Specifies the maximum tracking width (point.x) and the maximum tracking height (point.y) of the window.
'  The maximum tracking size is the largest window size that can be produced by using the borders to size the window.
endtype

' Our window variable.
def win as window

' Variables to store the screen width and height.
def screenwidth,screenheight as int
getscreensize screenwidth,screenheight

' Variables to store the left, top, width and height of the window.
def l,t,w,h as int

' We will now open the window.
openwindow win, 0,0,400,300, @caption|@maxbox|@minbox|@size, 0, "How to: Manage window sizes", &winproc

' Process window messages until run=0 (program closed).
run=1
waituntil run=0
closewindow win
end
' ----------------------------------------------------------------------------------


' ----------------------------------------------------------------------------------
' Our window message handler
sub winproc(),int
select @message
'---------------------------------------------------------------
' This is the message we intercept to manage the window sizes.
' The WM_GETMINMAXINFO message is sent to a window when the size
' or position of the window is about to change. An application can
' use this message to override the window's default maximized size
' and position, or its default minimum or maximum tracking size.
case WM_GETMINMAXINFO
' The MINMAXINFO structure is passed as a pointer in the @lparam in the window message
' We can access this structure using *<MINMAXINFO>@lparam
*<MINMAXINFO>@lparam.ptMaxSize.x = screenwidth-40:' Specifies the maximized width of the window
*<MINMAXINFO>@lparam.ptMaxSize.y = screenheight-100:' Specifies the maximized height of the window
*<MINMAXINFO>@lparam.ptMaxPosition.x = 20:' Specifies the position of the left side of the maximized window (point.x)
*<MINMAXINFO>@lparam.ptMaxPosition.y = 10:' Specifies the position of the top of the maximized window (point.y).
*<MINMAXINFO>@lparam.ptMinTrackSize.x = 420:' Specifies the minimum tracking width (point.x)
*<MINMAXINFO>@lparam.ptMinTrackSize.y = 300:' Specifies the minimum tracking height (point.y)
*<MINMAXINFO>@lparam.ptMaxTrackSize.x = screenwidth-40:' Specifies the maximum tracking width (point.x)
*<MINMAXINFO>@lparam.ptMaxTrackSize.y = screenheight-100:' Specifies the maximum tracking height (point.y)
' Write some info to the window
move win,0,0 : print win,"Win Size x: "+str$(w)+"    Win Size y:"+str$(h)+"      "
move win,0,40 : print win,"Min Track Size x: "+str$(*<MINMAXINFO>@lparam.ptMinTrackSize.x)+"    Min Track Size y:"+str$(*<MINMAXINFO>@lparam.ptMinTrackSize.y)+"      "
move win,0,80 : print win,"Max Track Size x: "+str$(*<MINMAXINFO>@lparam.ptMaxTrackSize.x)+"    Max Track Size y:"+str$(*<MINMAXINFO>@lparam.ptMaxTrackSize.y)+"      "
move win,0,120 : print win,"Max Size x: "+str$(*<MINMAXINFO>@lparam.ptMaxSize.x)+"    Max Size y:"+str$(*<MINMAXINFO>@lparam.ptMaxSize.y)+"      "
move win,0,160 : print win,"Max Position x: "+str$(*<MINMAXINFO>@lparam.ptMaxPosition.x)+"    Max Position y:"+str$(*<MINMAXINFO>@lparam.ptMaxPosition.y)+"      "
'---------------------------------------------------------------
' When the window size is changed, update the window info
case @idsizechanged
getsize win,l,t,w,h
move win,0,0 : print win,"Win Size x: "+str$(w)+"    Win Size y:"+str$(h)+"      "
'---------------------------------------------------------------
' When the window is first created, center it
case @idcreate
centerwindow win
'---------------------------------------------------------------
' When the user closes the window, end the program
case @idclosewindow
run=0
'---------------------------------------------------------------
endselect
return 0
endsub
' ----------------------------------------------------------------------------------