RAMESHBABU wrote:Hello friends,
As per the subject.
- Ramesh Babu
METHOD SaveToBmp( cBmpFile ) CLASS TWindow
local hBmp := WndBitmap( ::hWnd )
local hDib := DibFromBitmap( hBmp )
DibWrite( cBmpFile, hDib )
GloBalFree( hDib )
DeleteObject( hBmp )
return ( File( cBmpFile ) )
#include "Fivewin.ch"
FUNCTION Main()
LOCAL oWnd
DEFINE WINDOW oWnd TITLE "SaveToBmp"
@ 9, 2 BUTTON "Save To Bmp" ;
SIZE 210, 30 ;
ACTION ( oWnd:SaveToBmp("SavedBmp.Bmp"), MsgInfo("Saved") )
ACTIVATE WINDOW oWnd
RETURN nil
oClipBoard := TClipBoard():New( CF_BITMAP )
oClipBoard:Open()
hBmp := oClipBoard:GetData() // Get handle bitmap
oClipBoard:Close()
hDib := DibFromBitmap( hBmp ) // Write from handle
If Empty( hDib )
MsgInfo("Can't make a bitmap","Error")
RETURN
EndIf
DibWrite( "BmpFile.bmp", hDib )
GlobalFree( hDib )
DeleteObject( hBmp )
BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{
LPBITMAPINFO Info = ( LPBITMAPINFO ) GlobalLock( hDIB );
void huge * Bits = ( void huge * ) ( ( FARP ) Info + Info->bmiHeader.biSize +
wDIBColors( ( LPBITMAPINFOHEADER ) Info ) * sizeof( RGBQUAD ) );
long lSize = GlobalSize( ( HGLOBAL ) Info );
BITMAPFILEHEADER bmf;
int hBmp;
bmf.bfType = 'BM';
bmf.bfSize = sizeof( bmf ) + lSize;
bmf.bfReserved1 = 0;
bmf.bfReserved2 = 0;
bmf.bfOffBits = sizeof( bmf ) + ( FARP ) Bits - ( FARP ) Info;
#ifndef UNICODE
if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
{
_hwrite( hBmp, ( const char * ) &bmf, sizeof( bmf ) );
_hwrite( hBmp, ( const char * ) Info, lSize );
_lclose( hBmp );
GlobalUnlock( hDIB );
return TRUE;
}
#else
if( ( hBmp = hb_fsCreate( ( unsigned char * ) szFileName, 0 ) ) != ( int ) INVALID_HANDLE_VALUE )
{
hb_fsWriteLarge( hBmp, ( unsigned char * ) &bmf, sizeof( bmf ) );
hb_fsWriteLarge( hBmp, ( unsigned char * ) Info, lSize );
hb_fsClose( hBmp );
GlobalUnlock( hDIB );
return TRUE;
}
#endif
else
{
GlobalUnlock( hDIB );
return FALSE;
}
}
//---------------------------------------------------------------------------//
CLIPPER DIBWRITE( PARAMS ) // ( cFileName, hDib ) --> lSuccess
{
_retl( DibWrite( _parc( 1 ), ( HGLOBAL ) _parnl( 2 ) ) );
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 42 guests