#include "FiveWin.ch"
#include "constant.ch"
Static c_Path
Static c_Path1
Function Main()
local oWnd
local oBtn[10]
local oTextFont
local cImage := "Logo.png"
local nLeft := 10
local nTop := 10
local oBmp
local oImg1
local oImg2
local oImg3
local lIni := .T.
c_Path := cFilePath(GetModuleFileName( GetInstance() ) )
c_Path1 := c_Path + "IMAGES\"
DEFINE IMAGE oBmp FILENAME c_path1 + "Back.png"
oTextFont := TFont():New( "Arial", 0, 20,.F.,.F., 0, 0, 0,.F.,.F.)
DEFINE WINDOW oWnd FROM 10, 10 TO 700, 900 TITLE "GDI+ TEST" PIXEL // ;
// STYLE WS_POPUP BRUSH oBrush1
oWnd:bRClicked := {|| oWnd:End() }
@ oWnd:nHeight - 100, oWnd:nWidth - 370 BTNBMP oBtn[1] SIZE 100, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Paint.bmp" ;
LEFT ;
PROMPT "&Paint 1" ;
FONT oTextFont ;
ACTION ( cImage := "Logo.png", ; //nLeft := 500, nTop := 10, ;
oImg1 := DRAWIMAGE(oWnd, cImage, 500, 10 ) )
oBtn[1]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 10526975, 16777215 }, ;
{ 0.5, 16777215, 10526975 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[1]:nLayout := 2
oBtn[1]:SetColor( 128 )
oBtn[1]:cTooltip := { "Exit" + CRLF + ;
"GDI-test","EXIT", 1, CLR_BLACK, 14089979 }
@ oWnd:nHeight - 100, oWnd:nWidth - 260 BTNBMP oBtn[2] SIZE 100, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Paint.bmp" ;
LEFT ;
PROMPT "&Paint 2" ;
FONT oTextFont ;
ACTION ( cImage := "Logo.png", ; //nLeft := 250, nTop := 250, ;
oImg2 := DRAWIMAGE( oWnd, "Logo.png", 250, 250 ) )
oBtn[2]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 10526975, 16777215 }, ;
{ 0.5, 16777215, 10526975 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[2]:nLayout := 2
oBtn[2]:SetColor( 128 )
oBtn[2]:cTooltip := { "Image 2" + CRLF + ;
"test","TEST", 1, CLR_BLACK, 14089979 }
// -------------
@ oWnd:nHeight - 100, 20 BTNBMP oBtn[6] SIZE 110, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Color.bmp" ;
LEFT ;
PROMPT "&Color" ;
FONT oTextFont ;
ACTION DRAW_BACK( oWnd, 1, 3194624 )
oBtn[6]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 16765863, 16777215 }, ;
{ 0.5, 16777215, 16765863 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[6]:nLayout := 2
oBtn[6]:SetColor( 128 )
oBtn[6]:cTooltip := { "use color" + CRLF + ;
"Background","COLOR", 1, CLR_BLACK, 14089979 }
@ oWnd:nHeight - 100, 135 BTNBMP oBtn[7] SIZE 110, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Gradient.bmp" ;
LEFT ;
PROMPT "&Gradient" ;
FONT oTextFont ;
ACTION DRAW_BACK( oWnd, 2, 16762767, 16773088, .T., 0.5 )
oBtn[7]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 16765863, 16777215 }, ;
{ 0.5, 16777215, 16765863 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[7]:nLayout := 2
oBtn[7]:SetColor( 128 )
oBtn[7]:cTooltip := { "use Gradient" + CRLF + ;
"Background","GRADIENT", 1, CLR_BLACK, 14089979 }
@ oWnd:nHeight - 100, 250 BTNBMP oBtn[8] SIZE 110, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Brush.bmp" ;
LEFT ;
PROMPT "&Brush" ;
FONT oTextFont ;
ACTION DRAW_BACK( oWnd, 3, , , , , "Brush.bmp" )
oBtn[8]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 16765863, 16777215 }, ;
{ 0.5, 16777215, 16765863 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[8]:nLayout := 2
oBtn[8]:SetColor( 128 )
oBtn[8]:cTooltip := { "use Brush" + CRLF + ;
"Background","BRUSH", 1, CLR_BLACK, 14089979 }
@ oWnd:nHeight - 100, 365 BTNBMP oBtn[9] SIZE 110, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Image.bmp" ;
LEFT ;
PROMPT "&Image" ;
FONT oTextFont ;
ACTION DRAW_BACK( oWnd, 4, , , , , ,"Backgrd.jpg" )
oBtn[9]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 16765863, 16777215 }, ;
{ 0.5, 16777215, 16765863 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[9]:nLayout := 2
oBtn[9]:SetColor( 128 )
oBtn[9]:cTooltip := { "use Image" + CRLF + ;
"Background","IMAGE", 1, CLR_BLACK, 14089979 }
@ oWnd:nHeight - 100, oWnd:nWidth - 150 BTNBMP oBtn[10] SIZE 100, 50 OF oWnd 2007 ;
FILENAME c_path1 + "Exit.bmp" ;
LEFT ;
PROMPT "&Exit" ;
FONT oTextFont ;
ACTION oWnd:End()
oBtn[10]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
{ { 0.5, 10526975, 16777215 }, ;
{ 0.5, 16777215, 10526975 } }, ;
{ { 0.5, 16768185, 16777215 }, ;
{ 0.5, 16777215, 16768185 } } ) }
oBtn[10]:nLayout := 2
oBtn[10]:SetColor( 128 )
oBtn[10]:cTooltip := { "Exit" + CRLF + ;
"GDI-test","EXIT", 1, CLR_BLACK, 14089979 }
//oWnd:bPainted := {|| DRAWIMAGE(oWnd, cImage, nLeft, nTop ) }
ACTIVATE WINDOW oWnd CENTER ;
ON INIT ( oImg3 := DRAWIMAGE( oWnd, cImage, nLeft, nTop ) ) ;
ON PAINT ( ABPaint( oWnd:hDC, 30, 30, oBmp:hBitmap, 255 ), ;
if( !lIni, ( DrawImage( oWnd, oImg1, 500, 10 ),;
DrawImage( oWnd, oImg2, 250, 250 ),;
DrawImage( oWnd, oImg3, nLeft, nTop ) ), lIni := .F. ) ) //;
oTextFont:End()
RETURN NIL
// -------------
FUNCTION DRAWIMAGE( oWnd, cImage, nLeft, nTop )
local hDC := oWnd:GetDc()
local cNew
local oGraphics := Graphics():New( oWnd:hDC )
local oImage
if Valtype( cImage ) = "C"
cNew := c_Path1 + cImage
oImage := GDIBmp():New( cNew )
else
oImage := cImage
endif
if !Empty( oImage )
oGraphics:DrawImage( oImage, nTop, nLeft ) //, nTop )
oGraphics:Destroy()
endif
oWnd:ReleaseDc()
Return oImage
// -------- Background ---------------
FUNCTION DRAW_BACK( oWnd, nStyle, nColor1, nColor2, lDirect, nMove, cBrush, cImage )
local hDC
local oBrush
local oImage
local aGrad
local aRect := GETCLIENTRECT( oWnd:hWnd )
local hBmp
local hBmpOld
IF nStyle = 1 // COLOR
DEFINE BRUSH oBrush COLOR nColor1
ENDIF
IF nStyle = 2 // GRADIENT
aGrad := { { nMove, nColor1, nColor2 }, { nMove, nColor2, nColor1 } }
hDC = CreateCompatibleDC( oWnd:GetDC() )
hBmp = CreateCompatibleBitMap( oWnd:hDC, aRect[4], aRect[3] )
hBmpOld = SelectObject( hDC, hBmp )
GradientFill( hDC, 0, 0, aRect[3], aRect[4], aGrad, lDirect )
oBrush := TBrush():New( ,,,, hBmp )
oBrush:Cargo := aGrad
SelectObject( hDC, hBmpOld )
ReleaseDC(hDC)
ENDIF
IF nStyle = 3 // BMP-BRUSH
IF FILE( c_path1 + cBrush )
DEFINE BRUSH oBrush FILE c_path1 + cBrush
ELSE
IF !EMPTY(cImage)
MsgAlert( "File : " + cBrush + CRLF + ;
"does not exist" + CRLF + ;
"to create Background !", "ATTENTION" )
ENDIF
ENDIF
ENDIF
IF nStyle = 4 // Image ADJUSTED
IF FILE( c_path1 + cImage )
DEFINE IMAGE oImage FILE c_path1 + cImage
oBrush := TBrush():new( ,,,, ResizeBmp( oImage:hBitmap, aRect[4], aRect[3], .T. ) )
oImage:End()
ELSE
IF !EMPTY(cImage)
MsgAlert( "File : " + cImage + CRLF + ;
"does not exist" + CRLF + ;
"to create Background !", "ATTENTION" )
ENDIF
ENDIF
ENDIF
oWnd:Setbrush( oBrush )
oBrush:End()
RETURN( NIL)