Windows Clipboard

just experimenting trying to get more control over the windows clipboard, and some msdn docs suggest that i need to include AFXWIN.H

after a few little problems, i got it to compile without errors, but the linker gives me a fatal error, that it cannot open the file “uafxcwd.lib”

any ideas?

[edit : problem solved!]

God knows.

There are so many different incompatible versions and variations of windows libs that I lose track. Just search your whole hard disk for the library, I guess.

okay, my problem was trying to get around the fact that not all programs seem to be able to accept juce’s drop-files from the cursor. MS VC++express is one of those apps - it will accept a drop from windows explorer, but not from juce.

i wanted to make a nice simple app that will let me auto-generate the annoying repetive class header stuff (#ifndef BLAH #define BLAH class blah { blah(); ~blah(); }; #endif ) etc… and drag it straight into my visC++ project.

well, drag/drop is out of the question, but i’ve managed instead to adapt some code to allow the copying of FILES to the clipboard (not just text). all you need to do is include this file before you include JUCE (because windows.h needs to be included first):

typedef Array<File*> FileArray;

class ClipboardExtras

	static void copyFilesToClipboard( FileArray& files )
		MemoryBlock fileInfoData = getFileInfoData( files );

		DROPFILES dobj = { 20, { 0, 0 }, 0, 1 };

		int nLen = fileInfoData.getSize();

		int nGblLen = sizeof(dobj) + nLen*2 + 5;//lots of nulls and multibyte_char
		char* sData = (char*)::GlobalLock(hGbl);
		memcpy( sData, &dobj, 20 );
		char* sWStr = sData+20;
		for( int i = 0; i < nLen*2; i += 2 )
			sWStr[i] = fileInfoData[i/2];

		if( OpenClipboard(0) )
		SetClipboardData( CF_HDROP, hGbl );


	static MemoryBlock getFileInfoData( FileArray& files )
		const char nullChar = '\0';

		MemoryBlock fileInfo(0);

		for (int i=0; i<files.size(); i++)
			// get the current file in the array...
			File currentFile = *(files.getUnchecked(i));
			// copy the path name into the data block...
			String pathName = currentFile.getFullPathName();
			fileInfo.append( (const char*) pathName, pathName.length() ) ;
			// add the null separator...
			fileInfo.append( &nullChar, 1 );
		return fileInfo;


then you simply add whatever files you want to copy to a FileArray, and call ClipboardExtras::copyFilesToClipboard( fileArray ); - if you go into windows explorer or visualC++ you can right-click->paste the files that were in the array.

[EDIT- looking thru some of the platform specific juce code i see that my code here is far from elegant! :hihi: i think i should try to adapt it some more…]

1 Like