Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OLEDragDrop GetData() in BMP/WAV format?

Status
Not open for further replies.

awaresoft

Programmer
Joined
Feb 16, 2002
Messages
373
Location
DE
Anyone have any suggestions on how I can use the oDataObject.GetData() to retrieve binary BMP and WAV data dragged from another application?

I can successfully recognize data in BMP and WAV format via

oDataObject.GetFormat( 2 ) && binary BMP data (CF_BITMAP)
oDataObject.GetFormat( 12 ) && binary WAV data (CF_WAVE)

But ... I can't figure out how to retrieve this info once I've detected it:

For example:

oDataObject.GetData( 2 ) returns .F.

and

local laData[ 1 ]
oDataObject.GetData( 2, @laData )

doesn't change the default .F. value in laData.

I'm also looking for a way to place binary BMP and WAV data in oDataObject so users can drag this type of info out of my application and back to their original applications.

Any suggestions?

Malcolm
 
It might be evident to you but what is "oDataObject.GetData()". Where does this method come from?
The are may API calls on that allow you to retrieve information on BMP and WAV file.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

oDataObject is the object passed to an OLEDragDrop drop target when a user drops what they've been dragging. The drop target's OLEDragDrop event gets passed this parameter.

The GetFormat() and GetData() methods of the oDataObject return (respectively) a logical value if data in the specified format is present in oDataObject and the actual data itself in a specified format.

News2News has functions for working with the clipboard, but it does not discuss how to do OLEDragDrop except with files.

Malcolm
 
The GetFormat() and GetData() methods of the oDataObject return (respectively) a logical value if data in the specified format is present in oDataObject and the actual data itself in a specified format.

According to MS the values are not logical.

oDataObject

An object reference to OLE drag-and-drop DataObject, used with the GetData and GetFormat methods to return data and data formats in the DataObject.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

Well the MS documentation is poorly written in this case.

oDataObject.GetFormat( nFormat | cFormat ) returns a boolean value. Always.

oDataObject.GetData( nFormat | cFormat [, @aArray ) returns data if the format type is simple (ie. strings) and a boolean value if the data type is complex and the data is being passed by reference in the aArray parameter. In this later case, the boolean return is True if the requested data was placed in aArray or False otherwise.

I have my OLEDragDrop sequences working great with strings and files. Now I would like my program to do a little bit more than the standard string/file type of data, i.e. where the data in the oDataObject is raw BMP or WAV content.

I can properly detect that BMP or WAV content is present in the oDataObject. I just can't figure out how to extract this data. I'm beginning to think I'll need to try using the Windows API directly.

Thanks for your help,

Malcolm
 
I'm beginning to think I'll need to try using the Windows API directly.

You could also use GDI+ which also has both of these methods. Can I ask what it is you are trying to achieve? Once you drop a bitmap onto your form and discovered that it is indeed a bitmap, and you are able to retrieve the binary information of the file, what do you plan to do with it?



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
> Can I ask what it is you are trying to achieve?

My application helps users organize and prepare information for audit reports. Some of the content that they enter into my system may come from Word or PowerPoint documents prepared by others. My users would like to be able to drag and drop info (text, images, audio) from these files to my application. They already do this now for moving blocks of text and it works great.

In both the case of BMP and WAV data, I would like my application to convert the binary versions of this data to to files managed by my application and referenced in the paper/PDF, HTM, or PowerPoint output generated by my application.

I recognize that this could go thru the clipboard which will be a fallback approach for me. However, I was hoping to offer my users the same, consistent and seamless approach to moving data regardless of the data's underlying data format. That's suppossed to be the promise of OLEDragDrop and I would like to support it if at all possible.

I feel I'm so close ... just need to grab data that I know is there ...

Thanks again for helping me out on this post, Mike,

Malcolm
 
I recognize that this could go thru the clipboard which will be a fallback approach for me. However, I was hoping to offer my users the same, consistent and seamless approach to moving data regardless of the data's underlying data format. That's suppossed to be the promise of OLEDragDrop and I would like to support it if at all possible.

I don't see this promise being made anywhere in this link

I see that the nFormat paremeter specifies the format number (ie. 1,7,13) Specifies the format of the data to retrieve.
And the array contains the list of the fielnames if the drag & drop is used with multiple files. Specifies the name of the array in which the data is stored when the data can contain multiple values. The only data formats in which the data can contain multiple values are CF_FILES, CF_HDROP, and CFSTR_OLEVARIANTARRAY.


I recognize that this could go thru the clipboard which will be a fallback approach for me.

Sorry, perhaps someone else has an answer for you. I can only think of doing this via API calls.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

I appreciate your assistance in helping me find a solution. The help text you quoted is not entirely accurate in that .GetFormat() recognizes many more formats than those described in the online help.

I guess I'm going to have to see if there's a way for me to retrieve what I'm looking for via a Win32 API call.

Thanks again for your help,

Malcolm
 
Hi Mike,

Thanks - I'll take a look at the links you posted. I really appreciate the time you took helping me out.

Regards,
Malcolm
 
A solution!

With special thanks to Herman Tan on the UniversalThread:

The Bitmap Data is in DIB format:

#define CF_DIB 8
if oDataObject.GetFormat( 2 )
lcData = oDataObject.GetData( CF_DIB )
? lcData
endif

The trick to keep in mind (which I totally missed in reading the OLEDragDrop documentation) is that you may want to recognize data in one format and extract it using another format.

Mike, thanks again for your help as well.

Malcolm
 
Malcom

Glad you found the solution, but I am not convinced that this will do what you need. I think in the end you want to be able to display the dropped picture, and the dib format will not display.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

> I think in the end you want to be able to display the dropped picture, and the dib format will not display.

Yes, you are correct. The VFP help reports that the image control _CAN_ display DIB images, but when I save the binary data stream I retrieve with .GetData( CF_DIB ) to a *.DIB file, neither the image control, nor MS Paint are able to display the image.

I think this is a multi-step journey. Now that I can retrieve the data I'm looking for (and many more types of data as well), its "just"<g> a matter of figuring out how to convert the retrieved data to something usable.

Personally I think the hard part is behind me. I'll post back any other breakthroughs I come across.

Thanks again for your interest,

Malcolm
 

Can I ask why you didn't just go with filetostr() at first when it gets dropped and strtofile() to convert it back to a bmp?
You can also use the GDI+ Createfromfile() form the Image foundation class.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

> Can I ask why you didn't just go with filetostr() at first when it gets dropped and strtofile() to convert it back to a bmp?

The image arrives in a DIB binary stream (device independent bitmap). I tried saving this DIB to a file via strtofile( lcData, "temp.dib" ) and then setting the image control's .Picture property to "temp.dib". Nothing happens. I've also tried loading the image control directly via VFP 9's new .PictureVal = lcData property. Nothing either. Finally, I tried viewing the temp.dib file I created with MS Paint which should display DIB files. I get a corrupt file message which probably explains why the image control can't display the image either.

According to VFP 9's help: "Graphics Support in Visual FoxPro", the DIB image format is fully supported by VFP so I have to believe there's a problem with the binary data stream I'm getting by using .GetData( CF_DIB ) where CF_DIB = 8. Perhaps the data is getting truncated or requires a specific prefix or suffix? (those comments are pure speculation on my part)

I'm off to follow your suggestion that I look at VFP 9's new GDI+ classes. Herman Tan also pointed me to the following C++ article on how to convert DIB images to BMP files. I think this article may be beyond my skills with VFP, but I will return to it as an option if I am unable to get the VFP GDI+ class to help.

Here's the article Herman suggested I review. The 2nd example is the code that might apply to my situation.


Thanks again for your help!

Malcolm
 
The image arrives in a DIB binary stream (device independent bitmap). I tried saving this DIB to a file via strtofile( lcData, "temp.dib" ) and then setting the image control's .Picture property to "temp.dib".

I meant that at the drag and drop moment you know the fullpath of the file, do a filetostr() on the bitmap itself (preseving the binary information rather than translating it to dib format) and strtofile() it back from binary to bmp.

I had work out a sample recently that used GDI and drag and drop to move a picture to a report. I posted in France (dont' mind the french, but try the example)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

Thanks for sharing your code on atoufox.org. Nice website! I actually understood more than I thought. Glad to see VFP prospering on the other side of the pond :)

I can successfully handle dropped image files using GetData(15). My challenge is how to allow users to drag and drop images and wav files that they've pasted into their Word docs. (These users currently dragdrop text and files fine).

When you drag images out of Word, they don't get transfered as files (unfortunately), but rather as DIB's, Metafiles, or Enhanced Metafiles. So my challenge is how to deal with the content that my users are dragging without having to have these users convert their source documents to another format.

Thanks again for your help! Your effort and patience is deserving of several stars, but I fear assigning a star to a random post might confuse anyone monitoring these threads.

Regards,
Malcolm

 
I tried saving this DIB to a file via strtofile( lcData, "temp.dib" ) and then setting the image control's .Picture property...
Malcolm,

Just a wild idea, but what if try the createbinary function?
Code:
strtofile( CREATEBINARY(lcData), "temp.dib" )
Andy

 
Hi Andy,

Just gave it a shot - no luck. Thanks for the suggestion!

Malcolm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top