RE: Centering Windows
- Posted by Brian Broker <bkb at cnw.com> May 23, 2001
- 476 views
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 >