Frase se ajuste a un ancho

Re: Frase se ajuste a un ancho

Postby cnavarro » Fri Oct 07, 2022 5:52 am

Dejo por aqui un primer prototipo que hice hace ya tiempo.
Si a alguien le es útil, os aseguro que se puede mejorar mucho más
Saludos

Code: Select all  Expand view

//----------------------------------------------------------------------------//
// Author  : ( c ) Cristobal Navarro Lopez
// Date    : 04/2017
// Updated : 10/2022
//----------------------------------------------------------------------------//


#include "Fivewin.ch"

#define WM_NCPAINT          0x085   //133
#define WM_NCLBUTTONDOWN    0x0A1
#define WM_NCLBUTTONUP      0x0A2
#define WM_NCLBUTTONDBLCLK  0x0A3
#define WM_NCRBUTTONDOWN    0x0A4
#define WM_LBUTTONDBLCLK    0x203

#define RDW_NOFRAME         2048
#define RDW_VALIDATE           8
#define RDW_NOCHILDREN        64

Static oWnd

Function Main()

   Fw_SetUnicode( .T. )

   oWnd := TCWnd():New( 120, 120, 500, 780, "My Title", WS_CLIPCHILDREN, , ;
                        ,,,,,,,,, .T., .F., .T., .T., .T.,, "oWnd",, .T. )
   oWnd:bValid   := { || oWnd:SetButtons( .T. ), .T. }
   oWnd:SetColor( CLR_WHITE, METRO_STEEL )
   oWnd:bValid   := { || oWnd:SetButtons( .T. ), .T. }

   ACTIVATE WINDOW oWnd //CENTERED

Return nil

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

CLASS TCWnd FROM TWindow

   CLASSDATA lRegistered AS LOGICAL INIT .F.
   DATA oOldMnu
   DATA cFont          INIT "Calibri"
   DATA nHFont         INIT 14
   DATA lShowHideMnu   INIT .F.
   DATA oBtnExitUI
   DATA oBtnMaxiUI
   DATA oBtnMiniUI
   DATA nPaint         INIT 0
   DATA lSkin          INIT .F.

   DATA wParam
   DATA lParam

   METHOD HandleEvent( nMsg, nWParam, nLParam )
   METHOD NcPaint()
   METHOD SetButtons()

ENDCLASS

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

METHOD SetButtons( lEnd ) CLASS TCWnd

   DEFAULT lEnd   := .F.
   
   if !lEnd
      if Empty( ::oBtnExitUI )
         ::oBtnExitUI := GDIBmp():New( "..\icons\red.ico" )
      endif
      if Empty( ::oBtnMaxiUI )
         ::oBtnMaxiUI := GDIBmp():New( "..\icons\yellow.ico" )
      endif
      if Empty( ::oBtnMiniUI )
         ::oBtnMiniUI := GDIBmp():New( "..\icons\gray.ico" )
      endif
   else
      ::oBtnExitUI:End()
      ::oBtnMaxiUI:End()
      ::oBtnMiniUI:End()
   endif

Return nil

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

METHOD NcPaint( hRgnd ) CLASS TCWnd

   local hDC       := GetWindowDC( if( Empty( hRgnd ), ::hWnd, hRgnd ) )
   local oBrush
   local oBrush1
   local oBrush2
   local oBrush3
   local oGraphics
   local nR        := nRgbRed( ::nClrPane )
   local nG        := nRgbGreen( ::nClrPane )
   local nB        := nRgbBlue( ::nClrPane )
   local nRT       := nRgbRed( ::nClrText )
   local nGT       := nRgbGreen( ::nClrText )
   local nBT       := nRgbBlue( ::nClrText )
   local nHTitle   := GetSysMetrics( 4 ) + 1
   local nHMenu    := GetSysMetrics( 15 )
   local oPen := Pen():New( 255, 220, 220, 220, 1, .T. )

   oBrush2   := Brush():NewSolidBrush( 255, nRT, nGT, nBT )
   oBrush1   := Brush():NewSolidBrush( 255, nR, nG, nB )
   oBrush    := Brush():NewSolidBrush( 255, 200, 200, 200 )
   oBrush3   := Brush():NewSolidBrush( 255, 0, 255, 0 )

   ::nPaint++
   if ::nPaint = 1
      ::SetButtons()
      ::cCaption  := "Titulo A"
   endif

   oGraphics := Graphics():New( hDC )
   //if ::nPaint = 1
 
   oGraphics:DrawRect( , oBrush1, 0, nHTitle + 1 + if( Empty( ::oBar ), 0, ::oBar:nHeight ) + ;
                      if( !Empty( ::oMenu ), nHMenu, 0 ),;
                     ::nWidth, ::nHeight - nHTitle - if( Empty( ::oBar ), 0, ::oBar:nHeight ) - ;
                     if( !Empty( ::oMenu ), nHMenu, 0 ) )

   oGraphics:DrawRect( , oBrush , 0, 0, ::nWidth, nHTitle + 1 )
   oGraphics:DrawText( 1, Int( ( ::nWidth - hb_Utf8Len( ::cCaption ) * 14 ) / 2 ) , ;
                       ::cCaption, ::cFont, ::nHFont, oBrush2 )
   oGraphics:DrawImage( ::oBtnExitUI, Int( ( nHTitle - 16 ) / 2 ) + 1, 4, 16, 16  )
   oGraphics:DrawImage( ::oBtnMaxiUI, Int( ( nHTitle - 16 ) / 2 ) + 1, 4 + 20, 16, 16  )
   oGraphics:DrawImage( ::oBtnMiniUI, Int( ( nHTitle - 16 ) / 2 ) + 1, 4 + 40, 16, 16  )
   
   oGraphics:Destroy()
   ReleaseDc( if( Empty( hRgnd ), ::hWnd, hRgnd ), hDC )

   oBrush:Destroy()
   oBrush1:Destroy()
   oBrush2:Destroy()
   oBrush3:Destroy()
   oPen:Destroy()

   RedrawWindow( ::hWnd, { 0, 0, ::nWidth, nHTitle }, hrgnd, nOR( RDW_VALIDATE, RDW_NOFRAME, RDW_NOCHILDREN ) ) //, RDW_NOERASE ) )

Return nil

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

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TCWnd

   local lContinue := .T.
   local lSetFocus := .T.
   local nCol
   local nRow
   local nMsgDef
   local nHTitle   := GetSysMetrics( 4 ) + 2
   local aPoint    := { 0, 0 }
   local n
   local uRet

   Do Case
      Case nMsg == WM_NCPAINT
         ::wParam  := nWParam
         lContinue := .F.

      Case nMsg == WM_SETFOCUS
         lContinue := .F.
         lSetFocus := .T.
         ::wParam  := Nil
     
      Case nMsg == WM_KILLFOCUS
         lContinue := .F.
         ::wParam  := Nil

      Case nMsg == WM_NCRBUTTONDOWN
         nCol     := GetXParam( nLParam )
         nRow     := GetYParam( nLParam )
         aPoint   := ScreenToClient( ::hWnd, { nRow, nCol } )
         //lContinue  := .F.

      Case nMsg == WM_NCLBUTTONDOWN  //WM_NCLBUTTONUP   //
         nCol     := GetXParam( nLParam )
         nRow     := GetYParam( nLParam )
         aPoint := ScreenToClient( ::hWnd, { nRow, nCol } )
         if aPoint[ 1 ] < 0
            // Area Caption
         endif

      Case nMsg == WM_NCLBUTTONDBLCLK
         nCol     := GetXParam( nLParam )
         nRow     := GetYParam( nLParam )
         aPoint := ScreenToClient( ::hWnd, { nRow, nCol } )
         if aPoint[ 2 ] >= 4 .and. aPoint[ 2 ] <= 20
            ::End()
         endif
         if aPoint[ 2 ] > 20 .and. aPoint[ 2 ] <= 40
            MsgInfo( "Green" )
         endif
         if aPoint[ 2 ] > 40 .and. aPoint[ 2 ] <= 60
            MsgInfo( "Gray" )
         endif
         lContinue := .F.
         ::wParam  := Nil

      Case nMsg == WM_LBUTTONDBLCLK
     
         // No funciona en el caption
         nCol     := GetXParam( nLParam )
         nRow     := GetYParam( nLParam )
         //lContinue := .F.
         ::wParam  := Nil
      Otherwise
         ::wParam   := Nil
         lContinue  := .T.
   EndCase
   if !lContinue
      ::NcPaint( ::wParam )
      uRet := ::Super:HandleEvent( nMsg, nWParam, nLParam )
      if lSetFocus
         ::SetFocus()
      endif
   endif

return if( !lContinue, 0, ::Super:HandleEvent( nMsg, nWParam, nLParam ) )

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

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( REDRAWWINDOW ) // ( hWnd )

{
   HWND hwnd = ( HWND ) hb_parnl( 1 ) ;
   PRECT rect = ( PRECT ) hb_parvnl( 2 );
   HRGN hrgn = ( HRGN ) hb_parnl( 3 );
   INT flags = hb_parni( 4 );
   hb_retl( RedrawWindow( ( HWND ) hwnd, ( PRECT ) rect, ( HRGN ) hrgn, flags ) );

}

#pragma ENDDUMP

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Frase se ajuste a un ancho

Postby Antonio Linares » Fri Oct 07, 2022 11:05 am

Cristobal,

Aparece este error al correr tu ejemplo:
Error description: Error BASE/1004 No exported method: HBMP
Args:
[ 1] = U

Stack Calls
===========
Called from: => HBMP( 0 )
Called from: .\source\classes\TGDIPLUS.PRG => GRAPHICS:DRAWIMAGE( 158 )
Called from: c:\fwteam\samples\crist.prg => TCWND:NCPAINT( 130 )
Called from: c:\fwteam\samples\crist.prg => TCWND:HANDLEEVENT( 217 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3680 )
Called from: => GETWINDOWTEXT( 0 )
Called from: .\source\function\GETTASKS.PRG => ADDTASK( 32 )
Called from: .\source\function\GETTASKS.PRG => (b)GETTASKS( 15 )
Called from: => ENUMCHILDWINDOWS( 0 )
Called from: .\source\function\GETTASKS.PRG => GETTASKS( 15 )
Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG( 250 )
Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS( 24 )
Called from: => HBMP( 0 )
Called from: .\source\classes\TGDIPLUS.PRG => GRAPHICS:DRAWIMAGE( 158 )
Called from: c:\fwteam\samples\crist.prg => TCWND:NCPAINT( 130 )
Called from: c:\fwteam\samples\crist.prg => TCWND:HANDLEEVENT( 217 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3680 )
Called from: => MSGINFO( 0 )
Called from: .\source\classes\TGDIPLUS.PRG => GDIBMP:NEW( 639 )
Called from: c:\fwteam\samples\crist.prg => TCWND:SETBUTTONS( 72 )
Called from: c:\fwteam\samples\crist.prg => TCWND:NCPAINT( 115 )
Called from: c:\fwteam\samples\crist.prg => TCWND:HANDLEEVENT( 217 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3680 )
Called from: => SHOWWINDOW( 0 )
Called from: .\source\classes\WINDOW.PRG => TCWND:ACTIVATE( 1090 )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Frase se ajuste a un ancho

Postby cnavarro » Fri Oct 07, 2022 1:19 pm

En la carpeta icons seguramente solo tengas el fichero red.ico y faltan gray.ico y yellow.ico
Simplemente copia el red.ico a esas otras imágenes y funcionará, aunque te he enviado esas dos imágenes
Aqui están los links de las dos imágenes
https://bitbucket.org/fivetech/fivewin- ... yellow.ico
https://bitbucket.org/fivetech/fivewin- ... s/gray.ico

Image
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Frase se ajuste a un ancho

Postby karinha » Fri Oct 07, 2022 3:06 pm

Perfecto, perfect!

Code: Select all  Expand view

// C:\FWH..\SAMPLES\DIALCENT.PRG

#Include "FiveWin.ch"

STATIC oDlg, cTitle

FUNCTION Main()

   LOCAL oIco, oFont

   DEFINE FONT oFont  NAME "Ms Sans Serif"  SIZE 00, -16 BOLD
   DEFINE ICON oIco FILE "..\icons\fax.ico"

   cTitle := "Probando un Titulo Centrado"

   DEFINE DIALOG oDlg FROM 100, 100 TO 500, 700 PIXEL TITLE cTitle           ;
      COLOR CLR_BLACK, CLR_YELLOW TRANSPARENT ICON oIco FONT oFont

   oDlg:lHelpIcon := .F.

   @ 09.5, 23 BUTTON "&Ok" ACTION( oDlg:End() ) CANCEL

   ACTIVATE DIALOG oDlg CENTERED ON INIT( Centro() )

   oFont:End()

RETURN NIL

FUNCTION Centro()

   LOCAL Espacios

   Espacios := ( ( ( oDlg:nWidth ) / 8 ) - ( LEN( cTitle ) ) / 2 )

   oDlg:cTitle := SPACE( Espacios ) + cTitle

RETURN NIL

// FIN / END
 


Reagrds, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Frase se ajuste a un ancho

Postby Maggiro » Fri Oct 07, 2022 4:39 pm

Buenos Dias Joao:

Gracias por Complementar!
Seria bueno otro ejemplo a los compañeros Desarrolladores de la Gran Libreria Fivewin
que han tenido inconvenientes centrando Dialogos sobre la ventana principal
se mueva donde se mueva
Sabiendo que el CENTERED funciona solo respecto de la pantalla
y sabiendo que el CENTERED IN PARENT tampoco toma las nuevas coordenadas
de la ventana principal para realizar un centro, sino que se queda pegado a las coordenadas
originalmente definidas de la Main()
Estuve viendo los post diversos de los colegas programadores sobre el tema y sacando referencia de comandos
probé algo asi:

Code: Select all  Expand view

#include "FiveWin.ch"

MEMVAR VePru

FUNCTION Main()
   DEFINE WINDOW VePru FROM 0,0 TO 35,100 TITLE '   Ventana' MENU MePru()
   ACTIVATE WINDOW VePru
RETU nil

FUNCTION MePru()
   LOCAL mpr
   MENU mpr 2010
      MENUITEM '&Dialogo' ACTION Mein()
   ENDMENU
RETU mpr

FUNCTION Mein()
   LOCAL DiMein
   DEFINE DIALOG DiMein FROM 10.7,0.7 TO 33.2,50.5S TITLE '   Dialogo'
   ACTIVATE DIALOG DiMein ON INIT DiUbi(DiMein)
RETU nil

FUNCTION DiUbi(DiMein)
   LOCAL ventanaanc,ventanaalt,dialogoanc,dialogoalt,aTopLeft,oTop := 0,oLeft := 0
   ventanaanc=VePru:nWidth
   ventanaalt=VePru:nHeight
   dialogoanc=DiMein:nWidth
   dialogoalt=DiMein:nHeight
   aTopLeft := ClientToScreen( VePru:hWnd, { oTop, oLeft } )
   DiMein:setpos((aTopLeft[1]-54)+((ventanaalt-dialogoalt)/2),(aTopLeft[2]-8)+((ventanaanc-dialogoanc)/2))
RETU nil
 


Un Abrazo
Julio César Gómez Cortéz
Jultzem Estudio
lima Perú
Last edited by Maggiro on Fri Oct 07, 2022 5:57 pm, edited 2 times in total.
User avatar
Maggiro
 
Posts: 84
Joined: Thu Oct 14, 2010 3:26 am
Location: LIMA - PERU

Re: Frase se ajuste a un ancho

Postby karinha » Fri Oct 07, 2022 5:30 pm

Julio César, este ejemplo genera ERROR VeCont y otros.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Frase se ajuste a un ancho

Postby Maggiro » Fri Oct 07, 2022 5:58 pm

karinha wrote:Julio César, este ejemplo genera ERROR VeCont y otros.

Regards, saludos.


correcto, ya esta corregido para correr
User avatar
Maggiro
 
Posts: 84
Joined: Thu Oct 14, 2010 3:26 am
Location: LIMA - PERU

Re: Frase se ajuste a un ancho

Postby karinha » Sat Oct 08, 2022 8:05 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Previous

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests