C The code below attempts to fit as many rows and columns
C as possible into the client area of the current frame
C window without scroll bars.  The QuickWin sizing routines
C are somewhat inconsistent in what they do.  Because
C of backward compatibility problems they probably won't
C be changed. Using just the QuickWin sizing routines
C the child window would be off by 1 or 2 lines.

C The solution required the use of a WIN API to get
C unadjusted size information, and likewise for the
C status bar.

C Please find below sample code which uses GetWindowRect to
C get the size information, and GetMenuState to account
C for the status bar.

      PROGRAM TESTWIN
      USE DFLIB 
      USE DFWIN
c      IMPLICIT NONE
       logical*4 checkstatusbar, result
       external  checkstatusbar

	character(len=1) a
	integer n
c
	TYPE (QWINFO) winfo
	TYPE (windowconfig) wc
	LOGICAL(4)              status
	INTEGER(4)              ichk, ichk1, ichk2, ires
	
	TYPE (T_RECT)           rect
	INTEGER                 windno
	CHARACTER               windname*20


	INTEGER iresult,ixt,iyt
	LOGICAL istats

	windno = 6
	windname = 'TEST WINDOW'C

1       CONTINUE

	OPEN (windno,FILE='USER')

	write (windno,*) 'Change size or maximize frame window now.'
	write (windno,*) 'Remove or replace status bar now'
	write(windno,1000,ADVANCE='NO')
1000    format(' Continue? (Y/N)')
	read (windno,*) a
	if(a.ne.'Y'.and.a.ne.'y') stop

	ires = GetWindowRect (getHwndQQ(QWIN$FRAMEWINDOW),rect)

C Some of the empirical constants below can probably be computed from
C GetSystemMetrics for the size of the borders, title bar, and
C other screen components.  For example,
C statusbarheight = GetSystemMetrics(SM_CYCAPTION)
C as coded in the QuickWin sources. This is 19 on my machine and
C I think the other five pixels come from the top and bottom borders
C plus an additionel 1 pixel I added. They can be adjusted slightly
C for the desired appearance of the screen.
C

	wc.numxpixels  = rect.right-rect.left-16
	wc.numypixels  = rect.bottom-rect.top-96
	if(.not. checkstatusbar()) wc.numypixels = wc.numypixels + 24
	wc.numtextcols = - 1
	wc.numtextrows = -1
	wc.numcolors   = 256
	wc.fontsize = - 1
	wc.title = windname
	status = SETWINDOWCONFIG(wc)
	if (.NOT.status) status = SETWINDOWCONFIG(wc)
	ixt =wc.fontsize/65536  
	iyt=wc.fontsize-ixt*65536

	ncols  = min (wc.numtextcols,wc.numxpixels/ixt)
	nrows  = min (wc.numtextrows,wc.numypixels/iyt)
	nxpix = ncols * ixt
	nypix = nrows * iyt
       
	winfo.X=0
	winfo.Y=0
	winfo.H=nrows
	winfo.W=ncols
	winfo.TYPE=QWIN$SET
	ires=SETWSIZEQQ(windno,winfo)


100     continue
	do n=1,100
		write(windno,1010,ADVANCE='NO') n
1010            format(/,1x,'Text line',i4,' of 100')
	end do
C
	write(windno,1020,ADVANCE='NO')
1020    format(' Start again (Y/N)?')
	read(windno,*) a
	if(a.eq.'Y'.or.a.eq.'y') goto 1
      STOP
      
      END


      logical*4 function checkstatusbar()
      use msflib
      use msfwin
      implicit none
      ! menu values
      integer, parameter :: IDM_FILE_EXIT           =      1000
      integer, parameter :: IDM_EDIT_SELECTTEXT     =      1001
      integer, parameter :: IDM_EDIT_SELECTGRAPHICS =      1002
      integer, parameter :: IDM_EDIT_SELECTALL      =      1003
      integer, parameter :: IDM_EDIT_COPY           =      1004
      integer, parameter :: IDM_VIEW_SIZETOFIT      =      1006
      integer, parameter :: IDM_VIEW_FULLSCRN       =      1007
      integer, parameter :: IDM_STATE_PAUSE         =      1008
      integer, parameter :: IDM_STATE_RESUME        =      1009
      integer, parameter :: IDM_WINDOW_CASCADE      =      1010
      integer, parameter :: IDM_WINDOW_TILE         =      1011
      integer, parameter :: IDM_WINDOW_ARRANGE      =      1012
      integer, parameter :: IDM_WINDOW_STATUS       =      1015
      integer, parameter :: IDM_HELP_INDEX          =      1016
      integer, parameter :: IDM_HELP_USING          =      1017
      integer, parameter :: IDM_HELP_ABOUT          =      1018

      integer, parameter :: IDM_FILE_PRINT          =      1019
      integer, parameter :: IDM_FILE_SAVE           =      1020
      integer, parameter :: IDM_EDIT_TXTPASTE       =      1021
      integer, parameter :: IDM_WINDOW_CLEARPASTE   =      1022
      integer, parameter :: IDM_WINDOW_IOPEND       =      1023
      integer, parameter :: IDM_SHOW_CARET          =      1024
      integer, parameter :: IDM_SHOW_CARET1         =      1025
      integer*4 result, hmenu

	hmenu = getmenu(GETHWNDQQ(QWIN$FRAMEWINDOW))   
	result =  GetMenuState(hmenu, IDM_WINDOW_STATUS, MF_BYCOMMAND)
C        write(*,*) 'Result = ', result, ' hmenu = ', hmenu, MF_CHECKED
	checkstatusbar =  .FALSE.
	if(iand(result, MF_CHECKED) .ne. 0) checkstatusbar = .TRUE.

      end function checkstatusbar



       
