On Wed, 12 Nov 2003 02:25:33 -0800, "Roohi"
<an*************@hotmail.com> wrote:
hi
I am trying to copy an image to a clipboard and then get a
handle to the clipboard using API calls GetClipboardData().
~Roohi
Roohi
Can you modify this to do what you need:
public static bool JCopyFilesToClipboard(string[] strFiles, POINT pt)
{
bool blnReturn = false;
byte[] bData;
DROPFILES df = new DROPFILES();
int intChar, intFile, intDataLen, intPos;
IntPtr ipGlobal = IntPtr.Zero;
// Calculate total data length
intDataLen = 0;
for(intFile = 0; intFile <= strFiles.GetUpperBound(0);
intFile++)
intDataLen += strFiles[intFile].Length + 1;
// Terminating double zero
intDataLen++;
bData = new Byte[intDataLen];
intPos = 0;
// Build null terminated list of files
for(intFile = 0; intFile <= strFiles.GetUpperBound(0);
intFile++)
{
for(intChar = 0; intChar < strFiles[intFile].Length;
intChar++)
{
bData[intPos++] = (byte)strFiles[intFile][intChar];
}
bData[intPos++] = 0;
}
// Terminating double zero
bData[intPos++] = 0;
// Allocate and get pointer to global memory
int intTotalLen = Marshal.SizeOf(df) + intDataLen;
ipGlobal = Marshal.AllocHGlobal(intTotalLen);
if(ipGlobal == IntPtr.Zero)
return false;
// Build DROPFILES structure in global memory.
df.pFiles = Marshal.SizeOf(df);
df.pt = pt;
df.fNC = false;
df.fWide = 0;
Marshal.StructureToPtr(df, ipGlobal, true);
IntPtr ipNew = new IntPtr(ipGlobal.ToInt32() +
Marshal.SizeOf(df));
Marshal.Copy(bData, 0, ipNew, intDataLen);
// Open and empty clipboard
if(!OpenClipboard(IntPtr.Zero))
return false;
EmptyClipboard();
// Copy data to clipboard
blnReturn = (SetClipboardData(CF_HDROP, ipGlobal) !=
IntPtr.Zero);
if(!blnReturn)
Marshal.FreeHGlobal(ipGlobal);
// Clean up
CloseClipboard();
// Clipboard responsible for freeing memory
// Marshal.FreeHGlobal(ipGlobal);
return blnReturn;
}
It's a different file format but the principle is similar.
--
Jeff Gaines Damerham Hampshire UK