-----BEGIN PGP SIGNED MESSAGE----- "Michael (michka) Kaplan" wrote: > Not sure how this could be generally possible to restrict, since > WinNT/2K/XP/.Net all will transparently map CF_TEXT an CF_UNICODETEXT so > that if one if put on the clipboard and the other is asked for, you will get > it. "Synthetic clipboard formats", etc...
However, you can enumerate the formats that an app actually put on the clipboard, rather than asking for a specific one. I happen to have a code snippet demonstrating that, which is attached. - -- David Hopwood <[EMAIL PROTECTED]> Home page & PGP public key: http://www.users.zetnet.co.uk/hopwood/ RSA 2048-bit; fingerprint 71 8E A6 23 0E D3 4C E5 0F 69 8C D4 FA 66 15 01 Nothing in this message is intended to be legally binding. If I revoke a public key but refuse to specify why, it is because the private key has been seized under the Regulation of Investigatory Powers Act; see www.fipr.org/rip -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQEVAwUBPXLgRzkCAxeYt5gVAQGl/wf+L17suZyJRwjpTRBVaUpckCHANcHv5na5 O83ZrzRHFpdU1iGxOrqz5gPGWIywgYd9Od+KgqwtVII0bX1pHg7MssABmNVU9i3Z GAiYkuuuhhR1pWHorqazQTlix8rgtd6aXtZ4Rip77UcYs9uwk1mQgYBhj7YDWAom tRamUCChRsoGrXRqU+mFXOAU0YIYafRDQ++WljjxH2FI1pPVa5PmFjBNW+W5O7Ys Z8/mFDxvs+QFKy2Wl9zj/VELCCeuSImo8B0q9LPzXKHfIOofNbx07uuY5ZiWM1Mf rIMZIGXaB/95/AwbSU1x0oROnakBL/3rLKqg+w/W2BVbvQCWm59JLA== =cRFn -----END PGP SIGNATURE-----
#include <stdio.h> #include <stdlib.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> int main(int argc, char **argv); BOOL testPaste(void); BOOL pasteFormat(int format, const void *data, size_t size); int main(int argc, char **argv) { int retval = EXIT_SUCCESS; int format = 0; char name[20]; HANDLE data; if (!OpenClipboard(NULL)) { printf("Could not open clipboard.\n"); return EXIT_FAILURE; } while ((format = EnumClipboardFormats(format)) != 0) { printf("Format %d", format); if (GetClipboardFormatNameA(format, name, sizeof(name)-1)) { printf(" (%s)", name); } switch (format) { case CF_UNICODETEXT: printf(" (CF_UNICODETEXT)"); data = GetClipboardData(format); wprintf(L" = \"%s\"", (wchar_t *) data); break; case CF_TEXT: printf(" (CF_TEXT)"); data = GetClipboardData(format); printf(" = \"%s\"", (char *) data); break; case CF_OEMTEXT: printf(" (CF_OEMTEXT)"); data = GetClipboardData(format); printf(" = \"%s\"", (char *) data); break; case CF_LOCALE: printf(" (CF_LOCALE)"); break; } printf("\n"); } if (GetLastError() != NO_ERROR) { printf("Error enumerating clipboard formats.\n"); retval = EXIT_FAILURE; } if (!testPaste()) { retval = EXIT_FAILURE; } if (!CloseClipboard()) { printf("Could not close clipboard.\n"); retval = EXIT_FAILURE; } return retval; } BOOL testPaste(void) { wchar_t pastew[] = L"hello"; char pastea[] = "ascii"; if (!EmptyClipboard()) { printf("Could not empty clipboard.\n"); return FALSE; } if (!pasteFormat(CF_UNICODETEXT, pastew, sizeof(pastew))) { printf("Could not paste Unicode text.\n"); return FALSE; } if (!pasteFormat(CF_TEXT, pastea, sizeof(pastea))) { printf("Could not paste MBCS text.\n"); return FALSE; } if (!pasteFormat(CF_OEMTEXT, pastea, sizeof(pastea))) { printf("Could not paste OEM text.\n"); return FALSE; } return TRUE; } BOOL pasteFormat(int format, const void *data, size_t size) { HANDLE handle; void *buf; if (!(handle = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size))) { return FALSE; } if (!(buf = GlobalLock(handle))) { GlobalFree(handle); return FALSE; } memcpy(buf, data, size); GlobalUnlock(buf); if (!SetClipboardData(format, handle)) { GlobalFree(handle); return FALSE; } return TRUE; }