FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Move controls as window size
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Move controls as window size
Posted: Fri Feb 13, 2015 05:34 PM
Hi all,
I'm looking for the best way to move the controls in this folder (those in the red rectangule) automatically down based on the window size.
Which is in your opinion the best way to do it ? Instead of move any control, could it be possibile to put over the folder resource a large control (a title for example) and the put those controls over the title in order I can move all of them moving just the control under ?

Any ideas appreciated. thank you

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Move controls as window size
Posted: Fri Feb 13, 2015 08:58 PM
I may have missed something, but it sounds like something I do often.

Here is some code to illustrate:

Code (fw): Select all Collapse
   LOCAL oSelf := SELF 
...
   ACTIVATE WINDOW ::oWnd ;//MAXIMIZED;
           ON INIT ...
         ON RESIZE oSelf:SetSize( nSizeType, nWidth, nHeight ) ;
             VALID oSelf:End()
...

METHOD SetSize( nType, nWidth, nHeight ) CLASS MpCal
local nCntrl := aScan( ::oWnd:aControls, { |e| upper( e:ClassName() ) $ "TTOOLBAR,TREBAR,TBAR,TRIBBONBAR" } )
LOCAL aClient := GetClientRect ( ::oWnd:hWnd ), i

    if nWidth != nil

      if nCntrl > 0 .and. nHeight != Nil ; nHeight -= ::oWnd:aControls[ nCntrl ]:nHeight   ;endif

      ::oGridViewDlg:SetSize( aClient[4] - 1, nHeight, .T. )
      ::oGridViewDlg:Move( 0, 0 )
      ::oGridViewDlg:Show()
      ::oGridViewDlg:Refresh()

      IF ::oGridView == NIL
         RETURN NIL
      ENDIF

      ::oGridView:SetSize( ::oGridViewDlg:nWidth, ::oGridViewDlg:nHeight , .T. )
      ::oGridView:Move( 0, 0 )
      ::oGridView:SetFocus()


RETURN NIL


Perhaps that helps.

Reinaldo.
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Move controls as window size
Posted: Sat Feb 14, 2015 10:02 AM

Ok, I understand. I will try, thank you.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Move controls as window size
Posted: Sat Feb 14, 2015 10:20 AM

Marco,

When there are only two controls, you can use oWnd:oClient and oWnd:oBottom (oWnd is any window or dialog. A folder page is a dialog).

But as you have several controls, you can do as Reinaldo has explained you or you can use FWH layouts.

Please search in FWH\samples for "layout" and check those examples :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Move controls as window size
Posted: Sat Feb 14, 2015 03:43 PM

Reinaldo

I have been looking for such an algorithm myself .. unfortunately I have had to find the controls manually and resize them manually.

I am not a method kinda person .. It appears your code is for non-mdi windows .. Will your code work with MDI as well ?

Rick Lipkin

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Move controls as window size
Posted: Sat Feb 14, 2015 04:13 PM
Hey Rick!

Funny you asked. Just recently I had to adapt it for an MDI app. It would still work the same, though. To keep things easier, I make each MDICHILD window object a property of the class. In this manner I can address it as ::oWndChild.... Tell you what, here's some actual code. I'm not "happy" with this code as I only wrote it as simple as possible to test and prove how controls can be manipulated in placement and size inside a mdichild window and that it'd work.

Code (fw): Select all Collapse
//---------------------------------------------------//
//
METHOD SetSize( nType, nWidth, nHeight ) CLASS MpCal
local nCntrl := aScan( ::oWnd:aControls, { |e| upper( e:ClassName() ) $ "TTOOLBAR,TREBAR,TBAR,TRIBBONBAR" } )
LOCAL aClient := GetClientRect ( ::oWnd:hWnd ), i

    if nWidth != nil

      if nCntrl > 0 .and. nHeight != Nil ; nHeight -= ::oWnd:aControls[ nCntrl ]:nHeight   ;endif

      IF ::oRibbon:nOption == 1
         ::oPanelExplorer:Move( , , , nHeight )
         ::oPanelCalex:Move( , , nWidth - ::oPanelExplorer:nRight, nHeight )
         
         RETURN NIL 

      ENDIF 
      
      ::oWndChild:SetSize( aClient[ 4 ]-1, nHeight, .T. )
      ::oWndChild:Move( 0, 0 )

      IF ::oRibbon:nOption == 2
      
         ::oGridViewDlg:SetSize( aClient[4] - 1, nHeight, .T. )
         ::oGridViewDlg:Move( 0, 0 )
         ::oGridViewDlg:Show()
         ::oGridViewDlg:Refresh()

         IF ::oGridView == NIL ;            RETURN NIL   ;         ENDIF

         ::oGridView:SetSize( ::oGridViewDlg:nWidth, ::oGridViewDlg:nHeight , .T. ) 
         ::oGridView:Move( 0, 0 )
         ::oGridView:SetFocus()

      ENDIF

      IF ::oRibbon:nOption == 3 ... ;ENDIF

    ENDIF 

RETURN NIL


Hope that helps.

Reinaldo.
Reinaldo.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Move controls as window size
Posted: Sun Feb 15, 2015 06:17 AM

Use FWH layouts! :-)

They work really great

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Move controls as window size
Posted: Mon Feb 16, 2015 01:26 AM
Antonio Linares wrote:Use FWH layouts! :-)

They work really great

Antonio, hay sample o pueden colocar el uso de la clase Layouts.? gracias, saludos...
Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Move controls as window size
Posted: Mon Feb 16, 2015 02:15 AM
joseluisysturiz wrote:Antonio, hay sample o pueden colocar el uso de la clase Layouts.? gracias, saludos...


http://forums.fivetechsupport.com/viewtopic.php?p=151916#p151916
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Move controls as window size
Posted: Mon Feb 16, 2015 04:12 AM

Gracias Daniel, revisando, saludos... :shock:

Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 555
Joined: Wed Jul 31, 2013 01:14 PM
Re: Move controls as window size
Posted: Mon Feb 16, 2015 01:20 PM

Hello, tLayout wotk from resources?

Thank you very much.

Saludos
Ruben Dario Fernandez

Dario Fernandez

FWH 2501, Harbour, MVS2022 Community, MySql & MariaDB, Dbf/Cdx VSCode.

Maldonado - Uruguay
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Move controls as window size
Posted: Mon Feb 16, 2015 02:43 PM
D.Fernandez wrote:Hello, tLayout wotk from resources?

Thank you very much.

Saludos
Ruben Dario Fernandez


Hello, not work with resources
Posts: 38
Joined: Tue Mar 04, 2008 03:44 PM
Re: Move controls as window size
Posted: Tue Feb 17, 2015 10:22 AM
Any,

I use resources and I tried. Modal windows that go well.
Please see source under someone and develop.

http://www.milkweb.co.kr/DlgResize.zip

Code (fw): Select all Collapse
// RESOURCE SCRIPT generated by "Pelles C for Windows, version 8.00".

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>

// LANGUAGE LANG_KOREAN,SUBLANG_KOREAN

D_BROWSE DIALOGEX FIXED IMPURE 97, 119, 347, 245
STYLE WS_POPUP|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_VISIBLE
EXSTYLE 0x00000100
CAPTION "Dialog Resize"
FONT 9, "MS Sans Serif", 0, 0, 0
{
  CONTROL "", 401, "SysTabControl32", 0x00000000, 200, 56, 140, 84
  CONTROL "undefined static text", -1, "Static", WS_GROUP, 9, 12, 104, 8
  CONTROL "undefined group", -1, "Button", BS_GROUPBOX|WS_DISABLED, 4, 36, 340, 180
  CONTROL "", 101, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 140, 8, 200, 14
  CONTROL "save", 201, "Button", WS_TABSTOP, 208, 220, 64, 20
  CONTROL "cancel", 202, "Button", WS_TABSTOP, 276, 220, 64, 20
  CONTROL "Custom control", 301, "TxBrowse", WS_DISABLED|0x00100000, 12, 56, 180, 84
  CONTROL "Custom control", 302, "TxBrowse", WS_DISABLED|0x00100000, 12, 144, 328, 64
}


Code (fw): Select all Collapse
#include "fivewin.ch"
#include "xbrowse.ch"

/*
  2012.07.08  Charles Kwon made to my suggestion.

  ToDo : 1. Do not act in MDI yet.
         2. When define each control, I wish to can give factor of 4 directions  .or. obj:bFacter(||....)
*/

Static oInfo

FUNCTION Main()

   LOCAL oDlg
   LOCAL oBrw
   LOCAL oBrw2
   LOCAL oFld
   LOCAL oBtn
   LOCAL bSetup := { | oObj, cTitle, nAt, nID, cClsName, oSelf | SetupDlg( oObj, cTitle, nAt, nID, cClsName, oSelf ) }

   SET RESOURCES TO "DlgResiz.dll"

   USE customer NEW   // FiveWin samples

   DEFINE DIALOG oDlg RESOURCE "D_BROWSE"

      oDlg:bStart   := { | | oInfo := TDlgResize():New( oDlg, bSetup ) }
      oDlg:bResized := { | nSizeType, nWidth, nHeight | oInfo:Resize( nWidth, nHeight ) }

      REDEFINE XBROWSE oBrw  ID 301 OF oDlg  AUTOCOLS

      REDEFINE XBROWSE oBrw2 ID 302 OF oDlg  AUTOCOLS

      REDEFINE FOLDER  oFld  ID 401  OF oDlg  PROMPT "&One", "&Two", "&Three"

      REDEFINE BUTTON  oBtn  ID 202  ACTION oDlg:End()

   ACTIVATE DIALOG oDlg

   Set Resources to
   customer->( dbCloseArea() )

RETURN NIL


/*
   Dlg Controls Setup
*/
FUNCTION SetupDlg( oObj, cTitle, nAt, nID, cClsName, oSelf )
   LOCAL oFindObj

   oObj:nTopStyle    := 1        // 1.NONE    2.Upper relative position 3.Follow to Under Control OR Dialog Bottom
   oObj:nLeftStyle   := 1        // 1.NONE    2.Left relative position  3.Follow to Right Control OR Dialog Right
   oObj:nRightStyle  := 1        // 1.NONE    2.Dialog Width           * Appointment Control
   oObj:nBottomStyle := 1        // 1.NONE    2.Dialog Bottom          * Appointment Control

   DO CASE
      CASE nAt == 2                  // undefind static text. Resource Order 2
           oObj:nTopStyle    := 1
           oObj:nLeftStyle   := 1
           oObj:nRightStyle  := 1
           oObj:nBottomStyle := 1

      CASE nAt == 3                  // undefined group   . Resource Order 3
           oObj:nTopStyle    := 1
           oObj:nLeftStyle   := 1
           oObj:nRightStyle  := oSelf:FindByID( 401 )
           oObj:nBottomStyle := oSelf:FindByID( 202 )

      CASE nID == 101               // get                 . Resource Order 4
           oObj:nTopStyle    := 1
           oObj:nLeftStyle   := 3   // Follow to Dialog Right
           oObj:nRightStyle  := 1
           oObj:nBottomStyle := 1

      CASE nId == 201               // save               . Resource Order 5
           oObj:nTopStyle    := 3
           oObj:nLeftStyle   := 3
           oObj:nRightStyle  := 1
           oObj:nBottomStyle := 1

      CASE nID == 202               // cancel            . Resource Order 6
           oObj:nTopStyle    := 3
           oObj:nLeftStyle   := 3
           oObj:nRightStyle  := 1
           oObj:nBottomStyle := 1

      CASE nID == 401             //                    . Resource Order 1
           oObj:nTopStyle    := 1
           oObj:nLeftStyle   := 3
           oObj:nRightStyle  := 1
           oObj:nBottomStyle := 1

      CASE nID == 301              //                    . Resource Order 7
           oObj:nTopStyle    := 1
           oObj:nLeftStyle   := 1
           oObj:nRightStyle  := oSelf:FindByID( 401 )    // Appointment Control
           oObj:nBottomStyle := oSelf:FindByID( 302 )    // or oSelf:aChilds[5]

      CASE nID == 302             //                    . Resource Order 8
           oObj:nTopStyle    := 2
           oObj:nLeftStyle   := 1  // 3
           oObj:nRightStyle  := oSelf:FindByID( 401 )    // or oSelf:aChilds[6]
           oObj:nBottomStyle := oSelf:FindByID( 202 )    // or oSelf:aChilds[6]

   ENDCASE


RETURN NIL


//
//
CLASS TDlgResize

   DATA oDlg
   DATA aChilds AS ARRAY INIT {}

   DATA nTop
   DATA nLeft
   DATA nBottom
   DATA nRight
   DATA nHeight
   DATA nWidth
   DATA bSetup



   METHOD New( oDlg ) CONSTRUCTOR
   METHOD GetChilds()
   METHOD AddChild( hWnd )
   METHOD Resize( nWidth, nHeight )
   METHOD FindByID( nID )

ENDCLASS

METHOD New( oDlg, bSetup ) CLASS TDlgResize
   LOCAL aRect := {}
   LOCAL oChild
   LOCAL nI

   ::oDlg := oDlg

   //aRect := GetCoors( oDlg:hWnd )
   aRect := GetWndRect( oDlg:hWnd )

   ::nTop     :=   aRect[ 1 ]
   ::nLeft    :=   aRect[ 2 ]
   ::nBottom  :=   aRect[ 3 ]
   ::nRight   :=   aRect[ 4 ]

   ::nHeight  :=   aRect[ 3 ] - aRect[ 1 ] + 1
   ::nWidth   :=   aRect[ 4 ] - aRect[ 2 ] + 1

   ::bSetup   :=   bSetup
   ::GetChilds()

    IF ::bSetup <> NIL
       FOR nI := 1 TO LEN( ::aChilds )
           oChild := ::aChilds[ nI ]
           EVAL ( ::bSetup, oChild, GetWindowText( oChild:hWnd ), nI, oChild:nID ,  oChild:cClsName,  Self )
       NEXT
    ENDIF

RETURN Self

//
METHOD GetChilds() CLASS TDlgResize

   ::aChilds := {}
   EnumChildWindows( ::oDlg:hWnd , { | hWnd | ::AddChild( hWnd ) } )

return NIL

//
METHOD AddChild( hWnd ) CLASS TDlgResize
    LOCAL oChild

    oChild := TDlgResizeItem():New( hWnd, Self )

    AADD ( ::aChilds, oChild )

return nil

//
METHOD Resize( nWidth, nHeight ) CLASS TDlgResize
    local ni

    AEVAL ( ::aChilds, {|o|o:lResized := .f. } )
    AEVAL ( ::aChilds, {|o|o:Resize( nWidth, nHeight ) } )
    ::oDlg:Refresh(.f.)

RETURN NIL

//
METHOD FindByID( nID )  CLASS TDlgResize
   LOCAL nI

   FOR nI := 1 TO LEN( ::aChilds )
       IF ::aChilds[nI]:nID == nID
          RETURN ::aChilds[nI]
       ENDIF
   NEXT

   MsgInfo( "ID "+ALLTRIM(STR(nId))+" not found. So return 1")

RETURN 1


#pragma BEGINDUMP
#include <Windows.h>
#include <hbapi.h>
#include <hbapiitm.h>


static PHB_ITEM pCodeBlock = NULL, pParam = NULL;

static BOOL CALLBACK EnumChildProc( HWND hWnd, LPARAM lParam )
{
   PHB_ITEM pNumber = hb_itemPutNL( NULL, ( LONG ) hWnd );

   if( lParam )
      hb_evalBlock( pCodeBlock, pNumber, lParam, NULL );
   else
      hb_evalBlock1( pCodeBlock, pNumber );

   hb_itemRelease( pNumber );

   return TRUE;
}

HB_FUNC( ENUMCHILDWINDOWS )
{
   pCodeBlock = hb_param( 2, HB_IT_BLOCK );
   pParam = hb_param( 3, HB_IT_NUMERIC );
   hb_retl( EnumChildWindows( ( HWND ) hb_parnl( 1 ), EnumChildProc, hb_parnl( 2 ) ) );
   pCodeBlock = NULL;
   pParam = NULL;
}

HB_FUNC( GETDLGCTRLID )
{
   hb_retni( GetDlgCtrlID( ( HWND ) hb_parnl( 1 ) ) );
}

#pragma ENDDUMP


//
CLASS TDlgResizeItem

   DATA oParent
   DATA oDlg
   DATA hWnd

   DATA nTop
   DATA nLeft
   DATA nBottom
   DATA nRight
   DATA nHeight
   DATA nWidth

   DATA nTopStyle
   DATA nLeftStyle
   DATA nRightStyle
   DATA nBottomStyle

   DATA aRect2
   DATA lResized   AS LOGICAL INIT .F.

   DATA nID
   DATA cClsName

   METHOD New() CONSTRUCTOR
   METHOD Resize ( nWidth, nHeight )

ENDCLASS

//
METHOD New( hWnd, oParent ) CLASS TDlgResizeItem
   LOCAL aRect  := {}
   LOCAL aRect2 := {}

   ::oParent := oParent
   ::oDlg    := oParent:oDlg
   ::hWnd    := hWnd

   aRect     := GetCoors( ::hWnd )       // Absolute coordinate
   ::aRect2  := GetWndRect( ::hWnd )

   ::nId      := GetDlgCtrlID( ::hWnd )
   ::cClsName := GetClassName( ::hWnd )


   ::nTop     :=   aRect[ 1 ]
   ::nLeft    :=   aRect[ 2 ]
   ::nBottom  :=   aRect[ 3 ]
   ::nRight   :=   aRect[ 4 ]

   ::nHeight  :=   aRect[ 3 ] - aRect[ 1 ] + 1
   ::nWidth   :=   aRect[ 4 ] - aRect[ 2 ] + 1

RETURN Self

//
METHOD Resize ( nWidth, nHeight ) CLASS TDlgResizeItem
   LOCAL nTop
   LOCAL nLeft
   LOCAL nHeight2
   LOCAL nWidth2
   LOCAL oObj
   LOCAL aRect
   LOCAL lNoChangeHeight := .f.
   LOCAL lNoChangeWidth  := .f.

   IF ::lResized
      RETURN NIL
   ENDIF

   ::lResized := .T.

   IF nHeight >= ::oParent:nHeight
      nTop     := int ( ( nHeight  *  ::nTop     / ::oParent:nHeight )  )       // top
      nHeight2 := int ( ( nHeight  *  ::nHeight  / ::oParent:nHeight )  )       // height
   ELSE
      nTop     := ::nTop
      nHeight2 := ::nHeight
      lNoChangeHeight := .t.
   ENDIF

   IF nWidth >= ::oParent:nWidth
      nLeft   := int ( ( nWidth  *   ::nLeft  / ::oParent:nWidth  )  )
      nWidth2 := int ( ( nWidth  *   ::nWidth / ::oParent:nWidth  )  )
   ELSE
      nLeft  := ::nLeft
      nWidth2 := ::nWidth
      lNoChangeWidth  := .t.
   ENDIF

   /*

   IF lNoChangeHeight .or. lNoChangeWidth
      MoveWindow( ::hWnd, ::nTop, ::nLeft, ::nWidth, ::nHeight, .t. )
      RETURN NIL
   ENDIF
   */


   DO CASE
      CASE ::nTopStyle == 1
           nTop := ::nTop
      CASE ::nTopStyle == 3
           nTop := nHeight - ::nHeight - ( ::oParent:nBottom - ::aRect2[3] ) + 1
   ENDCASE


   DO CASE
      CASE ::nLeftStyle == 1
           nLeft := ::nLeft

      CASE ::nLeftStyle == 3
            nLeft := nWidth - ::nWidth - ( ::oParent:nRight - ::aRect2[4] ) + 1

   ENDCASE

   IF VALTYPE ( ::nRightStyle ) == "N"
      DO CASE
         CASE ::nRightStyle == 1
              nWidth2 := ::nWidth
      ENDCASE
   ELSE
      oObj := ::nRightStyle
      oObj:Resize( nWidth, nHeight )
      aRect := GetCoors( oObj:hWnd )
      nWidth2 := aRect[2] - nLeft - ( oObj:aRect2[2] - ::aRect2[4] )
   ENDIF

   IF VALTYPE( ::nBottomStyle ) == "N"
      DO CASE
         CASE ::nBottomStyle == 1
              nHeight2 := ::nHeight
      ENDCASE
   ELSE
      oObj := ::nBottomStyle
      oObj:Resize( nWidth, nHeight )
      aRect := GetCoors( oObj:hWnd )
      nHeight2 := aRect[1]  - nTop - ( oObj:aRect2[1] - ::aRect2[3] )
   ENDIF

   MoveWindow( ::hWnd, nTop, nLeft, nWidth2, nHeight2, .t. )

RETURN NIL
Regards,

Moon

FWH 16.11 | xHarbour | Harbour | BCC72 | DBF | ADS | MySQL | DrLib
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Move controls as window size
Posted: Thu May 14, 2015 07:16 PM
Daniel Garcia-Gil wrote:
D.Fernandez wrote:Hello, tLayout wotk from resources?

Thank you very much.

Saludos
Ruben Dario Fernandez


Hello, not work with resources


Saludos, aun la TLayout sigue sin trabajar desde recursos.? gracias, saludos... :-)
Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Move controls as window size
Posted: Fri May 15, 2015 06:47 AM

Please a question

the dialogresize class run also with x,y sources or only with resources ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com