| I like to run Windows with my resolution set to 800x600 and one of my pet
hates is response windows that are centralised for 640x480. This is such a simple thing to
fix now that PB4 has a function designed to help us out with this problem. Declare a
subroutine in your window ancestor called center() and place the following
code in it.
Environment env_Env
GetEnvironment( env_Env )
this.X = ( PixelsToUnits( env_Env.ScreenWidth, &
XPixelsToUnits! ) - this.Width ) / 2
this.Y = ( PixelsToUnits( env_Env.ScreenHeight, &
YPixelsToUnits! ) - this.Height ) /2
Now in your open event you can call center() to centralise all your response windows
regardless of screen resolution.
You can take this routine a step further, when I was writing PBDelta V2 I had the above
code in my center routine but the problem was that I now run my PC with the resolution set
1024x768. PBDelta V2 is an MDI application and while the code works fine when the MDI
Frame is maximized, now I have a large desktop I run my applications unmaximized. So now
my response windows are not centered around the location on the screen where I am working.
Phew! If you are still with me then the solution is to check for a valid MDI Frame and if
it is valid then center the response window based upon the MDI Frame. The code looks like
the following:
Long ll_X, ll_Y
Window lw_MdiFrame
// lw_MdiFrame contains a pointer to your MDI Frame
IF IsValid( lw_mdiFrame ) THEN
ll_X = lw_mdiframe.X + &
( lw_mdiframe.Width / 2 ) - ( this.Width / 2 )
ll_Y = lw_mdiframe.Y + &
( lw_mdiframe.Height / 2 ) - ( this.Height / 2 )
ELSE
Environment lenv_Env
GetEnvironment( lenv_Env )
ll_X = ( PixelsToUnits( lenv_Env.ScreenWidth, &
XPixelsToUnits! ) - this.Width ) / 2
ll_Y = ( PixelsToUnits( lenv_Env.ScreenHeight, &
YPixelsToUnits! ) - this.Height ) /2
END IF
IF ll_X < 1 THEN ll_X = 1
IF ll_Y < 1 THEN ll_Y = 1
this.X = ll_X
this.Y = ll_Y
|