#include "FiveWin.ch"
#include "Image.ch"
//----------------------------------------------------------------------------//
function Main()
LOCAL oDlg, oImage
LOCAL gcFile
DEFINE DIALOG oDlg FROM 0, 0 TO 22, 60 ;
TITLE FWDESCRIPTION + " JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"
@ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg SCROLL ADJUST
ZoomZone():New( oImage )
oImage:Progress( .f. )
@ 1, 28 BUTTON "Select Image" SIZE 50,10 OF oDlg ACTION gcFile := GetImage( oImage )
@ 2, 28 BUTTON "Reload" SIZE 50,10 OF oDlg ACTION If( gcFile != NIL, oImage:LoadBmp( gcFile ), )
ACTIVATE DIALOG oDlg CENTER
return nil
//----------------------------------------------------------------------------//
function GetImage( oImage )
local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" + ;
"DIB (*.dib)| *.dib|" + ;
"PCX (*.pcx)| *.pcx|" + ;
"JPEG (*.jpg)| *.jpg|" + ;
"GIF (*.gif)| *.gif|" + ;
"TARGA (*.tga)| *.tga|" + ;
"RLE (*.rle)| *.rle|" + ;
"All Files (*.*)| *.*" ;
,"Please select a image file", 4 )
if ! Empty( gcFile ) .and. File( gcFile )
oImage:LoadBmp( gcFile )
endif
return gcFile
//----------------------------------------------------------------------------//
function PrintImage( oImage )
local oPrn
PRINT oPrn NAME "Image Printing" PREVIEW
PAGE
oPrn:SayImage( 0, 0, oImage )
ENDPAGE
ENDPRINT
return nil
//----------------------------------------------------------------------------//
#define SRCCOPY 0x00CC0020
CLASS ZoomZone
DATA oImage
DATA nRow, nCol
DATA lPressed
METHOD New()
METHOD LButtonDown( nRow, nCol )
METHOD LButtonUp( nRow, nCol )
METHOD SelectZone( nRow, nCol )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( oImage ) CLASS ZoomZone
::oImage = oImage
::lPressed = .F.
oImage:bMMoved = {| nRow, nCol | ::SelectZone( nRow, nCol ) }
oImage:bLClicked = {| nRow, nCol | ::LButtonDown( nRow, nCol ) }
oImage:bLButtonUp = {| nRow, nCol | ::LButtonUp( nRow, nCol ) }
RETURN Self
//----------------------------------------------------------------------------//
METHOD LButtonDown( nRow, nCol ) CLASS ZoomZone
::nRow = nRow
::nCol = nCol
::lPressed = .T.
RETURN nil
//----------------------------------------------------------------------------//
METHOD LButtonuP( nRow, nCol ) CLASS ZoomZone
local hBmp, hBmpOld
local hDCDesk := GetDC( GetDesktopWindow() )
local hDCMem := CreateCompatibleDC( hDCDesk )
local hDCImg := ::oImage:GetDC()
local nLowRow, nHiRow, nLowCol, nHiCol
hBmp = CreateCompatibleBitmap( hDCDesk, ::oImage:nWidth, ::oImage:nHeight )
hBmpOld = SelectObject( hDCMem, hBmp )
if ::nRow > nRow
nLowRow = nRow + 1
nHiRow = ::nRow
else
nLowRow = ::nRow + 1
nHiRow = nRow
endif
if ::nCol > nCol
nLowCol = nCol + 1
nHiCol = ::nCol
else
nLowCol = ::nCol + 1
nHiCol = nCol
endif
StretchBlt( hDCMem, 0, 0, ::oImage:nWidth, ::oImage:nHeight, ;
hDCImg, nLowCol, nLowRow, nHiCol - nLowCol, nHiRow - nLowRow, SRCCOPY )
SelectObject( hDCMem, hBmpOld )
DeleteObject( ::oImage:hBitmap )
::oImage:hBitmap = hBmp
DeleteDC( hDCMem )
ReleaseDC( GetDesktopWindow(), hDCDesk )
::oImage:ReleaseDC()
::lPressed = .F.
::oImage:Refresh()
RETURN nil
//----------------------------------------------------------------------------//
METHOD SelectZone( nRow, nCol ) CLASS ZoomZone
local hDC
::oImage:Refresh()
SysRefresh()
hDC := ::oImage:GetDC()
if ::lPressed
DrawDotedBox( hDC, ::nRow, ::nCol, nRow , nCol, 0 )
endif
::oImage:ReleaseDC()
RETURN NIL
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
void WndDrawBox( HDC hDC, RECT * rct, HPEN hPUpLeft, HPEN hPBotRit );
HB_FUNC( DRAWDOTEDBOX ){
RECT rct;
COLORREF color = ( COLORREF ) hb_parnl( 6 );
HPEN hPen = CreatePen( PS_DOT, 1, color );
rct.top = hb_parni( 2 );
rct.left = hb_parni( 3 );
rct.bottom = hb_parni( 4 );
rct.right = hb_parni( 5 );
WndDrawBox( ( HDC ) hb_parnl( 1 ), &rct, hPen, hPen );
DeleteObject( hPen );
}
#pragma ENDDUMP
//----------------------------------------------------------------------------//