Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

At 08 JAN 1999 01:02:11PM Rick Todd wrote:

Is there a way to have a form window automatically center itself on the screen whenever and where ever it is opened?

Thanks Rick


At 08 JAN 1999 02:15PM Dave Pociu wrote:

You can use

GET_PROPERTY( "SYSTEM" , "SIZE" ) for screen size

and GET_PROPERTY( @window , 'SIZE') for window size.

Create the new windows size and then SET_PROPERTY( @window ,"SIZE", new_size)

I will post a subroutine I have that's going this shortly.

Dave


At 08 JAN 1999 03:08PM Dave Pociu wrote:

Here's the code for centering a window. It's a little messy but it works!

What I do is make the window invisible at designe time, then put a call in to CENTER_WIN() during CREATE.

You should also replace every reference to get and set with get_property and set_property. Get and Set are my internal shell functions that extend the functionality of Get_Property and Set_Property ( and are easier to type ;) )

compile subroutine center_win(NULL)

/* Written on 12/10/97 - by JW for Insight */

/* Subroutine repositions the window in the center of the screen and makes it visible */

/* Pass with no parameters */

declare function get, set

placement=get(@window,'SIZE')

ScreenSize=Get("SYSTEM", "SIZE")

parent=get(@window , 'PARENT')

if parent # "MENU_FORM" then

ParentSize=Get(parent , "SIZE")

end else

ParentSize='

end

/*

if ParentSize # then ParentSize=0":@fm:"0":@fm:ParentSize end */ xPos=0;yPos=0 if placement # then

wScreen=ScreenSize		;* width of screen
hScreen=ScreenSize		;* height of screen
xplacement=placement	;* x position of window
yplacement=placement	;* y position of window
wplacement=placement	;* width of window
hplacement=placement	;* height of window
xParent=ParentSize		;* x position of parent
yParent=ParentSize		;* y position of parent
wParent=ParentSize		;* width of parent
hParent=ParentSize		;* height of parent

/* When the parent windows have been created "rem" the following two lines */

/* in order to position the windows w.r.t. the Parent window. */

if ParentSize=' then
	placement=(wScreen - wplacement) / 2
	placement=(hScreen - hplacement) / 2
end else

/* When the parent windows have been created "un-rem" the following two lines */

/* in order to position the windows w.r.t. the Parent window. */

	placement=(wParent - wplacement)/2
	placement=(hParent - hplacement)/2
end

end else

call msg(@window,"Program CENTER_WIN malfunction while trying to reposition window.")

end

new_placement=set(@window,'SIZE',placement)

= set("SYSTEM" , "FOCUS" , @window)

return


At 11 JAN 1999 05:28AM Oystein Reigem wrote:

Rick,

Dave's function contains all you need for centering, but if you need more, like the ability to put a window at a certain offset to its parent, you can use my routine below. (You may want to change the name of the routine and a few program error msg calls.)

- Oystein -

<code>

subroutine Plasser_Vindu( WhichPointInThis, RelativeWhat, WhichPointInThat, Offset, NotOutsideScreen, NewDim )
 
    /*
    
    this subroutine places and sizes the current window
    according to its parameters,
    and makes the window visible.
    
    this subroutine is usually called at window startup,
    in the window's CREATE handler.
    
    note that the window should be set to invisible in Form Designer,
    or else the window will make a noticable jump on the screen.
    
    use:
    
    to center the window relative to the screen
    set the first four parameters to "centre", "screen", "centre", "",
    which means the centre of the window (1st param)
    should be placed relative the screen (2nd param),
    more specifically at the centre (3rd param) of the screen.
    
    to center the window relative to its parent instead
    set the first four parameters to "centre", "parent", "centre", "".
    
    to place the window "cascaded" relative to its parent,
    e.g with its upper left corner 100 pixels to the right and 50 pixels down
    from the parent's upper left corner,
    set the first four parameters to "ulc", "parent", "ulc", 100:@FM:50 .
    
    other combinations of the first four parameters are also possible.
    (note that "center" can be used instead of "centre".)
    
    sometimes the parameters above would make the window
    fall partly or wholly outside the screen.
    by default the subroutine will try to avoid that.
    to overrule the default behaviour
    set the fifth parameter - NotOutsideScreen - to false$ (0).
    
    some windows may not have a fixed height and width;
    the height and width will be determined at startup,
    in the CREATE handler.
    (example: if one has a popup window
    that shows a set of values or lines in an edit table,
    one would perhaps like the window to change its height
    according to the number of values there are to show.)
    but since setting the SIZE property of a window
    has the side effect of making the window visible,
    the CREATE handler should not try to change the height and width itself.
    it should leave it to this subroutine.
    this is what the last parameter - NewDim - is for.
    NewDim is  : @FM : .
    
    */
    
    $insert Logical
    
    declare function Set_Property
    declare function Get_Property
    
    declare function Konv_AmTegn_Til_Smaa
    
    /**************************/
    /* initialize parameters. */
    /* standardize.           */
    /* set defaults           */
    /**************************/
    
    /* initialize missing parameters */
    
    if assigned( WhichPointInThis ) else WhichPointInThis='
    if assigned( RelativeWhat )     else RelativeWhat='
    if assigned( WhichPointInThat ) else WhichPointInThat='
    if assigned( Offset )           else Offset='
    if assigned( NotOutsideScreen ) else NotOutsideScreen='
    if assigned( NewDim )           else NewDim='
    
    /* handle case */
    
    WhichPointInThis=Konv_AmTegn_Til_Smaa( WhichPointInThis )
    RelativeWhat    =Konv_AmTegn_Til_Smaa( RelativeWhat )
    WhichPointInThat=Konv_AmTegn_Til_Smaa( WhichPointInThat )
    NotOutsideScreen=Konv_AmTegn_Til_Smaa( NotOutsideScreen )
    
    /* handle variants and set default values */
    
    begin case
    case WhichPointInThis=centre' or WhichPointInThis=center'
        WhichPointInThis=centre'
    case WhichPointInThis=ulc'
    case true$   /* dvs else */
        /* default */
        WhichPointInThis=centre'
    end case
    
    begin case
    case RelativeWhat=screen'
    case RelativeWhat=parent'
    case true$   /* dvs else */
        /* default */
        RelativeWhat=parent'
    end case
    
    if RelativeWhat=parent' then
        Parent=Get_Property( @Window, 'PARENT' )
        /*call xmsg( 'Parent=, Parent )*/
        if Parent=' then
            RelativeWhat=screen'
        end
    end
    
    begin case
    case WhichPointInThat=centre' or WhichPointInThat=center'
        WhichPointInThat=centre'
    case WhichPointInThat=ulc'
    case true$   /* dvs else */
        /* default */
        WhichPointInThat=centre'
    end case
    
    X_Offset=Offset
    if num( X_Offset ) else X_Offset=0
    Y_Offset=Offset
    if num( Y_Offset ) else Y_Offset=0
    
    begin case
    case NotOutsideScreen=true$ 
    case NotOutsideScreen=false$ 
    case true$   /* dvs else */
        /* default */
        NotOutsideScreen=true$ 
    end case
    
    SizeOfThis=Get_Property( @Window, 'SIZE' )
    if NewDim=' then
        NewSizeOfThis=SizeOfThis
    end else
        NewSizeOfThis='
        NewSizeOfThis=SizeOfThis
        NewSizeOfThis=SizeOfThis
        NewSizeOfThis=NewDim
        NewSizeOfThis=NewDim
    end
    
    /*************/
    /* calculate */
    /*************/
    
    /* the size of the screen */
    
    Temp=Get_Property( 'SYSTEM', 'SIZE' )
    SizeOfScreen=Temp : @FM : Temp
    
    /* distance from the ulc of the screen
       to the ulc of whatever we place the window relative to */
    
    begin case
    case RelativeWhat=screen'
        SizeOfThat=0 : @FM : 0 : @FM : SizeOfScreen
    case RelativeWhat=parent'
        Parent=Get_Property( @Window, 'PARENT' )
        SizeOfThat=Get_Property( Parent, 'SIZE' )
    case true$   /* dvs else */
        call msg( @Window, '*** Programfeil 1 i subroutine Plasser_Vindu ***' )
    end case
    DistFromULCOfScreen=SizeOfThat : @FM : SizeOfThat
    
    /* distance from the ulc of the screen
       to the point we place the window relative to */
    
    begin case
    case WhichPointInThat=centre'
        DistFromULCOfScreen=DistFromULCOfScreen + SizeOfThat / 2 
        DistFromULCOfScreen=DistFromULCOfScreen + SizeOfThat / 2 
    case WhichPointInThat=ulc'
        /*DistFromULCOfScreen=DistFromULCOfScreen*/
    case true$   /* dvs else */
        call msg( @Window, '*** Programfeil 2 i subroutine Plasser_Vindu ***' )
    end case
    
    /* distance from the ulc of the screen
       to the ulc of the window, offset not included */
    
    begin case
    case WhichPointInThis=centre'
        DistFromULCOfScreen=DistFromULCOfScreen - NewSizeOfThis / 2 
        DistFromULCOfScreen=DistFromULCOfScreen - NewSizeOfThis / 2 
    case WhichPointInThis=ulc'
        /*DistFromULCOfScreen=DistFromULCOfScreen*/
    case true$   /* dvs else */
        call msg( @Window, '*** Programfeil 3 i subroutine Plasser_Vindu ***' )
    end case
    
    /* distance from the ulc of the screen
       to the ulc of the window, offset included */
    
    DistFromULCOfScreen=DistFromULCOfScreen + X_Offset
    DistFromULCOfScreen=DistFromULCOfScreen + Y_Offset
    /*call xmsg( 'DistFromULCOfScreen=, DistFromULCOfScreen )*/
    
    /* round off to nearest pixel */
    
    DistFromULCOfScreen=Int( DistFromULCOfScreen ) 
    DistFromULCOfScreen=Int( DistFromULCOfScreen ) 

    if NotOutsideScreen=true$ then
        /* if necessary modify that distance to try and keep the window wholly inside the screen */
        /* first make sure the window is not outside the right and bottom edges */
        if DistFromULCOfScreen + NewSizeOfThis ] SizeOfScreen then  
            DistFromULCOfScreen=SizeOfScreen - NewSizeOfThis
        end  
        if DistFromULCOfScreen + NewSizeOfThis ] SizeOfScreen then  
            DistFromULCOfScreen=SizeOfScreen - NewSizeOfThis
        end
        /* but more important is it that the window is not outside the left and top edges. 
           make sure it isn't */
        if DistFromULCOfScreen =0
        end  
        if DistFromULCOfScreen =0
        end
        /* (so now if the window is wider than the screen
           it will left align with the screen and stick out on the right side.
           and if it is higher than the screen 
           it will top align with the screen and go beyond the bottom) */
    end
     
    /***********************/
    /* place the window    */
    /* and make it visible */
    /***********************/
    
    /* place the window */
    
    SizeOfThis=DistFromULCOfScreen
    SizeOfThis=DistFromULCOfScreen
    
    OldVal=Set_Property( @Window, 'SIZE', SizeOfThis )
    
    /* make it visible.
       not really necessary because it gets visible as a side effect of setting SIZE */
    
    OldVal=Set_Property( @Window, 'VISIBLE', true$ )
    
return 0

</code>

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/db825ea4cbbe94df852566f3006313ca.txt
  • Last modified: 2024/01/04 21:00
  • by 127.0.0.1