FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Thu Oct 11, 2007 01:24 PM

Hello friends,

As per the subject.

  • Ramesh Babu
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Re: How to save the Wndcopy()'s Clipboard's output to a BMP
Posted: Thu Oct 11, 2007 02:09 PM
RAMESHBABU wrote:Hello friends,

As per the subject.

- Ramesh Babu


Ramesh,

oWnd:SaveToBmp( "mibmp.bmp" )
William, Morales

Saludos



méxico.sureste
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Thu Oct 11, 2007 04:35 PM

Hello Mr. Wmormar

This is not that much simple. At least in FWH 2.8 xHarbour (0.99.71 Simplex) !.

Which version of FWH and xHarbour you are using and you got it working?

I have used several methods to achive this well with in FWH. But I did
not suceeed. I had to adopt a long work around to achive this.

Thanks for your response.

  • Ramesh Babu P
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Thu Oct 11, 2007 05:01 PM
Ramesh,

METHOD SaveToBmp( cBmpFile ) CLASS TWindow

   local hBmp := WndBitmap( ::hWnd )
   local hDib := DibFromBitmap( hBmp )

   DibWrite( cBmpFile, hDib )
   GloBalFree( hDib )
   DeleteObject( hBmp )

return ( File( cBmpFile ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Thu Oct 11, 2007 08:11 PM

Antonio,

Is that saving a bitmap snapshot of the window to a BMP file?

I think Ramesh wants to save a bitmap that is in the clipboard to a file. Is that right Ramesh?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Fri Oct 12, 2007 01:19 AM
Mr.Antonio

Thanks for your attention.

The following code is a "savedbmp.bmp" with only 14 bytes !.

#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



As Mr.James said, I need to save the contents of clipboard to a BMP file.

I am using FWH 2.8 (Sep. build) + xHarbour 0.99.71 (Simplex)

This was working very well in our earlier versioins. But it is not working.

And I have come across several postings on our forum with the same
complaint that they are getting a saved BMP file only with 14 bytes.

Currently I have adopted a very long work around using some 3 party utilitys to achive this result.

Plase do help.


- Ramesh Babu P
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Fri Oct 12, 2007 06:13 AM

Ramesh,

Your code is working fine here using FWH 7.10 and Vista Ultimate 32 bits:

Using Harbour:
10/12/2007 08:12 1,168 b32.bc
10/12/2007 08:11 0 clip.log
10/12/2007 08:12 630,074 SavedBmp.Bmp
10/12/2007 08:11 4,694 test.c
10/12/2007 08:12 1,086,976 test.exe
10/12/2007 08:12 373,443 test.map
10/12/2007 08:12 2,096 test.obj
10/12/2007 08:11 1,147 test.ppo
10/12/2007 08:11 293 test.prg
10/12/2007 08:12 458,752 test.tds
10 File(s) 2,558,643 bytes

Using xHarbour:
10/12/2007 08:16 <DIR> .
10/12/2007 08:16 <DIR> ..
10/12/2007 08:16 964 b32.bc
10/12/2007 08:16 480 clip.log
10/12/2007 08:16 630,074 SavedBmp.Bmp
10/12/2007 08:16 1,278,464 test.exe
10/12/2007 08:16 435,917 test.map
10/12/2007 08:16 10,604 test.obj
10/12/2007 08:16 1,253 test.ppo
10/12/2007 08:11 293 test.prg
10/12/2007 08:16 655,360 test.tds
9 File(s) 3,013,409 bytes

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Fri Oct 12, 2007 08:27 AM
Mr.Antonio

As I have already pointed, the same functionality was working OK prior to
FWH 2.8 and it stopped working in 2.8 I don't know why.

Can you please check with FWH 2.8 (Sep. build) + xHarbour 0.99.71 (Simplex) and suggest me any way out ?

For your information, we have spoken several times in the forum earlier on
the same issue. And you said the same thing. I hope atleast this time so
will suggest me a way out. Because the working around way I am following presently is not giving the expected result some times and I am
facing problems.

My previous posting on the same subject for your reference:

http://fivetechsoft.com/forums/viewtopi ... t=save2bmp
" rel="noopener">
http://fivetechsoft.com/forums/viewtopi ... t=save2bmp


Thanks

- Ramesh Babu P
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Fri Oct 12, 2007 09:31 AM

Ramesh,

> Can you please check with FWH 2.8 (Sep. build)

We can't provide tech support for 2.8 september year 2006. There have been lots of changes both in Harbour/xHarbour and FWH. Please understand it.

We can only suggest you to upgrade to FWH 7.10

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Fri Oct 12, 2007 04:25 PM
Ramesh,

Try this:

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 )
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Sat Oct 13, 2007 09:56 AM

Mr.James

Thank you very much for your support.

Actually the DibWrite(...) function it self not functioning properly.
It is generating a BMP file with only 14 bytes !. I have tried several
ways including yours.

Still the same problem.

Thank you once again.

  • Ramesh Babu P
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Sat Oct 13, 2007 11:07 AM

Ramesh,

Please copy here the source code of your FWH DibWrite(), thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Sat Oct 13, 2007 11:35 AM
Mr.Antonio

Thank you very much for not leaving me in vain.

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 ) ) ); 
}


Please look into it and suggest me, if any thing is to be modified.

Thank you once again,

- Ramesh Babu P

FWH 2.8 (Sep Build) + xHarbour 0.99.71 (Simplex)
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Sat Oct 13, 2007 11:40 AM

It seems identical to the one in the current FWH release.

EMG

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to save the Wndcopy()'s Clipboard's output to a BMP ?
Posted: Sat Oct 13, 2007 11:42 AM

Ramesh,

Please email it to me, the entire dib.c, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com