Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

screen resolution 2

Status
Not open for further replies.

adit39

Technical User
May 6, 2006
26
US
What is best way to dynamically change application to the various screen resolutions end users may be using. We are programmed initally to run 1024x768 but would like to run on different computers with different resolutions without requiring user to change his or her setup. We use Sysmetric(1) to determine screen size and run maximized so, is there a way to fit the app to 1284x1080 screen dynamically or must I use a CASE statement for each possibilty?
Thanks in advance.
Anthony
 
I was given the following code some years ago -you may be able to modify it.

Code:
  CASE _SCREEN.WIDTH > 1000 AND _SCREEN.WIDTH < 1100  && 1024x768
        DEFINE WINDOW MainWind FROM -1.5,0 TO 43.5,114 ;
            FONT 'COURIER NEW',15;
            ICON FILE 'SALONTEC.ICO' ;
            NOCLOSE;
            FLOAT;
            NOGROW;
            NOZOOM;
            COLOR SCHEME 1
             

    CASE _SCREEN.WIDTH > 1200 AND _SCREEN.WIDTH < 1300  && 1280x1024
        DEFINE WINDOW MainWind FROM 0,0 TO 55,142 ;
            FONT 'COURIER NEW',18;
            ICON FILE 'SALONTEC.ICO' ;
            NOCLOSE;
            FLOAT;
            NOGROW;
            NOZOOM;
            COLOR SCHEME 1
             
    OTHERWISE
        =MESSAGEBOX("Monitor Resolution must be: 1024x768 or 1280x1024",48,"Warning")
        CANCEL

ENDCASE

HTH Bryan
 
My client has utilities within an EXE application which utilize Forms of varying sizes.

In order to dynamically maximize the over-all Screen size on a select few of the wider Forms so that they will be best displayed on them I use the following code in the Load Method of the Form.

Note that I am intentionally only going to a only percentage of the over-all workstation screen size with my VFP screen (85% for height and 97% for width)
Code:
* --- Determine Workstation Display Settings ---
mnScreenW = SYSMETRIC(1) && Screen Width
mnScreenH = SYSMETRIC(2) && Screen Height

IF _SCREEN.WIDTH < (THISFORM.WIDTH * 1.1);
      OR _SCREEN.HEIGHT < (THISFORM.HEIGHT * 1.1)
   * --- Save Values For Return To 'Normal' ---
   ThisForm.ScreenHeight = _SCREEN.HEIGHT
   ThisForm.ScreenWidth = _SCREEN.WIDTH

   * --- Change Screen Size ---
   _SCREEN.HEIGHT = (mnScreenH * .85)
   _SCREEN.WIDTH = (mnScreenW * .97)
   _SCREEN.AUTOCENTER = .F.
   _Screen.Refresh
   
   * --- Original Auto-Center No Longer Works ---
   * -- Modify FORM Position To Center On New Screen Size ---
   THISFORM.TOP = (((mnScreenH * .85) - THISFORM.HEIGHT) / 2)
   THISFORM.LEFT = (((mnScreenW * .97) - THISFORM.WIDTH) / 2)
ENDIF

The user then runs the Form and in the Form's Unload Method I use the following code to return to the original screen size.
Code:
mnScreenHeight = THISFORM.ScreenHeight
IF !(TYPE('mnScreenHeight') $ "U,L")
   _SCREEN.HEIGHT = THISFORM.ScreenHeight
   _SCREEN.WIDTH = THISFORM.ScreenWidth
   _SCREEN.REFRESH
ENDIF  && IF !(TYPE('mnScreenHeight') $ "U,L")

I'd guess that you could modify this code to do what you need.

However, remember that changing the over-all VFP screen size will not, by itself, change the Form size.

Good Luck,
JRB-Bldr
 
Hi Anthony,

Just to add to the good advice you've already been given.

Basically, there are three ways of finding the size of the screen:

1. _SCREEN gives the size of the client area (the window minus the form title and borders) of the main VFP window.

2. SYSMETRIC() gives the size of the physical screen.

3. SystemParametersInfo() (which a Windows API function) can be used to determine the size of the physical screen minus any fixed objects such as the Windows taskbar. This is important, because if you rely on SYSMETRIC() alone, your application's window will cover the taskbar.

Here's how to use SystemParametersInfo():

Code:
* Returns the height of the physical screen, taking
* account of the taskbar, if visible.

LOCAL lcBuffer, lcDWord

DECLARE INTEGER SystemParametersInfo IN Win32Api ;
  INTEGER   uiAction,;
  INTEGER   uiParam,;
  STRING    @pvParam,;
  INTEGER   fWinIni

lcBuffer = SPACE(16)
SystemParametersInfo(48, 0, @lcBuffer, 0)

lcDWord = SUBSTR(lcBuffer, 13, 4)
  && or take bytes 9-12 for the screen width

RETURN ASC(SUBSTR(lcDWord, 1,1)) + ;
  BITLSHIFT(ASC(SUBSTR(lcDWord, 2,1)),  8) +;
  BITLSHIFT(ASC(SUBSTR(lcDWord, 3,1)), 16) +;
  BITLSHIFT(ASC(SUBSTR(lcDWord, 4,1)), 24)

Hope this helps.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Here is some code to help get you started on creating forms that resize themselves according to the screen resolution of the computer they are running on. This is very old code, so if your propgram is running on wide screen monitors, you will have to modify it becasue the aspect ratio on a wide screen is different.

Add this code to the Init of your base form class:
Code:
LOCAL loControl
WITH Thisform
  *** Determine the ratio needed to maximize the form
  *** depending on screen resolution and store it to form properties
  .WidthRatio = SYSMETRIC( 1 ) / 640
  .HeightRatio = SYSMETRIC( 2 ) / 480
  *** If resolution is higher than 640 x 480, reposition
  *** and maximize the form
  IF .WidthRatio > 1
    .Top = 0
    .Left = 0
    .Width = .Width * .WidthRatio
    .Height = .Height * .HeightRatio
    *** And resize each control contained in the form
    FOR EACH loControl IN .Controls
      .ResizeControls( loControl )
    ENDFOR
  ENDIF
ENDWITH
And this code goes in the form's custom ResizeControls() method:
Code:
LPARAMETERS toControl
LOCAL loPage, loControl, loColumn, lnColumnWidths[1], lnCol
IF PEMSTATUS( toControl, 'Width', 5 )
  toControl.Width = toControl.Width * Thisform.WidthRatio
ENDIF 
IF PEMSTATUS( toControl, 'Height', 5 )
  toControl.Height = toControl.Height * Thisform.HeightRatio
ENDIF
IF PEMSTATUS( toControl, 'Top', 5 )
  toControl.Top = toControl.Top * Thisform.HeightRatio
ENDIF
IF PEMSTATUS( toControl, 'Left', 5 )
  toControl.Left = toControl.Left * Thisform.WidthRatio
ENDIF
*** Now resize the font of the control, grid (naturally <g>) is a special case because
*** resizing the font resizes the column widths of the grid, so save and restore them
IF UPPER( ALLTRIM( toControl.Baseclass ) ) = 'GRID'
  DIMENSION lnColumnWidths[toControl.ColumnCount]
  FOR lnCol = 1 TO toControl.ColumnCount
    lnColumnWidths[lnCol] = toControl.Columns[lnCol].Width
  ENDFOR 
  toControl.Fontsize = INT( toControl.FontSize * Thisform.WidthRatio )
  FOR lnCol = 1 TO toControl.ColumnCount
    toControl.Columns[lnCol].Width = lnColumnWidths[lnCol]
  ENDFOR 
ELSE 
  IF PEMSTATUS( toControl, 'Fontsize', 5 )
    toControl.Fontsize = INT( toControl.FontSize * Thisform.WidthRatio )
  ENDIF 
ENDIF
DO CASE
  CASE UPPER( toControl.BaseClass ) = 'PAGEFRAME'
    FOR EACH loPage IN toControl.Pages
      Thisform.ResizeControls( loPage )
    ENDFOR
  CASE INLIST( UPPER( toControl.BaseClass ), 'PAGE', 'CONTAINER' )
    FOR EACH loControl IN toControl.Controls
      Thisform.ResizeControls( loControl )
    ENDFOR
  CASE UPPER( toControl.BaseClass ) = 'GRID'
    WITH toControl
      .RowHeight = .RowHeight * Thisform.HeightRatio
      .HeaderHeight = .HeaderHeight * Thisform.HeightRatio
      FOR EACH loColumn IN .Columns
        loColumn.Width = loColumn.Width * Thisform.WidthRatio
      ENDFOR
    ENDWITH 
  CASE INLIST( UPPER( toControl.BaseClass ), 'COMBOBOX', 'LISTBOX' )
    LOCAL lnCol, lnStart, lnEnd, lnLen, lcColumnWidths
    WITH toControl
      IF .ColumnCount < 2
        .ColumnWidths = ALLTRIM( STR( .Width ) )
      ELSE 
        lcColumnWidths = ''
        lnStart = 1
        FOR lnCol = 1 TO .ColumnCount - 1
          lnEnd = AT( ',', .ColumnWidths, lnCol ) 
          lnLen = lnEnd - lnStart 
          lcColumnWidths = lcColumnWidths + IIF( EMPTY( lcColumnWidths ), '', ',' ) + ALLTRIM( STR( VAL (SUBSTR( .ColumnWidths, lnStart, lnLen ) ) * Thisform.WidthRatio ) )
          lnStart = lnEnd + 1
        ENDFOR 
        lnLen = LEN( .ColumnWidths ) - lnStart + 1
        lcColumnWidths = lcColumnWidths + ',' + ALLTRIM( STR( VAL (SUBSTR( .ColumnWidths, lnStart, lnLen ) ) * Thisform.WidthRatio ) )
        .ColumnWidths = lcColumnWidths
      ENDIF
    ENDWITH 
  CASE INLIST( UPPER( ALLTRIM( toControl.BaseClass ) ), 'COMMANDGROUP', 'OPTIONGROUP' )
    LOCAL lnButton
    FOR lnButton = 1 TO toControl.ButtonCount
      ThisForm.resizeControls( toControl.Buttons[lnButton] )
    ENDFOR
  OTHERWISE
    *** There is no otherwise...I think we got all cases 
ENDCASE


Marcia G. Akins
 
Since the Anchor property was added to the Visual FoxPro visible classes, I've found it to be better than most other explored methods. Granted, anchors will sometimes require that you set a min size on the forms to keep the user from resizing so small that everything looks messed up. However, the effect produced by proper anchor use appears professional (scales quite well) and follows accepted Windows conventions.

boyd.gif

SweetPotato Software Website
My Blog
 
Thanks for all the suggestions.
I'll have my programmer try each of them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top