Window Resize-protection ( MIN / MAX ) ?

Window Resize-protection ( MIN / MAX ) ?

Postby ukoenig » Thu Mar 29, 2012 6:58 pm

Hello,

I want to protect a Window to be resized > given MAX and < given MIN.

I tested with :
oWnd:Move and oWnd:Resize, but a oversized Window is not adjusted to the given MIN and MAX

The start Window :

Image

The Image-background stopps Resizing, reaching Max-width or Max-Height
I still have to adjust the Window.

Image

Code: Select all  Expand view

...
...
nMDI := 2 // 1 = Modal
nWStyle := 4 // Image selected
nMINWidth := 300
nMINHeight := 300
nMAXWidth := 800
nMAXHeight := 500

IF nMDI = 1 // Modal
    DEFINE WINDOW oWnd TITLE "Window SizeProtection" FROM 100, 100 TO 400, 700  PIXEL MENU TMenu():New()  
ELSE
    DEFINE WINDOW oWnd TITLE "Window SizeProtection" FROM 100, 100 TO 400, 700 PIXEL MDI
ENDIF

SET MESSAGE OF oWnd TO "Windows Size Protection" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd ;
ON INIT  IIF( nMDI = 1, W_BACKGRD( oWnd, nWStyle, lWDirect, nWColorF, nWColorB, nWGradPos, cWBrush, cWImage ), ;        
                                     W_BACKGRD( oWnd:oWndClient, nWStyle, lWDirect, nWColorF, nWColorB, nWGradPos, cWBrush, cWImage ) ) ;      
ON RESIZE IIF( nMDI = 1, SIZE_PROT(oWnd), SIZE_PROT(oWnd:oWndClient) )

SET _3DLOOK OFF

RETURN ( NIL )

// --------------------

FUNCTION SIZE_PROT(oWnd)
LOCAL nWidth, nHeight

oWnd:CoorsUpdate()

nWidth := oWnd:nWidth
nHeight := oWnd:nHeight

W_BACKGRD( oWnd, nWStyle, lWDirect, nWColorF, nWColorB, nWGradPos, cWBrush, cWImage )

lProtect := .F.

IF nWidth > nMAXWidth
    nWidth := nMAXWidth
    lProtect := .T.
ENDIF
IF nWidth < nMINWidth
    nWidth := nMINWidth
    lProtect := .T.
ENDIF
IF nHeight > nMAXHeight
    nHeight := nMAXHeight
    lProtect := .T.
ENDIF
IF nHeight < nMINHeight
    nHeight := nMINHeight
    lProtect := .T.
ENDIF
IF lProtect = .T. // resize back to MIN or MAX  Height/Width
        oWnd:ReSize(nWidth, nHeight) // ?????????
//  oWnd:Move( , , nWidth, nHeight, .T. ) // ?????????
ENDIF

RETURN ( NIL )
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Window Resize-protection ( MIN / MAX ) ?

Postby Rick Lipkin » Thu Mar 29, 2012 7:23 pm

Uwe

I have been looking at how to re-zise a window and recalculate the controls based on the screen size.

Antonio gave me a suggestion in the forum and I have been working on a solution .. Take a look at the code and see if there is anything you can use .. note, this is a Mdi Child with an embedded dialog from resource.

Consider this code .. notice the ON INIT .. if you can work up a smart way of recalculating the controls ( my xbrowse works fine with this code ).. having trouble with the buttons and groups .. also note that trapping a frame pull and MAXIMIZE seem to result in the same value nSizeType.

Rick Lipkin

Code: Select all  Expand view

DEFINE WINDOW oWndChild            ;
       FROM 0,0 to 39,120          ;
       MDICHILD                    ;
       OF oWnd                     ;
       ICON oIco                   ;
       TITLE xTITLE

       DEFINE DIALOG oWork RESOURCE "WORKBROW" of oWndChild

       REDEFINE xBROWSE oLBX         ;
         RECORDSET oRsRepair         ;
         COLUMNS "RN",               ;
                 "ADDR1",            ;
                 "CITY",             ;
                 "PH",               ;
                 "RT",               ;
                 "STATUS",           ;
                 "TN",               ;
                 "PN",               ;
                 "MN",               ;
                 "MODEL",            ;
                 "SNUM"              ;
         COLSIZES 65,150,85,85,85,85,85,85,120,120,120  ;
         HEADERS "Repair Num",       ;
                 "Address",          ;
                 "City",             ;
                 "Phone",            ;
                 "Request Type",     ;
                 "Status",           ;
                 "Tracking Num",     ;
                 "Pref Tech",        ;
                 "Manufacturer",     ;
                 "Model Number",     ;
                 "Serial Number"     ;
         ID 172 of oWork             ;
         AUTOCOLS LINES AUTOSORT CELL

       ADD oCol TO oLbx AT 2 DATA {|x| x := _ChkCust(oRsRepair:Fields("lname"):Value,;
                   oRsRepair:Fields("fname"):Value)  } HEADER "Customer Name" size 150 ;
                             SORT "LNAME,FNAME"
       ADD oCol TO oLbx AT 5 DATA {|x| x := _ChkComp(oRsRepair:Fields("cc"):Value) };
                   HEADER "Instructions" size 150

       oLbx:lFooter   := .t.
       oCol           := oLbx:aCols[ 1 ]
       oCol:bFooter   := { || Ltrim( Str( oLbx:KeyNo() ) ) + " / " + LTrim( Str( oLbx:KeyCount() ) ) }
       oLbx:bChange   := { || oCol:RefreshFooter() }

       REDEFINE GROUP oGrp1 ID 197 OF oWork
                oGrp1:SetFont( oFontB )
       REDEFINE RADIO oRadSort VAR nRadSort ID 169, 170 OF oWork COLOR 0 ;
         ON CLICK _ChgSort( oWork,nRadSort,oRsRepair,oLbx )

       AEval( oRadSort:aItems, { | oRad | oRad:lTransparent := .T., ;
                          oRad:SetFont( oFontB )} ) //, oRad:nClrText := 128 } )

       REDEFINE BTNBMP oBtn1 ID 147 PROMPT "Create New Repair" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn2 ID 148 PROMPT "Call Customer" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn3 ID 149 PROMPT "Assign Order" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn4 ID 150 PROMPT "Edit Repair Order" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn5 ID 151 PROMPT "Scheduler" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn6 ID 152 PROMPT "Pickup Repair" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn7 ID 153 PROMPT "Add Repair Detail" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn8 ID 154 PROMPT "Advanced Payments" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn9 ID 155 PROMPT "Request Parts" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn10 ID 156 PROMPT "Call Backs" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn11 ID 157 PROMPT "Change Status" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")

       REDEFINE BTNBMP oBtn12 ID 158 PROMPT "Repair Bench" CENTER ;
                of oWork 2007 ;
                ACTION MsgInfo( "Under Construction")




       REDEFINE BTNBMP oBtn13 ID 140 PROMPT "&Close" CENTER ;
                of oWork 2007 ;
                ACTION oWndChild:End()

       ACTIVATE DIALOG oWork NOMODAL ;
                VALID(!GETKEYSTATE( 27 ))

ACTIVATE WINDOW oWndChild ;
   ON INIT ( oWork:Move( 0,0, oWndchild:nWidth, oWndchild:nHeight, .T. ), oLbx:SetFocus(), ;
           oWndChild:bResized := {|| _ReSizeUm( oWork,oWndChild,oLbx) }, ;
           oWork:refresh(.t.));
   VALID ( IIF( !lOK, ExitPgm(.T.,oWndChild,oRsRepair ), .F. ))

*  xbrowse( oWork:aControls[ 1 ] ),;
RETURN( NIL )

//------------------------------
Static Func _ReSizeUm( oWork,oWndChild,oBrw )


oWork:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. ) // frame and dialog link

// dialog controls
oWork:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oWork )  }

oBrw:SetFocus()

Return(nil)

//-------------------------
Static Func ResizeControls( nSizeType, nWidth, nHeight, oDlg )

if nSizeType = 0 //SIZE_MAXIMIZED

   xbrowse( oDlg:aControls[17] )

   oDlg:aControls[ 1  ]:SetSize( nWidth - 37, nHeight - 277 ) //txbrowse
   oDlg:aControls[ 3  ]:SetSize( nWidth - 37, nHeight - 570 ) // descending radio
   oDlg:aControls[ 4  ]:SetSize( nWidth - 37, nHeight - 570 ) // ascending radio

*   oDlg:aControls[ 17 ]:SetSize( nWidth - 37, nHeight - 800 ) // close button


endif

Return(nil)

//-------------------
Static Func _ChkCust( cLast,cFirst )

Local cName

If cFirst = " " .or. empty( cFirst)
   cName := substr(alltrim( cLast )+space(40),1,40)
Else
   cName := substr(alltrim( cLast )+", "+alltrim(cFirst)+space(40),1,40)
Endif

Return(cName)

//-------------------
Static Func _ChkComp( cComplaint )

Local cName

cName := cComplaint

Return(cName)
 


Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Window Resize-protection ( MIN / MAX ) ?

Postby ukoenig » Thu Mar 29, 2012 7:39 pm

Rick,

Thank You very much.

oWnd:SetSize( nWidth, nHeight, .t. )

works inside FUNCTION SIZE_PROT(oWnd).
Windows stopps resizing !!!! but only on a MODAL-window :cry:

The complete test :

Code: Select all  Expand view

#INCLUDE "FIVEWIN.CH"
#include "Image.ch"

STATIC oWnd, nMDI
STATIC nWStyle, nWColorF, nWColorB, nWGradPos, lWDirect, cWBrush, cWImage, nWLogo, cWLogo
STATIC nMINWidth, nMINHeight, nMAXWidth, nMAXHeight

FUNCTION MAIN()

nSWidth := GetSysMetrics(0)
nSHeight := GetSysMetrics(1)

c_path := GETCURDIR()

SET _3DLOOK ON
SetBalloon( .T. )

nWColorF := 16443068
nWColorB := 10899511
nWGradPos := 0.2
lWDirect := .T.
cWBrush := "BluStone.Bmp"
cWImage := "Fantasy2.Jpg"

nMDI := 1
nWStyle := 4
nMINWidth := 300
nMINHeight := 300
nMAXWidth := 800
nMAXHeight := 500

IF nMDI = 1 // Modal
    DEFINE WINDOW oWnd TITLE "Window SizeProtection" FROM 100, 100 TO 400, 500  PIXEL MENU TMenu():New()  
ELSE
    DEFINE WINDOW oWnd TITLE "Window SizeProtection" FROM 100, 100 TO 400, 500 PIXEL MDI
ENDIF

SET MESSAGE OF oWnd TO "Windows Size Protection" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd ;
ON INIT  IIF( nMDI = 1, W_BACKGRD( oWnd, nWStyle, lWDirect, nWColorF, nWColorB, nWGradPos, cWBrush, cWImage ), ;        
                                     W_BACKGRD( oWnd:oWndClient, nWStyle, lWDirect, nWColorF, nWColorB, nWGradPos, cWBrush, cWImage ) ) ;      
ON RESIZE IIF( nMDI = 1, SIZE_PROT(oWnd), SIZE_PROT(oWnd:oWndClient) )

SET _3DLOOK OFF

RETURN ( NIL )

// --------------------

FUNCTION SIZE_PROT(oWnd)
LOCAL nWidth, nHeight

oWnd:CoorsUpdate()
W_BACKGRD( oWnd, nWStyle, lWDirect, nWColorF, nWColorB, nWGradPos, cWBrush, cWImage )

lProtect := .F.
IF oWnd:nWidth > nMAXWidth
    nWidth := nMAXWidth
    lProtect := .T.
ENDIF
IF oWnd:nWidth < nMINWidth
    nWidth := nMINWidth
    lProtect := .T.
ENDIF
IF oWnd:nHeight > nMAXHeight
    nHeight := nMAXHeight
    lProtect := .T.
ENDIF
IF oWnd:nHeight < nMINHeight
    nHeight := nMINHeight
    lProtect := .T.
ENDIF
IF lProtect = .T.
//        oWnd:ReSize(nWidth, nHeight)
//  oWnd:Move( , , nWidth, nHeight, .T. )
        oWnd:SetSize( nWidth, nHeight, .t. )

ENDIF

RETURN ( NIL )

// --------  WINDOW - Background  ---------------

FUNCTION W_BACKGRD( oWnd, nStyle, lDirect, nColor1, nColor2, nMove, cBrush, cImage )
local oBrush

IF nStyle = 1 // COLOR
    DEFINE BRUSH oBrush COLOR nColor1
//  FillRect( oBitmap:hDC, aRect, oNewbrush:hBrush )
ENDIF
IF nStyle = 2 // GRADIENT
    aGrad := { { nMove, nColor1, nColor2 }, { nMove, nColor2, nColor1 } }
    hDC = CreateCompatibleDC( oWnd:GetDC() )
    hBmp = CreateCompatibleBitMap( oWnd:hDC, oWnd:nWidth, oWnd:nHeight )
    hBmpOld = SelectObject( hDC, hBmp )
    GradientFill( hDC, 0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, lDirect )
    DeleteObject( oWnd:oBrush:hBrush )
    oBrush := TBrush():New( ,,,, hBmp )
    oBrush:Cargo  := aGrad
    SelectObject( hDC, hBmpOld )
    ReleaseDC(hDC)
ENDIF
IF nStyle = 3 // BMP-BRUSH
    DEFINE BRUSH oBrush FILE c_path + "\Images\" + cBrush
ENDIF
IF nStyle = 4 // Image ADJUSTED
    DEFINE IMAGE oImage FILE c_path + "
\Images\" + cImage
    oBrush := TBrush():new( ,,,, ResizeBmp( oImage:hBitmap, oWnd:nWidth, oWnd:nHeight , .T. ) )
    oImage:End()
ENDIF

oWnd:SetBrush( oBrush )
oBrush:End()

RETURN( NIL )


I will carry on with testing

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Window Resize-protection ( MIN / MAX ) ?

Postby Enrico Maria Giordano » Thu Mar 29, 2012 7:50 pm

Did you already tried using aMinMax property?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Window Resize-protection ( MIN / MAX ) ?

Postby ukoenig » Thu Mar 29, 2012 9:58 pm

Enrico,

Thank You very much for the Info.
A great Function, I didn't noticed before : oWnd:aMinMaxInfo ...

That makes it short and easy :

Code: Select all  Expand view

#INCLUDE "FIVEWIN.CH"
#include "Image.ch"

STATIC oWnd, c_path

FUNCTION MAIN()
LOCAL nMDI, nWStyle, nWColorF, nWColorB, nWGradPos, lWDirect, cWBrush, cWImage, nWLogo, cWLogo
LOCAL nMINWidth, nMINHeight, nMAXWidth, nMAXHeight

c_path := GETCURDIR()

// Change for FWH-release < 12.1 in :
// c_path := CURDRIVE() + ":\" + GETCURDIR()

SET _3DLOOK ON
SetBalloon( .T. )

nWColorF := 16443068
nWColorB := 10899511
nWGradPos := 0.2
lWDirect := .T.
cWBrush := "BluStone.Bmp"
cWImage := "Fantasy2.Jpg"

nMDI := 2
nWStyle := 4
nMINWidth := 300
nMINHeight := 300
nMAXWidth := 800
nMAXHeight := 500

IF nMDI = 1 // Modal
    DEFINE WINDOW oWnd TITLE "Window SizeProtection" FROM 100, 100 TO 400, 500  PIXEL MENU TMenu():New()  
ELSE
    DEFINE WINDOW oWnd TITLE "Window SizeProtection" FROM 100, 100 TO 400, 500 PIXEL MDI
ENDIF

oWnd:aMinMaxInfo = { 600, 400,;  // xMaxSize,      yMaxSize
                   50,  50,;  // xMaxPosition,  yMaxPosition
                   nMINWidth,  nMINHeight,;  // xMinTrackSize, yMinTrackSize
                   nMAXWidth, nMAXHeight }  // xMaxTrackSize, yMaxTrackSize 

SET MESSAGE OF oWnd TO "Windows Size Protection" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd ;
ON RESIZE  IIF( nMDI = 1, W_BACKGRD( oWnd, nWStyle, lWDirect, nWColorF, ;
                       nWColorB, nWGradPos, cWBrush, cWImage ), ;        
                       W_BACKGRD( oWnd:oWndClient, nWStyle, lWDirect, ;
                       nWColorF, nWColorB, nWGradPos, cWBrush, cWImage ) )       

SET _3DLOOK OFF

RETURN ( NIL )

// --------  WINDOW - Background  ---------------

FUNCTION W_BACKGRD( oWnd, nStyle, lDirect, nColor1, nColor2, nMove, cBrush, cImage )
local oBrush

IF nStyle = 1 // COLOR
    DEFINE BRUSH oBrush COLOR nColor1
//  FillRect( oBitmap:hDC, aRect, oNewbrush:hBrush )
ENDIF
IF nStyle = 2 // GRADIENT
    aGrad := { { nMove, nColor1, nColor2 }, { nMove, nColor2, nColor1 } }
    hDC = CreateCompatibleDC( oWnd:GetDC() )
    hBmp = CreateCompatibleBitMap( oWnd:hDC, oWnd:nWidth, oWnd:nHeight )
    hBmpOld = SelectObject( hDC, hBmp )
    GradientFill( hDC, 0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, lDirect )
    DeleteObject( oWnd:oBrush:hBrush )
    oBrush := TBrush():New( ,,,, hBmp )
    oBrush:Cargo  := aGrad
    SelectObject( hDC, hBmpOld )
    ReleaseDC(hDC)
ENDIF
IF nStyle = 3 // BMP-BRUSH
    DEFINE BRUSH oBrush FILE c_path + "\Images\" + cBrush
ENDIF
IF nStyle = 4 // Image ADJUSTED
    DEFINE IMAGE oImage FILE c_path + "
\Images\" + cImage
    oBrush := TBrush():new( ,,,, ResizeBmp( oImage:hBitmap, oWnd:nWidth, oWnd:nHeight , .T. ) )
    oImage:End()
ENDIF

oWnd:SetBrush( oBrush )
oBrush:End()

RETURN( NIL )


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests