// viewtopic.php?f=6&t=19174
CREATE FIRST A YOUR Fichero.txt or use this
- Code: Select all Expand view
- I found some function on forum by Antolin and I make the control class / I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and / I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class/ I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class I found some function on forum by Antolin and I make the control class
use the symbol "/" to make a CRLF into the File text if you want
the test
- Code: Select all Expand view
#include "FiveWin.ch"
Function test()
Local oWnd
Local oSay
Local cText := MemoRead( "Fichero.txt" )
Local nlenght := 200
Local nLinea := 10
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE WINDOW oWnd
osay:=TSayjustified():New(10, 10, oWnd, 250, 200, cText,nLinea, nlenght, oFont)
ACTIVATE WINDOW oWnd
RETURN NIL
the class TSayjustified
- Code: Select all Expand view
#include "FiveWin.ch"
#include "Constant.ch"
CLASS TSayjustified FROM TControl
DATA cText INIT ""
DATA nLenght AS NUMERIC
DATA nColorTesto AS NUMERIC INIT nRGB( 125, 165, 224 )
DATA nLinea AS NUMERIC
DATA aTexto AS ARRAY INIT {}
DATA lBorder AS LOGICAL INIT .T.
DATA nBorderLine AS NUMERIC INIT 3
DATA oFont
DATA nColorBorder AS NUMERIC INIT CLR_RED
DATA nColorBack AS NUMERIC INIT nRGB( 89, 135, 214 )
DATA ltransparent AS LOGICAL INIT .T.
CLASSDATA lRegistered AS LOGICAL
METHOD New( nTop, nLeft, oWnd, nWidth, nHeight,cText,nLinea,;
nlenght, oFont, nColortesto,nBorderLine,lBorder,nColorBack,;
nColorBorder,lPixel,lTransparent,lDesign, lUpdate ) CONSTRUCTOR
METHOD ReDefine( nId, oWnd ) CONSTRUCTOR
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD Paint()
METHOD FormatText()
METHOD PainText()
METHOD _FillRect( nTop, nLeft, nBottom, nRight, nColor )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New(nTop, nLeft, oWnd, nWidth, nHeight,cText,nLinea,;
nlenght, oFont, nColortesto,nBorderLine,lBorder,nColorBack,;
nColorBorder,lPixel,lTransparent,lDesign, lUpdate ) CLASS TSayjustified
DEFAULT nTop := 0, nLeft := 0 ,;
oWnd := GetWndDefault() ,;
lPixel := .t. ,;
nBorderLine := 3 ,;
lBorder := .t. ,;
nWidth := 400, nHeight := 200 ,;
nLenght := 150 ,;
nColortesto := CLR_BLACK ,;
lTransparent := .t. ,;
lDesign := .f. ,;
lUpdate := .f.
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )
::nId = ::GetNewId()
::oWnd = oWnd
::ctext = ctext
::nTop = If( lPixel, nTop, nTop * SAY_CHARPIX_H )
::nLeft = If( lPixel, nLeft, nLeft * SAY_CHARPIX_W )
::nBottom = ::nTop + nHeight - 1
::nRight = ::nLeft + nWidth - 1
::oFont = oFont
::nLinea = nLinea
::nColortesto = nColortesto
::nLenght = nLenght
::lTransparent = lTransparent
::lDrag = lDesign
::lCaptured = .f.
::lUpdate = lUpdate
::nStyle = nOR( WS_CHILD, WS_VISIBLE,;
If( lDesign, nOr( WS_CLIPSIBLINGS, WS_TABSTOP ), 0 ) )
::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
if ! Empty( oWnd:hWnd )
::Create()
::Default()
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
if ::lDrag
::CheckDots()
endif
return Self
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, oWnd, cText,nLinea,;
nlenght, oFont, nColortesto,nBorderLine,lBorder,nColorBack,;
nColorBorder ) CLASS TSayjustified
DEFAULT oWnd := GetWndDefault() ,;
nBorderLine := 3 ,;
lBorder := .t. ,;
nLenght := 200
::nId = nId
::oWnd = oWnd
::oFont = oFont
::nLinea = nLinea
::nColortesto = nColortesto
::nLenght = nLenght
::Register()
oWnd:DefControl( Self )
return Self
//----------------------------------------------------------------------------//
METHOD _FillRect( nTop, nLeft, nBottom, nRight, nColor ) CLASS TSayjustified
LOCAL oBrush, hBru, hOld, nMid
hBru := CreateSolidBrush( nColor )
hOld := SelectObject( ::hDC, hBru )
FillRect( ::hDC, { nTop, nLeft, nBottom, nRight }, hBru )
SelectObject( ::hDC, hOld )
DeleteObject( hBru )
RETURN (Nil)
//----------------------------------------------------------------------------//
METHOD Paint() CLASS TSayjustified
Local aRect := GetClientRect( ::hWnd )
Local nMidLine,hPen,hOldPen
Local hDC := ::hDC
* Local aInfo := ::DispBegin()
// IF ::lTransparent
// ::DrawPBack( ::hWnd, hDC )
// ELSE
::_FillRect( aRect[1], aRect[2], aRect[3],aRect[4], ::nColorBack )
// ENDIF
//background
// create array atexto
::FormatText(hDC )
// paint the text
::PainText(hDc,::oFont,::aTexto,::nLenght,::nLinea,::nColorTesto)
If ::lBorder
hPen := CreatePen( 0, ::nBorderLine, ::nColorBorder )
hOldPen := SelectObject( ::hDc, hPen )
nMidLine := ::nBorderLine / 2
MoveTo( ::hDC, nMidLine, nMidLine )
LineTo(::hDC, nMidLine, ::nHeight - nMidLine , hPen )
LineTo(::hDC, ::nWidth - nMidLine, ::nHeight - nMidLine , hPen )
LineTo(::hDC, ::nWidth - nMidLine , nMidLine, hPen )
LineTo(::hDC, nMidLine, nMidLine, 0, hPen )
ENDIF
::oFont:end()
* ::DispEnd( aInfo )
return 0
//----------------------------------------------------------------------------//
METHOD FormatText(hDC) CLASS TSayjustified
LOCAL nCont,nTokn,nCrLf
LOCAL cWord,cLinea,lFinLin
cLinea := ""
DO WHILE !Empty(::cText)
lFinLin := .F.
cLinea := ""
cWord := StrToken(::cText,1)
IF Left(cWord,2) = CRLF
::cText := SubStr(::cText,3)
cWord := ""
cLinea := ""
lFinLin := .T.
ENDIF
nTokn := 0
DO WHILE !Empty(cWord)
cWord := StrToken(::cText,1)
nCrLf := AT( CRLF, cWord )
IF cWord="/" //MORE ...
cWord := CRLF
++nTokn
ENDIF
IF nCrLf > 0
cWord := Left(cWord,nCrLf-1)
lFinLin := .T.
ENDIF
IF GetTextWidth(hDc,cLinea+cWord,::oFont:hFont) > ::nLenght
EXIT
ELSEIF lFinLin
::cText := STUFF(::cText,1,LEN(cWord)+2,"")
cLinea += cWord
++nTokn
EXIT
ELSE
::cText := LTRIM(STUFF(::cText,1,LEN(cWord),""))
cLinea += cWord+" "
++nTokn
ENDIF
ENDDO
AADD( ::aTexto, {RTRIM(cLinea),nTokn,lFinLin} )
ENDDO
ATail(::aTexto)[3] := .T.
return ::aTexto
//----------------------------------------------------------------------------//
METHOD PainText(hDc,oFont,aText,nWidth,nLinea,nColorTesto) CLASS TSayjustified
LOCAL hOldFnt := SelectObject( hDc, oFont:hFont )
LOCAL nCont,nLong,nExtra
FOR nCont = 1 TO LEN(aText)
nLong := GetTextWidth(hDc,aText[nCont,1],oFont:hFont)
nExtra := 0
IF !aText[nCont,3] .AND. Len( aText[nCont,1] ) < (nWidth-nLong)
nExtra := Min( 4, Int((nWidth-nLong)/Len(aText[nCont,1])) )
nExtra := SetTextCharacterExtra( hDc, nExtra )
nLong := GetTextWidth(hDc,aText[nCont,1],oFont:hFont)
ENDIF
IF !aText[nCont,3] .AND. nLong < nWidth
SetTextJustification(hDc, nWidth-nLong, aText[nCont,2]-1)
ENDIF
SetBkMode( hDC, 1 )
SetTextColor( hDC, nColorTesto )
ExtTextOut( hDc, nLinea, 22, {nLinea,22,nLinea+16,22+nWidth}, aText[nCont,1],0 )
nLinea += 18
SetTextJustification(hDc, 0, 0)
SetTextCharacterExtra( hDc, nExtra )
NEXT
SelectObject( hDc, hOldFnt )
return nil
//-----------------------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
HB_FUNC( SETTEXTCHARACTEREXTRA )
{
hb_retni( SetTextCharacterExtra( ( HDC ) hb_parnl( 1 ), ( int ) hb_parni( 2 ) ) ) ;
}
#pragma ENDDUMP
Only I have a problem with the method ::DrawPBack( ::hWnd, hDC ) to make the say transparent
any solution ?
please Antonio ?