1. RE: Centering Windows
> -----Original Message-----
> From: president at insight-concepts.com
> [mailto:president at insight-concepts.com]
> Sent: Wednesday, 23 May 2001 9:25 AM
> To: EUforum
> Subject: Centering Windows
>
> Does anyone know how to center win32lib windows no matter
> what the screen
> resolution is?
Try this procedure.
---------------
--/Topic Utilities
--/proc centerWindow(integer id, integer referid)
--/desc Moves /i id control to the center of /i refid control.
--If /i refid is zero then the Screen is used.
--
--Example:
--/code
-- -- Move the window to the center of the screen.
-- centreWindow( myWIN, 0)
-- -- Move the button to the center of the window.
-- centreWindow( myButton, myWIN)
--/endcode
procedure centreWindow(integer id, integer referid)
sequence lRect, lClient, lRefRect
trace(1)
-- use Screen if no referid supplied.
if referid = 0 then
referid = Screen
end if
-- Get width and height of the window.
lRect = {0, 0} & getCtlSize(id)
-- Get left, top, right, bottom co-ordinates
-- of the reference control client area.
lRefRect = getClientRect(referid)
-- Calculate reference client area width and height
lRefRect[3] = lRefRect[3] - lRefRect[1]
lRefRect[4] = lRefRect[4] - lRefRect[2]
-- Calculate new left and top co-ordinates
lRect[1] = floor((lRefRect[3] - lRect[3]) * 0.5)
lRect[2] = floor((lRefRect[4] - lRect[4]) * 0.5)
-- Move the window to the new position and repaint it.
setRect(id, lRect[1], lRect[2], lRect[3] , lRect[4], True)
end procedure
-----------
cheers,
Derek Parnell
2. RE: Centering Windows
Thanks Derek,
The code you sent worked fine.
Long Live Euphoria,
Chris
At 11:47 23.05.2001 +1000, you wrote:
>
>
> > -----Original Message-----
> > From: president at insight-concepts.com
> > [mailto:president at insight-concepts.com]
> > Sent: Wednesday, 23 May 2001 9:25 AM
> > To: EUforum
> > Subject: Centering Windows
> >
> > Does anyone know how to center win32lib windows no matter
> > what the screen
> > resolution is?
>
>Try this procedure.
>
>---------------
>--/Topic Utilities
>--/proc centerWindow(integer id, integer referid)
>--/desc Moves /i id control to the center of /i refid control.
>--If /i refid is zero then the Screen is used.
>--
>--Example:
>--/code
>-- -- Move the window to the center of the screen.
>-- centreWindow( myWIN, 0)
>-- -- Move the button to the center of the window.
>-- centreWindow( myButton, myWIN)
>--/endcode
>procedure centreWindow(integer id, integer referid)
> sequence lRect, lClient, lRefRect
> trace(1)
> -- use Screen if no referid supplied.
> if referid = 0 then
> referid = Screen
> end if
>
> -- Get width and height of the window.
> lRect = {0, 0} & getCtlSize(id)
>
> -- Get left, top, right, bottom co-ordinates
> -- of the reference control client area.
> lRefRect = getClientRect(referid)
>
> -- Calculate reference client area width and height
> lRefRect[3] = lRefRect[3] - lRefRect[1]
> lRefRect[4] = lRefRect[4] - lRefRect[2]
>
> -- Calculate new left and top co-ordinates
> lRect[1] = floor((lRefRect[3] - lRect[3]) * 0.5)
> lRect[2] = floor((lRefRect[4] - lRect[4]) * 0.5)
>
<snip>
>
>
3. RE: Centering Windows
Thanks Derek,
The code you sent worked fine.
Long Live Euphoria,
Chris
-----------------------------------------------------------------
Derek Parnell wrote:
> > -----Original Message-----
> > From: president at insight-concepts.com
> > [mailto:president at insight-concepts.com]
> > Sent: Wednesday, 23 May 2001 9:25 AM
> > To: EUforum
> > Subject: Centering Windows
> >
> > Does anyone know how to center win32lib windows no matter
> > what the screen
> > resolution is?
>
> Try this procedure.
>
> ---------------
> --/Topic Utilities
> --/proc centerWindow(integer id, integer referid)
> --/desc Moves /i id control to the center of /i refid control.
> --If /i refid is zero then the Screen is used.
> --
> --Example:
> --/code
> -- -- Move the window to the center of the screen.
> -- centreWindow( myWIN, 0)
> -- -- Move the button to the center of the window.
> -- centreWindow( myButton, myWIN)
> --/endcode
> procedure centreWindow(integer id, integer referid)
> sequence lRect, lClient, lRefRect
> trace(1)
> -- use Screen if no referid supplied.
> if referid = 0 then
> referid = Screen
> end if
>
> -- Get width and height of the window.
> lRect = {0, 0} & getCtlSize(id)
>
> -- Get left, top, right, bottom co-ordinates
> -- of the reference control client area.
> lRefRect = getClientRect(referid)
>
> -- Calculate reference client area width and height
> lRefRect[3] = lRefRect[3] - lRefRect[1]
> lRefRect[4] = lRefRect[4] - lRefRect[2]
>
> -- Calculate new left and top co-ordinates
> lRect[1] = floor((lRefRect[3] - lRect[3]) * 0.5)
> lRect[2] = floor((lRefRect[4] - lRect[4]) * 0.5)
>
> -- Move the window to the new position and repaint it.
<snip>
4. RE: Centering Windows
Chris,
Here is my version. It takes into account the size and location of the
task bar as well as the screen resolution:
-- start --
include win32lib.ew
-- these constants are used in 'getWorkArea'
constant
xSystemParameters = registerw32Function
(user32, "SystemParametersInfoA",
{C_UINT, C_UINT, C_POINTER, C_UINT}, C_LONG),
SPI_GETWORKAREA = 48
------------------------------
-- FUNCTION: getWorkArea()
-- Returns: sequence containing the coordinates of the work area,
-- expressed in virtual screen coordinates {x1,y1, x2,y2}
------------------------------
global function getWorkArea()
atom mset, workarea
sequence wa_out
-- get pointer for RECT structure to receive coordinates
mset = new_memset()
workarea = acquire_mem( mset, SIZEOF_RECT )
-- call C function from user32.dll
if not w32Func( xSystemParameters, {SPI_GETWORKAREA, 0, workarea, 0} )
then
warnErr( "getWorkspace:SystemParametersInfo failed" )
end if
-- set return sequence
wa_out = { fetch( workarea, rectLeft ), fetch( workarea, rectTop ),
fetch( workarea, rectRight ), fetch( workarea, rectBottom )
}
-- free pointer
free( mset )
return wa_out
end function
------------------------------
-- FUNCTION: centerWindow
-- uses 'getWorkArea' to center window on destop,
-- regardless of taskbar location & size
-- Parameters:
-- id: ID of Window/Pixmap
------------------------------
global procedure centerWindow( integer id )
sequence wa, wa_size, id_size
integer winx, winy
wa = getWorkArea()
wa_size = { wa[3]-wa[1], wa[4]-wa[2] }
id_size = getCtlSize( id )
winx = wa[1] + floor( (wa_size[1] - id_size[1])/2 )
winy = wa[2] + floor( (wa_size[2] - id_size[2])/2 )
setRect( id, winx, winy, id_size[1], id_size[2], True )
end procedure
-- end --
-- Brian
Chris wrote:
> Hi all,
>
> Does anyone know how to center win32lib windows no matter what the
> screen
> resolution is?
>
> Chris
>