>>>>Does anyone know an API function that will copy the content of a known, standard BMP file to the Windows Clipboard? I need this so that the user can select a file via GetFile(), then paste it into a RichText OCX.
>>>>
>>>>Any suggestions welcome!
>>>>
>>>>Thanks in advance.
>>>>
>>>Hi Mike,
>>>
>>>I must admit that when I first saw this post, I didn't think that there was a way to do (at least easily). However, and I've run only one test, the following seems to work:
>>>* Win32 Declares
>>>DECLARE SHORT OpenClipboard IN Win32API;
>>> INTEGER hWndNewOwner
>>>DECLARE INTEGER SetClipboardData IN Win32API;
>>> INTEGER uFormat, INTEGER hMem
>>>DECLARE SHORT CloseClipboard IN Win32API
>>>DECLARE INTEGER LoadImage IN Win32API;
>>> INTEGER hinst, STRING @lpszName,;
>>> INTEGER uType, INTEGER cxDesired,;
>>> INTEGER cyDesired, INTEGER fuLoad
>>>* Open the clipboard. I use the value from the foxtools
>>>* MainhWnd() function here, but zero is permissable
>>>lnhWnd = MainhWnd()
>>>IF OpenClipboard(lnhWnd) # 0
>>> * lcfile is the name of the bitmap file
>>> * Use 16 to load from file
>>> * Other types (icons, etc. can be loaded too.
>>> * Parameter 3 in this case indicates a bitmap
>>> lnhandle = LoadImage(0, @lcfile, 0, 0, 16)
>>> lnresult = SetClipboardData(2, lnhandle)
>>> IF lnresult = lnhandle
>>> * The call succeeded
>>> ENDIF
>>> = CloseClipboard()
>>>ENDIF
>>>Note that the image won't be available until the clipboard is closed. Further, failure to close it will make it unavailable to other applications.
>>>
>>>hth,
>>
>>George,
>>It works! With only two slight modifications...
>>First, I had to EMPTY the clipboard with:
>>declare integer EmptyClipboard in Win32API
>>=EmptyClipboard()
>
>I'm running Win 98 and I think that in 95 as well, you can have multiple items in the clipboard. I know when I ran the test the result left me with multiple types. When I went to Paint and selected Paste, the bitmap was copied rather than the text.
>
>>Second, there is a parameter missing in the LoadImage call:
>>you had
>> lnhandle = LoadImage(0, @lcfile, 0, 0, 16)
>>I changed to
>> lnhandle = LoadImage(0, @lcfile, 0, 0, 0, 16)
>>
>>That did it.
>
>Whoops. Need to proof my own stuff a little more closely (Yeah, I even used the preview window before sending the message and still missed it). You're correction is absolutely correct. However, while I haven't tried it with icons, etc. that third parameter is file type dependent.
>
>>Once again, you defended your crown of King of the API with ease.
>
>Yee Gods and little fishes! Thanks for the compliment. Maybe I just have too much time on my hands.
George,
You're correct about the clipboard holding multiple items, the problem was that I wanted to paste the bitmap into a RichText control and the text would always paste first, if available. Flushing it first narrowed down the possibilities.
Thanks again.
Mike