Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OLEDragDrop GetData() in BMP/WAV format?
Message
From
24/05/2005 16:08:12
 
 
To
24/05/2005 14:22:03
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01016102
Message ID:
01017255
Views:
77
Herman!

Yes!!! AWESOME! Your code rocks! Thank you very, very much!!! :)

3 more stars: * * * !

For those following this thread, jump to the end of this reply for a repeat of Herman's code and some extra support functions.

There's one little tweak left to do and I strongly believe it may be related to Office apps vs. your code. As presently coded, the images get converted to a 256 color palette. My guess is that this is Word doing the conversion. The reason I believe this is if I copy and paste a Word image into MS Paint, the MS Paint image is more than twice the size of raw image data we receive in a DIB via .GetData( CF_DIB ).

Example:

Saved as 24 color BMP via Paint: 17,334
Saved as BMP created from Word DIB: 6,838 (256 color palette)

Note: I recieved the same result regardless of how I pasted (Edit/Paste Special) my source images into Word: bitmap, Windows Metafile, or DIB all resulted in a palette conversion being performed by Word.

Herman Tan's code follows (place in OLEDragDrop drop target control and set its OLEDropMode to 1).
* comment out if Foxpro.h is part of #include stream
#define CF_DIB 8

lcData = oDataObject.GetData( CF_DIB )
nBISize = DWord2Num( substr( lcData, 1, 4 )) + DWord2Num( substr( lcData, 21, 4 ))
nBPP = Word2Num( substr( lcData, 15, 2 ))
If (nBPP < 24)
   nColorUsed = DWord2Num( substr( lcData, 33, 4 )) * 4
   nBISize = nBISize + nColorUsed
   cBmpData = 'BM' + Num2DWord(14 + nBISize ) + replicate( chr(0), 4 ) + ;
      Num2DWord( 54 + nColorUsed ) + left( lcData, nBISize )
else
   cBmpData = 'BM' + Num2DWord(14 + nBISize ) + replicate( chr(0), 4 ) + ;
      Num2DWord( 54 ) + left( lcData, nBISize )
endif
Set safety off
StrToFile( cBmpData, 'Test.BMP' )
Set safety on
For those following this thread, here are extra functions you need to try Herman's code.
set procedure to winapi.prg

Then place this in your winapi.prg program:

* From: http://www.tek-tips.com/viewthread.cfm?qid=747858
function DWord2Num( pcBuffer )
   local lnValue 
   lnValue = asc( substr( pcBuffer, 1, 1 ) ) + ;
      asc(substr( pcBuffer, 2, 1 ) ) * 256 + ;
      asc(substr( pcBuffer, 3, 1 ) ) * 65536 + ;
      asc(substr( pcBuffer, 4, 1 ) ) * 16777216

   return lnValue
endFunc

* Modified version of DWordNum().
function Word2Num( pcBuffer )
   local lnValue
   lnValue = asc( substr( pcBuffer, 1, 1 ) ) + ;
      asc(substr( pcBuffer, 2, 1 ) ) * 256
      
   return lnValue
endFunc

* Based on : http://fox.wikis.com/wc.dll?Wiki~LightweightApiStructures~VFP
function Num2DWord( pnValue )
    local lnByte0, lnByte1, lnByte2, lnByte3
    lnByte3 = int( pnValue / 16777216 )
    lnByte2 = int( ( pnValue - lnByte3 * 16777216 )/ 65536 )
    lnByte1 = int( ( pnValue - lnByte3 * 16777216  - lnByte2 * 65536 )/ 256 )
    lnByte0 = mod( pnValue, 256 )
    return chr( lnByte0 ) + chr( lnByte1 ) + chr( lnByte2 ) + chr( lnByte3 )
endfunc
Herman, thanks again for all your hard work on this thread!!!

Malcolm
Malcolm Greene
Brooks-Durham
mgreene@bdurham.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform