A working-sample, to create Buttons ( BMP ) with vertical-text.
- Code: Select all Expand view
oProgFont := TFont():New("Arial", ,-14,.F.,.F., , , ,.F.)
oBfont1 := TFont():New("MS Sans Serif", ,-16, .F. ,.T., , , ,.F.)
DEFINE DIALOG oDlg RESOURCE "Tools" OF oWnd ;
TITLE "BMP-Buttons" FONT oProgFont
// Test.BMP ( Brush not used )
REDEFINE BITMAP oBmp4 ID 210 ADJUST RESOURCE "Blanc" OF oDlg
oBmp4:bLClicked := {|| MsgAlert( "Your Function 1" ) }
oBmp4:bMMoved := { || cursorhand() }
oBMP4:bPainted := { |hDC|OnPaintV( hDC,oBMP4, ;
13003573,15779475,0, ;
"Vertical Button", oBfont1, 0 ,"TEST.BMP" ,4 ) }
REDEFINE BITMAP oBmp5 ID 220 ADJUST RESOURCE "Blanc" OF oDlg
oBmp5:bLClicked := {|| MsgAlert( "Your Function 2" ) }
oBmp5:bMMoved := { || cursorhand() }
oBMP5:bPainted := { |hDC|OnPaintV( hDC,oBMP5, ;
13003573,15779475,0, ;
"Vertical Button", oBfont1, 0 ,"TEST.BMP" ,4 ) }
REDEFINE BITMAP oBmp6 ID 230 ADJUST RESOURCE "Blanc" OF oDlg
oBmp6:bLClicked := {|| MsgAlert( "Your Function 3" ) }
oBmp6:bMMoved := { || cursorhand() }
oBMP6:bPainted := { |hDC|OnPaintV( hDC,oBMP6, ;
13003573,15779475,0, ;
"Vertical Button", oBfont1, 0 ,"TEST.BMP" ,4 ) }
ACTIVATE DIALOG oDlg CENTERED NOWAIT ;
ON INIT ( oDlg:Move( 70 , 50, oDlg:nWidth, oDlg:nHeight, .f.,) )
RETURN NIL
//------------------- VERTICAL ---------------------------------------------//
FUNCTION ONPAINTV(hDC,oBmp,nVColor, nBColor,nColor,cText, ;
oBfont1,nLEFT, cBRUSH, nPEN)
LOCAL hOldFont, oNewbrush
xDFONT := e_oBfont1
hOldFont := SelectObject( hDC, oBfont1:hFont )
nTOP := 5
nTXTLG := GettextWidth( hDC, cText )
nBMPWIDTH := oBmp:Super:nWidth()
nBMPLONG := oBmp:Super:nHeight()
nFONTHIGHT := oBfont1:nInpHeight * -1
nFONTWIDTH := INT( e_oBfont1:nSize() )
nLEFT := (nBMPWIDTH - nTXTLG) / 2
aRect := GETCLIENTRECT( oBmp:hWnd )
// .T. Horizontal
nGRADIENT := Gradient( hDC, aRect, nVColor, nBColor, .T. )
oBmp:oBrush := TBrush():New( , nGRADIENT )
FillRect( hDC, aRect, oBmp:oBrush:hBrush )
SetBkMode( hDC, 0 ) // 1 = Transparent
SetTextColor( hDC,nColor)
nTOP := nFONTHIGHT / 2
i := 1
nBMPWIDTH1 := nBMPWIDTH / 2
FOR i := 1 to len(cTEXT)
cCHAR := SUBSTR(cTEXT,i,1)
nCharWidth := GettextWidth( hDC, cCHAR )
TextOut( hDC, nTOP, nBMPWIDTH1 - ( nCharWidth / 2 ), cCHAR )
IF !empty(cCHAR)
nTOP := nTOP + nFONTHIGHT
ELSE
nTOP := nTOP + ( nFONTHIGHT / 2 )
ENDIF
NEXT
SelectObject( hDC, hOldFont )
nColor1 := 128 // Border-Color
IF nPEN > 0
DRAWBOX( aRect, hDC, nColor1, ;
nBMPLONG, nBMPWIDTH, nPEN )
ENDIF
RETURN NIL
// ----------------------------------------
STATIC FUNCTION DRAWBOX( aRect, hDC, nColor1, ;
nBMPLONG, nBMPWIDHT, nPEN )
LOCAL hPen := CREATEPEN( PS_SOLID, nPEN, nColor1 )
LOCAL hOldPen := SELECTOBJECT( hDC, hPen )
MOVETO( hDC, 0, 0 )
LINETO( hDC, nBMPLONG, 0 )
LINETO( hDC, nBMPWIDHT, nBMPLONG )
LINETO( hDC, 0, nBMPLONG )
LINETO( hDC, 0, 0 )
DELETEOBJECT( hPen )
RETURN NIL
Regards
Uwe