FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Resizing Controls
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Resizing Controls
Posted: Thu Dec 19, 2013 11:00 PM
To All

I am trying to calculate the controls on a parent dialog when the user RESIZES the screen. I have no problems resizing folders and xBrowse .. I just can not seem to be able to calculate the proper movement of a BtnBmp.

What happens is I lose the caption and the button does not move .. please review my code and tell me what I am doing wrong... aControls[56] is the correct control .. note the loss of the caption in the second screen shot.

Rick Lipkin

Starting to resize screen


notice the Close button


Code (fw): Select all Collapse
Static Func _ResizeControls( nSizeType, nWidth, nHeight, oGrps,oFld )


if nSizeType = 0 //SIZE_MAXIMIZED

*   xbrowse( oGrps:aControls )            // 37          247
*   xbrowse( oFld:aDialogs[1]:aControls )
*   xbrowse( oFld:aDialogs[1]:aControls[6] )
*       xbrowse( oFld:aDialogs )

                                                        // 340
   oGrps:aControls[1 ]:SetSize( nWidth - 372, nHeight - 290 )                //folder
   oFld:aDialogs[1]:SetSize(    nWidth - 372, nHeight - 290 )                // dialog1
   oFld:aDialogs[1]:aControls[1]:SetSize( , nHeight - 340 )                  // ad campaign
   oFld:aDialogs[1]:aControls[6]:SetSize( nWidth - 600, nHeight - 370 )      // publications

*   oGrps:aControls[58]:SetSize( nWidth - 372, nHeight - 340 )                //delete
*   oGrps:aControls[57]:SetSize( nWidth - 372, nHeight - 340 )                //save edit
*   oGrps:aControls[54]:SetSize( nWidth - 372, nHeight - 340 )                //save new
*   oGrps:aControls[55]:SetSize( nWidth - 372, nHeight - 340 )                //add new
   oGrps:aControls[56]:SetSize( , nHeight - 100 )                             //close  <----  here

*   oFld:aDialogs[1]:SetSize( nWidth - 372, nHeight - 340 )                  // ad campaign
*   oFld:aDialogs[1]:aControls[6]:SetSize( nWidth - 372, nHeight - 340 )     // ad publications

endif

Return(nil)
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Resizing Controls
Posted: Sat Dec 21, 2013 02:22 PM

Any Ideas anyone ????

Thanks
Rick Lipkin

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Resizing Controls
Posted: Sat Dec 21, 2013 03:49 PM

Rick:

1) Where did all the hard-coded numbers come from?

2) You say there is a missing caption--please explain. What caption is missing?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Resizing Controls
Posted: Sat Dec 21, 2013 05:26 PM
James

The only way I know how to resize controls is to identify them manually .. the rem'd out xBrowse lines allow me to inspect the array controls to determine the exact ( button, get, checkbox, xBrowse ) id.

Code (fw): Select all Collapse
     xbrowse( oGrps:aControls )   // see screen shot         
*   xbrowse( oFld:aDialogs[1]:aControls )
*   xbrowse( oFld:aDialogs[1]:aControls[6] )
*   xbrowse( oFld:aDialogs )


control 56 is the "Close" Button

Note array inspection on the caption to verify control


Two things happen to my ( test ) "Close" button when I try to calculate the resize .. I lose the caption, and two, the button does not move. .. Notice the previous post screen shot.

If there is an easy way to resize controls, I would be be grateful to know the best way to do it.

Thanks
Rick Lipkin
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Resizing Controls
Posted: Sat Dec 21, 2013 05:55 PM

Rick,

I have not done any work with resizing, but it seems to me that you need to work with percentages not pixels (or in the case of dialogs, "dialog units"). So, I would be multiplying each control's height and width by a factor. Then you can make them different sizes by just passing a factor (and screen resolution will not matter).

I see two close buttons in your screenshots and both the before and after shots clearly show "Close" on the buttons so I still do not understand which caption is missing. Can you draw a circle around where the missing caption is supposed to be? Since it is a button, I suspect that the font size would also have to be changed. It may be that if the font size is not changed that the caption is too large for the button so it is not displayed at all. Makes sense to me.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Resizing Controls
Posted: Sat Dec 21, 2013 07:01 PM

For the caption issue, may I suggest making as simple of an example as possible for testing--just a dialog with the Close button. This should make it easier to test and resolve.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Resizing Controls
Posted: Sat Dec 21, 2013 09:02 PM
James

Here is your test .. scaled down .. note the calculation for the folder, dialog, xbrowse and close button. Notice when you pull the lower right corner, the folder, dialog and xbrowse expand properly, but the button loses its caption and does not move... I need to be able to rezise the buttons and I can not make that happen.

Note that all the resize calculations are done in _ResizeControls().

Hope this helps.

Rick Lipkin


AdvtBrow.rc
Code (fw): Select all Collapse
ADVTBROW DIALOG 12, 11, 365, 131
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
 CONTROL "", 272, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 35, 4, 327, 123
 CONTROL "Add", 213, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 5, 10, 27, 19
 CONTROL "Edit", 214, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 5, 31, 27, 19
}

Billing.rc
Code (fw): Select all Collapse
BILLING DIALOG 12, 11, 401, 179
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
}

Custview.rc
Code (fw): Select all Collapse
CUSTVIEW DIALOG 3, 13, 612, 343
STYLE WS_CHILD
FONT 6, "MS Sans Serif"
{
 EDITTEXT 130, 56, 12, 160, 12, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
 EDITTEXT 131, 56, 25, 98, 12, ES_CENTER | ES_AUTOHSCROLL | NOT WS_TABSTOP | WS_BORDER
 CONTROL "&Close", 182, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 532, 315, 70, 17
 CONTROL "Customer Info", 172, "TXBrowse", 0 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, 230, 13, 373, 110
 CONTROL "&Add New", 181, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 459, 315, 70, 17
 CONTROL "&Save New", 180, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 386, 315, 70, 17
 CONTROL "Company", 110, "STATIC", SS_NOPREFIX | WS_GROUP, 7, 12, 46, 12
 GROUPBOX "  Search", 200, 3, 1, 221, 41, BS_GROUPBOX
 LTEXT "Customer Id", 111, 7, 25, 46, 12, SS_NOPREFIX | WS_GROUP
 CONTROL "Save Edit", 183, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 313, 315, 70, 17
 CONTROL "", 173, "TFolderex", 0 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 231, 128, 371, 155
}


Main Code
Code (fw): Select all Collapse
// main.prg

#include "Fivewin.ch"
#Include "xBrowse.Ch"

Function Main()

   Local oWind

   DEFINE WINDOW oWind MDI

   ACTIVATE WINDOW oWind ON INIT ( _CustView("A",oWind) ) MAxiMizED

   Return nil

//-------------------------------
Static FUNC _CustView( cMODE,oWind )

LOCAL SAYING, oWndChild, oGrps,oSay1,oSay2
LOCAL cTITLE, oBtn1,oBTN2,oBtn3,oBtn4
Local oBtn5,oBtn6

Local lOk
Local oFontB

Local cName,cCid,oName,oCid
Local oCol
Local oFld,nFolder,oLbxA,oLbx

lOk := .F.    // trap valid

oFontB := TFont():New("Ms Sans Serif",,-6,.F.,.T. ,,,,.F. )
cMode  := "A"

// search vars
cName              := space(50)
cCid               := space(15)

LightGreyGrad()

cTITLE := "Clients-Billing"

DO CASE
CASE cMODE = "E"
     cTITLE := "Clients-Billing  EDIT   "
CASE cMODE = "A"
     cTITLE := "Clients-Billing   ADD   "
CASE cMODE = "V"
     cTITLE := "Clients-Billing  VIEW   "
ENDCASE

DEFINE WINDOW oWndChild              ;
       MDICHILD                      ;
       FROM 0,1 to 37,117            ;
       NOMINIMIZE                    ;
       NOZOOM                        ;
       OF oWind                      ;
       TITLE cTITLE

   oWndChild:bGotFocus = { || oGrps:SetFocus() }

   DEFINE DIALOG oGRPS RESOURCE "CUSTVIEW" ;
   of oWndChild


   REDEFINE FOLDEREX oFld ID 173 of oGrps ;
                PROMPT "Advertising Information", "Billing-Invoicing Information";
                DIALOGS "ADVTBROW", "BILLING" ;
                ON CHANGE( nFolder := nOption )

   // folder 1

         REDEFINE xBROWSE oLbxA      ;
         COLSIZES 50,120,80,80,150   ;
         HEADERS "PubId",            ;
                 "Publication",      ;
                 "StartDate",        ;
                 "EndDate",          ;
                 "Acct Executive"    ;
         ID 272 of oFld:aDialogs[1]  ;
         AUTOCOLS LINES CELL

         oLbxA:lRecordSelector := .f.
         oLbxA:lHScroll := .f. // turn off horiz scroll bar

         REDEFINE BTNBMP oBTN5 ID 213 of oFld:aDialogs[1]  ;     // add
         PROMPT "Add" LEFT 2007;
         ACTION ( nil )

         REDEFINE BTNBMP oBTN6 ID 214 of oFld:aDialogs[1]  ;     // edit
         PROMPT "Edit" LEFT 2007;
         ACTION ( nil )


   // end folder1


 *  REDEFINE GROUP oGrp1 ID 200 OF oGrps
 *       oGrp1:SetFont( oFontB )
 *       oGrp1:nClrText := nRgb( 7,7,224 ) // blue
   REDEFINE SAY oSay1  PROMPT "Company"        ID 110 OF oGrps UPDATE
                oSay1:SetFont( oFontB )
   REDEFINE SAY oSay2  PROMPT "Customer Id"    ID 111 OF oGrps UPDATE
                oSay2:SetFont( oFontB )

   // search
   REDEFINE GET oName var cName ID 130 of oGrps UPDATE
   REDEFINE GET oCid  var cCid ID 131 of oGrps UPDATE

   REDEFINE xBROWSE oLBX             ;
         COLSIZES 75,150,85,150      ;
         HEADERS "Cust Id",          ;
                 "Customer Name",    ;
                 "Phone",            ;
                 "Contact Person"    ;
         ID 172 of oGrps             ;
         AUTOCOLS LINES CELL

       oLbx:lRecordSelector := .f.


   REDEFINE BTNBMP oBTN1 ID 180 of oGRPS  ;     // save new
         RESOURCE "OK" ;
         PROMPT "    Save New  " LEFT 2007;
         ACTION ( nil )

   REDEFINE BTNBMP oBTN2 ID 181 of oGRPS   ;    // add new
         RESOURCE "PLUS16" ;
         PROMPT "      Add New  " LEFT 2007;
         ACTION ( lOK := .F., oWndChild:END() )

   REDEFINE BTNBMP oBTN3 ID 182 of oGRPS   ;    // close
         RESOURCE "CANCEL" ;
         PROMPT "      Close   " LEFT 2007;
         ACTION ( lOK := .F., oWndChild:END() )

   REDEFINE BTNBMP oBTN4 ID 183 of oGRPS  ;     // save edit
         RESOURCE "OK" ;
         PROMPT "   Save Edit  " LEFT 2007;
         ACTION ( nil )

ACTIVATE DIALOG oGRPS NOWAIT ;
         ON INIT (oGrps:Move( 0,0 ), oName:SetFocus(), .F. ) ;
         VALID(!GETKEYSTATE( 27 ))


ACTIVATE WINDOW oWndChild ;
   ON INIT (  ;
           oWndChild:bResized := {|| _ReSizeUm( oGrps,oWndChild,oLbx,oLbxA,oFld) }, ;
           oGrps:ReFresh());
           VALID ( IIF( !lOk, ExitPgm( .T.,@lOk,oFontB,oWndChild ) , .F. ))


RETURN( nil )

//------------------------------
Static Func _ReSizeUm( oGrps,oWndChild,oLbx,oLbxA,oFld )


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

// dialog controls
oGrps:bResized = { | nSizeType, nWidth, nHeight | _ResizeControls( nSizeType, nWidth, nHeight, oGrps, oFld ) }


Return(nil)

//-------------------------
Static Func _ResizeControls( nSizeType, nWidth, nHeight, oGrps,oFld )


if nSizeType = 0 //SIZE_MAXIMIZED

*   xbrowse( oGrps:aControls )
*   xbrowse( oFld:aDialogs[1]:aControls )
*   xbrowse( oFld:aDialogs[1]:aControls[6] )
*   xbrowse( oFld:aDialogs )

                                                        // 340
   oGrps:aControls[1 ]:SetSize( nWidth - 372, nHeight - 290 )                //folder
   oFld:aDialogs[1]:SetSize(    nWidth - 372, nHeight - 290 )                // dialog1
   oFld:aDialogs[1]:aControls[1]:SetSize(nWidth - 435, nHeight - 340 )       // xbrowse folder 1
*   oFld:aDialogs[1]:aControls[6]:SetSize( nWidth - 600, nHeight - 370 )      // publications

*   oGrps:aControls[7]:SetSize(  nWidth - 372, nHeight - 340 )                //save new
*   oGrps:aControls[8]:SetSize(  nWidth - 372, nHeight - 340 )                //add new
   oGrps:aControls[9]:SetSize(  nWidth - 372, nHeight - 340 )                //close
*   oGrps:aControls[10]:SetSize( nWidth - 372, nHeight - 340 )                //save edit


endif

Return(nil)


//------------------
Static Func LightGreyGrad()

SetDlgGradient( { { .50, nRGB( 216, 216, 216 ), nRGB( 255, 255, 255 ) } } )

Return(nil)


//----------------------
Static FUNC _CleanUp()

RETURN(.T.)

//-----------------------
Static FUNCTION ExitPgm( lClean,lOk,oFontB,oWndChild )

Local Saying

IF lCLEAN = .T.
   lOk := .T.

   RELEASE oFontB

ENDIF

RETURN( lOk )
Posts: 1286
Joined: Mon Feb 25, 2008 02:54 PM
Re: Resizing Controls
Posted: Sun Dec 22, 2013 11:34 AM
ubiratanmga@gmail.com

FWH24.04
BCC7.3
HARBOUR3.2
xMate
Pelles´C
TDolphin
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Resizing Controls
Posted: Sun Dec 22, 2013 06:10 PM

Rick,

From a quick look at the functions referenced in the previous message, it appears that the font width is being resized also. This may be your solution.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 208
Joined: Wed Dec 03, 2008 04:48 PM
Re: Resizing Controls
Posted: Mon Dec 23, 2013 11:24 PM

I still do not understand how this code will work. The resizing use the absolute values but the user can change the dialog size in many steps... How these numbers fit in such logic?
I would expect percentages, because the user can resize dialog for just a 20 pixels down-right for example, or he can resize the dialog for 100 pixels... How the absolute resizing values can handle both situations.

Or I am missing something?

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Resizing Controls
Posted: Tue Dec 24, 2013 02:06 PM
Boris

The sample code looks to resize controls when the dialog box is pulled from the corners. I am not looking to resize all the controls, but only the folders, the contents of the folders including the embedded dialogs, buttons and xbrowses.

The math seems fairly straight forward .. determine the size of the ( expanding ) dialog and subtract the controls position ( as a constant ) from the sides and bottom.

What I have found out is you can not use the SetSize() method on buttons, instead you have to calculate the Move() in proportion to the expanding corners .. top, left, height and width.

I looked at the code suggested from the link from SGS and am trying to apply this logic to the btnbmp's .. the nFactorHeight and nFactorWidth are based on the original screen resolution ...

nFactorWidth := 1280
nFactorHeight := 960

* oGrps:aControls[9] is the cancel button control id in the above example.

Code (fw): Select all Collapse
/*
oWnd:ClassName()$"/TBTNBMP/"

         oWnd:Move( oWnd:nTop * nFactorHeight , ;
         oWnd:nLeft * nFactorWidth, ;
         oWnd:nWidth * nFactorWidth, ;
         oWnd:nHeight * nFactorHeight , ;
         .F. )

         *********************************
         * resizes the BMP BTNBMP
         o:=oWnd:hbitmap1
         if o<>0
            hbmp:=ownd:hbitmap1
            nbmpwidth := nbmpwidth(hbmp)
            nbmpheight:= nbmpheight(hbmp)
            larg:=nbmpwidth*nfactorwitdh
            alt:=nbmpheight*nfactorheight
            o:=resizebmp(o,larg ,alt )
            oWnd:=o
         endif
*/


Unfortunately, I have not yet been able to successfully interpret the suggested code ... I have looked at the buttons object properties and know its exact position, nTop,nRight,nLeft,nHeight and nWidth but I have not yet come up with the proper algorithm to get the correct Move() co-ordinates in proportion to the expanding dialog.

Again, I am not trying to recalculate every control on resize, I just want to recalculate the bottom right folder, its contents and buttons when the bottom right corner is expanded.

My above sample works for the folders and the embedded dialogs and xbrowse .. I am struggling with finding the right calculation to Move() the btnbmps in proportion to the expanding dialog.

Compile my sample and pull the lower right hand corner of the dialog over and down and observe the movement of the folder and its contents.

Again, I think the answer to the buttons is in the Move() method and not SetSize().

Rick Lipkin

Continue the discussion