CONTROLS IN A WINDOW

Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Resizing with fonts

Post by Frank Demont »

Silvio,

Now you have a working sample from resizing also the fonts

Fonts are only resized when the vertical factor exceeds 10 , 20 , 30 .. % from 1 . This can be changed in the increment ( 10 or -10 ) from currentheight

Frank

Code: Select all

FUNCTION MAIN() 
***************
LOCAL oWnd , oFont
LOCAL cVar := PAD("TEST ON RESIZE WITH FONT",35)
		
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, -24
DEFINE WINDOW oWnd 

@ 10, 10 GET cVar OF oWnd SIZE 400,24 PIXEL FONT oFont
@ 60, 60 BUTTON "&Close" SIZE 100,24 PIXEL FONT oFont; 
         ACTION oWnd:End() 

ACTIVATE WINDOW oWnd; 
    ON RESIZE RESIZECONTROLS(nSizeType,nWidth,nHeight,oWnd )

oFont:end()
		
RETURN NIL 
************************************************************************************************************
STATIC FUNCTION RESIZECONTROLS(nSizeType,nWidth,nHeight, oWnd ) 
***************************************************************
STATIC aCoordinates := {} , FV  
STATIC StartWidth , StartHeight 
STATIC CurrentHeight 

LOCAL i , aHlp[5] ,  F := Hash() 
LOCAL oCtl 
LOCAL NewFontH  , oFont , cFaceName , lNewFont := .F.
		
IF EMPTY( aCoordinates ) 
  FOR EACH oCtl IN oWnd:aControls 
    AADD(aCoordinates , Array(5)) 
    i := Hb_EnumIndex()          
    aCoordinates[i,1] := oCtl:nTop 
    aCoordinates[i,2] := oCtl:nLeft 
    aCoordinates[i,3] := oCtl:nWidth() 
    aCoordinates[i,4] := oCtl:nHeight() 
    aCoordinates[i,5] := oCtl:oFont:nHeight 
  NEXT 
  StartWidth  := oWnd:nWidth() 
  StartHeight := oWnd:nHeight()
  FV := 1
  lFont := .F. 
  CurrentHeight := 0
ENDIF 
F["H"] := oWnd:nWidth()/StartWidth       // horizontal
F["V"] := oWnd:nHeight()/StartHeight     // vertical
IF F["V"] <> FV
  IF ABS(ROUND(( F["V"] - 1 )*100 ,2 ) - CurrentHeight) > 10
    lNewFont := .T. 
    IF F["V"] > FV
      CurrentHeight += 10
    ELSEIF F["V"] < FV 
      CurrentHeight -= 10
    END
  ENDIF
ENDIF
FOR EACH oCtl IN oWnd:aControls 
  i := Hb_EnumIndex() 
  aHlp[1] := aCoordinates[i,1]*F["V"]              // nTop
  aHlp[2] := aCoordinates[i,2]*F["H"]              // nLeft
  aHlp[3] := aCoordinates[i,3]*F["H"]              // nWidth
  aHlp[4] := aCoordinates[i,4]*F["V"]              // nHeight
  oCtl:Move( aHlp[1] , aHlp[2] , aHlp[3] , aHlp[4] , .T. )
  IF lNewFont 
    NewFontH := ROUND(aCoordinates[i,5]*F["V"],0)
    oFont := oCtl:oFont
    cFaceName := oFont:cFaceName
    oFont:end()
    DEFINE FONT oFont NAME cFaceName SIZE 0, -NewFontH
    oCtl:SetFont(ofont)
    oCtl:refresh()
  END
NEXT 
FV := F["V"]
RETURN 
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

THANK
I try it for 1 min 41 secs
I open and close the window all run ok
then it made an error at RESIZECONTROLS(313)

this is log file

Code: Select all

Application
===========
   Path and name: C:\work\PRG\cassa\bar.Exe (32 bits)
   Size:   882,688 bytes
   Time from start: 0 hours 1 mins 41 secs 
   Error occurred at: 08/19/06, 15:52:54
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = A   { ... }
     [   2] = N   81

Stack Calls
===========
   Called from:  => RESIZECONTROLS(313)
   Called from: bar.prg => (b)CASSA(265)
   Called from: WINDOW.PRG => TWINDOW:RESIZE(0)
   Called from: WINDOW.PRG => TWINDOW:HANDLEEVENT(0)
   Called from: WINDOW.PRG => _FWH(0)
   Called from:  => WINRUN(0)
   Called from: WINDOW.PRG => TWINDOW:ACTIVATE(0)
   Called from: bar.prg => CASSA(265)
Best Regards, Saludos

Falconi Silvio
Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Post by Frank Demont »

Silvio

1) When you run mine example , run it ok ?

2) I suppose that you try it in your aplication , but i can't recognize the linenumber

Called from: => RESIZECONTROLS(313)
Which line in resizecontrol ?

Also the variables in use can tell something , espacialy from resizecontrols

Is len(acoordinates) < LEN(oWnd:acontrols) ?

IF so you could :

Code: Select all

FOR EACH oCtl IN oWnd:aControls 
  i := Hb_EnumIndex()
  IF i <= LEN(aCoordinates) 
    aHlp[1] := aCoordinates[i,1]*F["V"]              // nTop
    aHlp[2] := aCoordinates[i,2]*F["H"]              // nLeft
    aHlp[3] := aCoordinates[i,3]*F["H"]              // nWidth
    aHlp[4] := aCoordinates[i,4]*F["V"]              // nHeight
    .........
  endif
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

yes your sample run ok

the line 313 at mine application is
aHlp[1] := aCoordinates[i,1]*F["V"] // nTop
Best Regards, Saludos

Falconi Silvio
Post Reply