#include "FiveWin.ch"
#define CLR_MSPURPLE RGB( 128, 57, 123 )
#define CLR_MSRED RGB( 232, 17, 35 )
#define CLR_MSGRAY RGB( 229, 229, 229 )
#define TME_LEAVE 2
STATIC c_path, c_path1
FUNCTION MAIN()
LOCAL oWnd, nRowPos, nColPos, oBtnClose, oBtnMax, oBtnMin, lDrag := .F., lRResize := .F., lBResize := .F.
LOCAL nWidth := 500, nNewWidth := 500, nHeight := 300, nNewHeight := 300
LOCAL nFactorW := 1, nFactorH := 1, lWZoomed
LOCAL nImgRow := 40, nImgCol := 40
LOCAL nImgSpace := 16, nLeftPos, nRightPos
c_path := cFilePath(GetModuleFileName( GetInstance() ) )
c_path1 := c_path + "BITMAPS\"
DEFINE WINDOW oWnd STYLE WS_POPUP COLOR CLR_BLACK, CLR_MSPURPLE
oWnd:SetSize( nWidth, nHeight )
oWnd:Center()
oWnd:Shadow()
oWnd:bPainted = { || oWnd:Say( 8, 30, "Caption", CLR_WHITE, CLR_MSPURPLE, oWnd:oFont, .T., .T. ) }
oWnd:bPainted := { || oWnd:Say( 8, 30, "Width - Factor : " + ALLTRIM(STR( nNewWidth )) + " = " + ALLTRIM(STR( nFactorW )) + ;
" Height - Factor : " + ALLTRIM(STR( nNewHeight )) + " = " + ALLTRIM(STR( nFactorH )) + ;
" ( " + ALLTRIM(STR( nWidth )) + " x " + ALLTRIM(STR( nHeight )) + " ) ", ;
CLR_WHITE, CLR_MSPURPLE, oWnd:oFont, .T., .T. ), ;
SHOW_IMG( oWnd, nImgRow, nImgCol, nImgSpace, nFactorW, nFactorH, lWZoomed ) }
oWnd:bLClicked = { | nRow, nCol | If( nRow < 25, ( oWnd:Capture(), nRowPos := nRow, nColPos := nCol, lDrag := .T. ),),;
If( nRow > 25 .and. nCol > oWnd:nWidth - 25, ( oWnd:Capture(), nRowPos := nRow, nColPos := nCol, lRResize := .T. ),),;
If( nRow > 25 .and. nRow > oWnd:nHeight - 25, ( oWnd:Capture(), nRowPos := nRow, nColPos := nCol, lBResize := .T. ),) }
oWnd:bMMoved = { | nRow, nCol | TrackMouseEvent( oWnd:hWnd, TME_LEAVE ),;
If( lDrag .and. ! IsZoomed( oWnd:hWnd ) .and. IsOverWnd( oWnd:hWnd, nRow, nCol ),;
oWnd:Move( oWnd:nTop + nRow - nRowPos, oWnd:nLeft + nCol - nColPos,,, .T. ),),;
If( lRResize .and. ! IsZoomed( oWnd:hWnd ) .and. IsOverWnd( oWnd:hWnd, nRow, nCol ),; // width
( oWnd:SetSize( oWnd:nWidth + nCol - nColPos, oWnd:nHeight, .T. ), nColPos := nCol,;
nNewWidth := oWnd:nWidth(), nFactorW := nNewWidth / nWidth, lWZoomed := .T. ),),;
If( lBResize .and. ! IsZoomed( oWnd:hWnd ) .and. IsOverWnd( oWnd:hWnd, nRow, nCol ),; // height
( oWnd:SetSize( oWnd:nWidth, oWnd:nHeight + nRow - nRowPos, .T. ), nRowPos := nRow,;
nNewHeight := oWnd:nHeight(), nFactorH := nNewHeight / nHeight, lWZoomed := .F. ),) }
oWnd:bLButtonUp = { || ReleaseCapture(), lDrag := .F., lRResize := .F., lBResize := .F. }
oWnd:bMLeave = { || lDrag := .F. }
@ 1, oWnd:nWidth - 46 BTNBMP oBtnClose BITMAP c_path1 + "closew.png" ;
FLAT NOBORDER NOROUND ACTION oWnd:End() SIZE 32, 32 ;
COLOR CLR_BLACK, CLR_MSPURPLE
@ 1, oWnd:nWidth - 92 BTNBMP oBtnMax BITMAP c_path1 + "max.png" ;
FLAT NOBORDER NOROUND ACTION If( ! IsZoomed( oWnd:hWnd ), oWnd:Maximize(), oWnd:Restore() ) SIZE 32, 32 ;
COLOR CLR_BLACK, CLR_MSPURPLE
@ 1, oWnd:nWidth - 138 BTNBMP oBtnMin BITMAP c_path1 + "min.png" ;
FLAT NOBORDER NOROUND ACTION If( ! IsIconic( oWnd:hWnd ), oWnd:Iconize(), oWnd:Restore() ) SIZE 32, 32 ;
COLOR CLR_BLACK, CLR_MSPURPLE
oBtnClose:bMMoved = { || oBtnClose:SetColor( CLR_BLACK, If( oBtnClose:lMOver, CLR_MSRED, oWnd:nClrPane ) ) }
oBtnMax:bMMoved = { || oBtnMax:SetColor( CLR_BLACK, If( oBtnMax:lMOver, CLR_MSGRAY, oWnd:nClrPane ) ) }
oBtnMin:bMMoved = { || oBtnMin:SetColor( CLR_BLACK, If( oBtnMin:lMOver, CLR_MSGRAY, oWnd:nClrPane ) ) }
oWnd:bResized = { || oBtnClose:Move( 1, oWnd:nWidth - 45 ), oBtnMax:Move( 1, oWnd:nWidth - 75 ),;
oBtnMin:Move( 1, oWnd:nWidth - 105 ) }
ACTIVATE WINDOW oWnd
RETURN NIL
// --------------------
FUNCTION SHOW_IMG( oWnd, nImgRow, nImgCol, nImgSpace, nFactorW, nFactorH, lWZoomed )
LOCAL oGraphics := Graphics():New( oWnd:hDC )
LOCAL oImage := GDIBmp():New( c_path1 + "Olga.jpg" )
LOCAL nTop, nLeft
LOCAL nWidth := oImage:GetWidth(), nHeight := oImage:GetHeight(), nSpace := 1
LOCAL nFactor := nFactorW
IF lWZoomed = .F. // vertical resize selected
nFactor := nFactorH
ENDIF
nTop := nImgRow * nFactor
nLeft := nImgCol * nFactor
nSpace := nImgSpace * nFactor
// 1. Image
oGraphics:DrawImage( oImage, nTop, nLeft, nWidth * nFactor, nHeight * nFactor )
nImgCol := oImage:GetWidth() + nSpace
nTop := nImgRow * nFactor
nLeft := nLeft + nSpace + ( nWidth * nFactor )
oGraphics:destroy()
// 2. Image
oGraphics := Graphics():New( oWnd:hDC )
oGraphics:DrawImage( oImage, nTop, nLeft, nWidth * nFactor, nHeight * nFactor )
oGraphics:destroy()
RETURN NIL