redimensionar dialogos...

Post Reply
Francisco Horta
Posts: 845
Joined: Sun Oct 09, 2005 5:36 pm
Location: la laguna, mexico.

redimensionar dialogos...

Post by Francisco Horta »

Hola foro,
se que en alguna ocasion se toco el temo, pero lo encontre..
Tengo dialogos diseñados para una resolucion de 800x600 pero si mi resolucion es mayo quiero que el dialogo se ajuste al tamaño nuevo de resolucion incluyendo controles, sera posible?
gracias
Paco
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Paco,

En la clase TDialog en el método Initiate tienes este código que sirve para redimensionar un diálogo. Se podría generalizar, para usarlo como método y al tamaño que se desease:

Code: Select all

      #define SCALE_FACTOR 1.16668
      if ::lResize16 .and. ! Empty( ::cResName )
         ::nWidth = ::nWidth * SCALE_FACTOR
         hCtrl = GetWindow( ::hWnd, GW_CHILD )
         if hCtrl != 0
            do while ! lEnd
               aRect = GetCoors( hCtrl )
               SetWindowPos( hCtrl, 0, aRect[ 1 ], aRect[ 2 ] * SCALE_FACTOR,;
                             ( aRect[ 4 ] - aRect[ 2 ] ) * SCALE_FACTOR,;
                             aRect[ 3 ] - aRect[ 1 ], nOr( SWP_NOZORDER,;
                             SWP_NOREDRAW, SWP_NOACTIVATE ) )
               hCtrl = GetWindow( hCtrl, GW_HWNDNEXT )
               lEnd = ! ( ( hCtrl != 0 ) .and. ( GetParent( hCtrl ) == ::hWnd ) )
            end
         endif
      endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
FiveWiDi
Posts: 910
Joined: Mon Oct 10, 2005 2:38 pm

Re: redimensionar dialogos...

Post by FiveWiDi »

Francisco Horta wrote:Hola foro,
se que en alguna ocasion se toco el temo, pero lo encontre..
Tengo dialogos diseñados para una resolucion de 800x600 pero si mi resolucion es mayo quiero que el dialogo se ajuste al tamaño nuevo de resolucion incluyendo controles, sera posible?
gracias
Paco
Yo utilizo esta función:

/* ******************** */
#Include "FiveWin.ch"

/*
Los parámetros recibidos son:
oWnd: Objeto/ventana/diálogo/control a ser redimensionado.
nResolution: Número que identifica que resolución tenía la pantalla en la cual
se diseñó el objeto.
lRepaint: Indicador de si debe repintarse el objeto una vez redimensionado.

Esta función permitirá que una aplicación desarrolada en un PC con una resolución
de pantalla de por ejemplo 1024 x 768 (nResolution valdría en este caso 3), se vea
redimensionada proporcionalmente en un PC con una resolución diferente, ya sea mayor
o menor.

A falta de perfeccionar el código, se comprueba solamente la variación de la anchura
de la resolución de la pantalla para aplicar la variación del tamaño, aunque cuando
ello se realiza se hace tanto en la anchura como en la altura.

Esta función está orientada a ser utilizada en el evento ON INIT del ACTIVATE
de las WINDOW y DIALOG con un valor fijo de lRepaint a .T. o sin él.
Además también puede utilizarse directamente sobre un control definido posteriormente
a la ACTIVACIÓN de su contenedor ya sea éste WINDOW o DIALOG, con la salvedad que
lRepaint debe valer .T. para forzar su repintado.

Ejemplos de uso:

-* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
ACTIVATE oWnd ON INIT AutoResize( oWnd, 3 )

-* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*

@ 185.50,8.00 TABS oTabs OF oWnd ITEMS "Tab1","Tab2","Venga a ordenarrrrr!!" ;
PIXEL COLORS CLR_BLUE,CLR_HCYAN SIZE 288.00,9.00 MESSAGE "Mensaje del Tabs"

AutoResize( oTabs, 3, .T. )

-* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -* -*
*/

FUNCTION AutResiz( oWnd, nResolution, lRepaint )

// Resolución de la pantalla en el momento de definir los controles.
Local nOriWidth, nOriHeight

// Resolución actual de la pantalla.
Local nWidth, nHeight

// Son la relación entre la resolución de pantalla y la resolución de diseño.
Local nFactorWitdh, nFactorHeight

Local nContador

DEFAULT lRepaint := .T.

nOriWidth := 0
nOriHeight := 0
nWidth := 0
nHeight := 0
nContador := 0

If nResolution = 1
nOriWidth := 640
nOriHeight := 480
ElseIf nResolution = 2
nOriWidth := 800
nOriHeight := 600
ElseIf nResolution = 3
nOriWidth := 1024
nOriHeight := 768
ElseIf nResolution = 4
nOriWidth := 1152
nOriHeight := 864
ElseIf nResolution = 5
nOriWidth := 1280
nOriHeight := 1024
ElseIf nResolution = 6
nOriWidth := 1600
nOriHeight := 1200
Else
ScrResolution( @nOriWidth, @nOriHeight )
Endif

ScrResolution( @nWidth, @nHeight )

/*
Traza( 1, "nOriWidth=", nOriWidth )
Traza( 1, "nOriHeight=", nOriHeight )

Traza( 1, "nWidth=", nWidth )
Traza( 1, "nHeight=", nHeight )
*/

//Traza( 1, "oWnd:ClassName()=", oWnd:ClassName() )

If nOriWidth != nWidth // .or. nOriHeight != nHeight

nFactorWitdh := nWidth / nOriWidth
nFactorHeight := nHeight / nOriHeight

//oWnd:CoorsUpdate()

If lRepaint
oWnd:Hide()
EndIf

If nFactorWitdh > 1 // .or. nFactorHeight >= 1

//Traza( 1, "Aumentando tamaño." )

If oWnd:ClassName() == "kalimeroquetequiero"
ElseIf oWnd:ClassName() $ "/TJ02LISMN/TLISTBOX/"
/* Traza( 1, "oWnd:nTop=", oWnd:nTop )
Traza( 1, "oWnd:nLeft=", oWnd:nLeft )
Traza( 1, "oWnd:nWidth=", oWnd:nWidth )
Traza( 1, "oWnd:nHeight=", oWnd:nHeight )
*/
oWnd:Move( oWnd:nTop * nFactorHeight , ;
oWnd:nLeft * nFactorWitdh, ;
oWnd:nWidth * nFactorWitdh, ;
oWnd:nHeight , ;
.F. )
Else
oWnd:Move( oWnd:nTop * nFactorHeight , ;
oWnd:nLeft * nFactorWitdh, ;
oWnd:nWidth * nFactorWitdh, ;
oWnd:nHeight * nFactorHeight , ;
.F. )
EndIf
EndIf

If oWnd:ClassName() == "TFOLDER"
// Traza( 1, "ValType(oWnd:aDialogs)=", ValType(oWnd:aDialogs) )
If ValType( oWnd:aDialogs ) = "A"
For nContador := 1 To Len( oWnd:aDialogs )
AutResiz( oWnd:aDialogs[nContador], nResolution, .F. )
EndFor
EndIf
Else
// Traza( 1, "ValType(oWnd:aControls)=", ValType(oWnd:aControls) )
If ValType( oWnd:aControls ) = "A"
For nContador := 1 To Len( oWnd:aControls )
AutResiz( oWnd:aControls[nContador], nResolution, .F. )
EndFor
EndIf
EndIf

If nFactorWitdh < 1 // .or. nFactorHeight < 1

//Traza( 1, "Disminuyendo tamaño." )

If oWnd:ClassName() == "kalimeroquetequiero"
ElseIf oWnd:ClassName() $ "/TJ02LISMN/TLISTBOX/"
/* Traza( 1, "oWnd:nTop=", oWnd:nTop )
Traza( 1, "oWnd:nLeft=", oWnd:nLeft )
Traza( 1, "oWnd:nWidth=", oWnd:nWidth )
Traza( 1, "oWnd:nHeight=", oWnd:nHeight )
*/

//Traza( 1, "oWnd:nRight=", oWnd:nRight )
//Traza( 1, "oWnd:nBottom=", oWnd:nBottom )

oWnd:Move( oWnd:nTop * nFactorHeight , ;
oWnd:nLeft * nFactorWitdh, ;
oWnd:nWidth * nFactorWitdh, ;
oWnd:nHeight , ;
.F. )
//oWnd:SetSize( oWnd:nWidth * nFactorWitdh, oWnd:nHeight * nFactorHeight, .T. )
/* Traza( 1, "oWnd:nTop=", oWnd:nTop )
Traza( 1, "oWnd:nLeft=", oWnd:nLeft )
Traza( 1, "oWnd:nWidth=", oWnd:nWidth )
Traza( 1, "oWnd:nHeight=", oWnd:nHeight )
*/
Else
oWnd:Move( oWnd:nTop * nFactorHeight , ;
oWnd:nLeft * nFactorWitdh, ;
oWnd:nWidth * nFactorWitdh, ;
oWnd:nHeight * nFactorHeight , ;
.F. )
EndIf
EndIf

If lRepaint
oWnd:Show()
EndIf

EndIf


/* ******************** */

Saludos
Carlos G.
Francisco Horta
Posts: 845
Joined: Sun Oct 09, 2005 5:36 pm
Location: la laguna, mexico.

Re: redimensionar dialogos...

Post by Francisco Horta »

Hola Carlos,

me tira error ...
Carlos G.
Posts: 8
Joined: Mon Oct 10, 2005 2:37 pm
Location: Vallirana

Re: redimensionar dialogos...

Post by Carlos G. »

Francisco Horta wrote:Hola Carlos,

me tira error ...
Si, pero cual?

Saludos
Carlos G.
User avatar
RenOmaS
Posts: 205
Joined: Fri Oct 07, 2005 5:07 pm

Post by RenOmaS »

Si te Sirve ahi te envio como lo hago

Llamas al CheckRes() en el on init del dialog, tambien esta para modificar el font del dialogo o controles... se puede tambien modificar el tsbrowse o la barra de mensages... contactame por el MSN ;), Ya tenemos avanzado algo el Punto de Venta

Code: Select all

Static Function CheckRes( oDlg )
//---------------------------------------------------------------------------
   Local hWDsk := GetDeskTopWindow()
   Local ResXY := GetClientRect( hWDsk )
   Local aRectD :=  GetClientRect( oDlg:hWnd )
   Local nFor, oRow
   Local nFactorX := ResXY[ 3 ] / aRectD[ 3 ]
   Local nFactorY := ResXY[ 4 ] / aRectD[ 4 ]

   //modificando el dialog
   //PARA RECURSOS TODOS LOS CONTROLES TIENEN QUE ESTAR REDEFINDOS !! OJO !!
   oDlg:Move( 0, 0, ResXY[ 4 ], ResXY[ 3 ], .t. )

   // Redfiniendo Tamaño de Fonts de Controles / Dialogs..
   oDlg:MSetFont( nFactorX, nFactorY )

   Return Nil
En el Move() del Dialog puedes hacer esto... yo en este caso he creado una clase TMDialog que hereda de TDialog. El move de los controles. tiene para mantener fijo la parte superior ( lFixTop ) o la parte izquierda ( lFixLeft )

Code: Select all

#Include 'FiveWin.ch'

CLASS TMDialog From TDialog

   METHOD Move()
   METHOD ClassName()            INLINE 'TDIALOG'
   METHOD MSetFont()

ENDCLASS

//-----------------------------------------------------------------------------------------//
METHOD Move( nTop, nLeft, nWidth, nHeight, lRepaint ) CLASS TMDialog
   Local nFor
   Local aRectD :=  GetClientRect( ::hWnd )

   Super:Move( nTop, nLeft, nWidth, nHeight, lRepaint )

   For nFor := 1 To Len( ::aControls )
       MoveControl( ::aControls[ nFor ], aRectD[ 3 ], aRectD[ 4 ], nHeight, nWidth, .T. )
   EndFor
   Return nil


Static Function MoveControl( oCtrl, nBottomAnt, nRightAnt, nBottomNew, nRightNew, lProportional, lFixTop, lFixLeft )
   Local nTop   := oCtrl:nTop +  nBottomNew - nBottomAnt
   Local nLeft  := oCtrl:nLeft + nRightNew - nRightAnt
   Local nHeight:= 0
   Local nWidth := 0
   Local nFactorX := nBottomNew / nBottomAnt
   Local nFactorY := nRightNew / nRightAnt

   DEFAULT lProportional := .F., ;
           lFixTop := .F., ;
           lFixLeft:= .F.

   If lProportional
      nTop   := Int( oCtrl:nTop * nFactorX )
      nLeft  := Int( oCtrl:nLeft * nFactorY )
      nHeight:= INT( oCtrl:nHeight * nFactorX )
      nWidth := INT( oCtrl:nWidth * nFactorY )
   EndIf

   If lFixTop
      If lProportional //tenemos que modificar el Height //para ke seubique en la pos correcta
         nHeight += nTop - oCtrl:nTop
      EndIf
      nTop := oCtrl:nTop
   EndIf

   If lFixLeft
      If lProportional //tenemos que modificar el Width //para ke seubique en la pos correcta
         nWidth += nLeft - oCtrl:nLeft
      EndIf
      nLeft := oCtrl:nLeft
   EndIf

   If oCtrl:ClassName() == 'TBITMAP' .and. !oCtrl:lStretch
      nWidth := 0          // cuando el bitmap y no es ajustado
      nHeight:= 0          // lo dibujamos con sus mismas extesiones
   EndIf

   oCtrl:Move( nTop, nLeft, nWidth, nHeight )

   Return Nil

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

METHOD MSetFont( nFactorX, nFactorY ) CLASS TMDialog
   Local nFor, oCtrl
   Local oFont := TFont():New( ::oFont:cFaceName, ;
                               Int( If( ::oFont:nWidth == Nil, 0, ::oFont:nWidth ) * nFactorY ), ;
                               Int( ::oFont:nHeight * nFactorX ), , ;
                               ::oFont:lBold, ;
                               ::oFont:nEscapement, ;
                               ::oFont:nOrientation, ;
                               ::oFont:nWeight, ;
                               ::oFont:lItalic, ;
                               ::oFont:lUnderline,;
                               ::oFont:lStrikeOut, ;
                               ::oFont:nCharSet, ;
                               ::oFont:nOutPrecision, ;
                               ::oFont:nClipPrecision,;
                               ::oFont:nQuality, , ;
                               ::oFont:nPitchFamily )


   ::SetFont( oFont )

   oFont:End()

   For nFor := 1 To Len( ::aControls )
       oCtrl := ::aControls[ nFor ]
       oFont := TFont():New( oCtrl:oFont:cFaceName, ;
                               Int( If( oCtrl:oFont:nWidth == Nil, 0, oCtrl:oFont:nWidth ) * nFactorY ), ;
                               Int( oCtrl:oFont:nHeight * nFactorX ), , ;
                               oCtrl:oFont:lBold, ;
                               oCtrl:oFont:nEscapement, ;
                               oCtrl:oFont:nOrientation, ;
                               oCtrl:oFont:nWeight, ;
                               oCtrl:oFont:lItalic, ;
                               oCtrl:oFont:lUnderline,;
                               oCtrl:oFont:lStrikeOut, ;
                               oCtrl:oFont:nCharSet, ;
                               oCtrl:oFont:nOutPrecision, ;
                               oCtrl:oFont:nClipPrecision,;
                               oCtrl:oFont:nQuality, , ;
                               oCtrl:oFont:nPitchFamily )

       oCtrl:SetFont( oFont )

       If oCtrl:ClassName() == 'TSBROWSE'
          oCtrl:ChangeFont( oFont )
       EndIf

       oFont:End()

   EndFor

   oFont := Nil

   Return Nil

User avatar
Manuel Valdenebro
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Post by Manuel Valdenebro »

RenOmaS wrote:Ya tenemos avanzado algo el Punto de Venta
¿Teneis ya depurado el código?. Sería interesante contar, en la propia clase Tdialogo, con la posibilidad de adaptar los dialogos y controles a la resolucion de la pantalla.
Un saludo

Manuel
User avatar
jose_murugosa
Posts: 943
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay
Contact:

Post by jose_murugosa »

RenOmaS

Siempre sorprendiéndonos con buen código, estoy de acuerdo con Manuel de lo interesante que sería contar con una clase de ese tipo.

Desde ya Gracias por el código que has volcado.
Saludos/Regards,
José Murugosa
FWH + Harbour + Bcc7. Una seda!
User avatar
RenOmaS
Posts: 205
Joined: Fri Oct 07, 2005 5:07 pm

Post by RenOmaS »

Pos ese es el mismo codigo..
Sigue funcionando..
pos la clase esta ahi TMDialog

Saludos
Post Reply