Thanks for your feedback.
Code: Select all
#include "hmg.ch"
#include "i_winuser.ch"
*------------------------------------------------------------------------------*
FUNCTION Main
*------------------------------------------------------------------------------*
LOCAL cText := "MULTI-COLOR TEXT"
LOCAL hFont
hFont := GetFontHandle( "Font_Text" )
IF hFont == 0
DEFINE FONT Font_Text FONTNAME "IMPACT" SIZE 48
ENDIF
hFont := GetFontHandle( "Font_Text" )
SET EVENTS FUNCTION TO App_OnEvents
DEFINE WINDOW Form_Main ;
AT 0, 0 ;
WIDTH 600 HEIGHT 400 ;
TITLE cText ;
MAIN ;
ON SIZE InvalidateRect( This.Handle, 0 ) ;
ON MAXIMIZE InvalidateRect( This.Handle, 0 ) ;
ON PAINT App_OnPaint( This.Handle, hFont, cText )
DEFINE STATUSBAR FONT "Arial" SIZE 12
STATUSITEM "Color Text" BACKCOLOR HMG_n2RGB( GetSysColor( COLOR_GRADIENTINACTIVECAPTION ) )
END STATUSBAR
ON KEY ESCAPE ACTION ThisWindow.Release
END WINDOW
CENTER WINDOW Form_Main
ACTIVATE WINDOW Form_Main
RETURN NIL
#define DT_SINGLELINE 32
#define DT_CALCRECT 1024
*------------------------------------------------------------------------------*
FUNCTION App_OnPaint( hWnd, hFont, cText )
*------------------------------------------------------------------------------*
LOCAL aColors := { ;
METRO_LIME, METRO_GREEN, METRO_EMERALD, METRO_TEAL, METRO_CYAN, ;
METRO_COBALT, METRO_INDIGO, METRO_VIOLET, METRO_PINK, METRO_MAGENTA, ;
METRO_CRIMSON, METRO_RED, METRO_ORANGE, METRO_AMBER, METRO_YELLOW, ;
METRO_BROWN, METRO_OLIVE, METRO_STEEL, METRO_MAUVE, METRO_TAUPE }
LOCAL aRect := { 0, 0, 0, 0 }
LOCAL c, n, hDC, nRight, bk
GetClientRectArea( hWnd, aRect )
// Center Statusbar Text
Form_Main.Statusbar.Item( 1 ) := PadC( "Color Text", aRect[ 4 ] / 4 )
hDC := GetDC( hWnd )
// Center Text
n := DrawTextEx( hDC, cText, aRect, DT_SINGLELINE + DT_CALCRECT, hFont, 0, @nRight )
aRect[ 1 ] += ( aRect[ 3 ] - aRect[ 1 ] - n ) / 2
aRect[ 2 ] += Int( ( aRect[ 4 ] - nRight ) / 2 )
// Paint Text
bk := SetBkMode( hDC, 1 )
FOR n := 1 TO Len( cText )
c := SubStr( cText, n, 1 )
DrawTextEx( hDC, c, aRect, DT_SINGLELINE + DT_CALCRECT, hFont, aColors[ n ], @nRight )
DrawTextEx( hDC, c, aRect, DT_SINGLELINE, hFont, aColors[ n ] )
aRect[ 2 ] := nRight
NEXT
SetBkMode( hDC, bk )
ReleaseDC( hWnd, hDC )
RETURN NIL
I've also attached a demo executable for your review.