void VDAgent::on_clipboard_grab() { uint32_t types[clipboard_formats_count * VD_CLIPBOARD_FORMAT_MAX_TYPES]; int count = 0; if (!VD_AGENT_HAS_CAPABILITY(_client_caps, _client_caps_size, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND)) { return; } if (CountClipboardFormats() == 0) { return; } for (unsigned int i = 0; i < clipboard_formats_count; i++) { if (IsClipboardFormatAvailable(clipboard_formats[i].format)) { for (uint32_t* ptype = clipboard_formats[i].types; *ptype; ptype++) { types[count++] = *ptype; } } } if (count) { write_message(VD_AGENT_CLIPBOARD_GRAB, count * sizeof(types[0]), types); set_clipboard_owner(owner_guest); } else { UINT format = 0; while ((format = EnumClipboardFormats(format))) { vd_printf("Unsupported clipboard format %u", format); } } }
WStringAutoPtr ClipboardFormats ( void ) { wstring format_list = L""; if ( OpenClipboard ( NULL ) ) { UINT formats = CountClipboardFormats(); UINT next_format = 0; for ( UINT i = 0 ; i < formats ; i++ ) { next_format = EnumClipboardFormats ( next_format ); const int max_count = 4096; wchar_t format_name[max_count]; int name_length = GetClipboardFormatName ( next_format, format_name, max_count ); if ( name_length > 0 ) { format_list += format_name; format_list += L"\r"; } } CloseClipboard(); } return WStringAutoPtr ( new wstring ( format_list ) ); } // ClipboardFormats
static PyObject * py_count_clipboard_formats(PyObject* self, PyObject* args) { CHECK_NO_ARGS2(args, "CountClipboardFormats"); int rc; Py_BEGIN_ALLOW_THREADS; rc = CountClipboardFormats(); Py_END_ALLOW_THREADS; if (!rc) { return ReturnAPIError("CountClipboardFormats"); } return (Py_BuildValue("i", rc)); // @pyseeapi CountClipboardFormats // @rdesc If the function succeeds, the return value is the number of // different data formats currently on the clipboard. // If the function fails, win32api.error is raised with the GetLastError // info. }
void CUIDesignerView::OnUpdateNeedClip(CCmdUI* pCmdUI) { BOOL bOn = FALSE; if(CountClipboardFormats()!=0 && IsClipboardFormatAvailable(m_cfUI)) bOn = TRUE; pCmdUI->Enable(bOn); }
std::unique_ptr<Clipboard> Clipboard::Capture() { auto clipboard = std::make_unique<Clipboard>(GetClipboardOwner()); if (clipboard == nullptr) return nullptr; UINT format_id = 0; for (auto i = 0, l = CountClipboardFormats(); i < l; ++i) { format_id = EnumClipboardFormats(format_id); if (format_id == 0) // error break; auto handle = GetClipboardData(format_id); if (handle == NULL) // error continue; std::unique_ptr<Format> format; if (format_id == CF_BITMAP) { // ignore } else if (format_id == CF_ENHMETAFILE) { auto meta_file = CopyEnhMetaFile(reinterpret_cast<HENHMETAFILE>(handle), nullptr); if (meta_file == NULL) // error continue; format = std::make_unique<MetaFileFormat>(meta_file); } else { auto size = GlobalSize(handle); auto memory = GlobalLock(handle); if (memory == nullptr) // error continue; format = std::make_unique<Format>(format_id, size); memcpy(format->Get(), memory, size); GlobalUnlock(handle); } if (format != nullptr) clipboard->Add(std::move(format)); } if (clipboard->IsEmpty()) return nullptr; return clipboard; }
/************************************************************************** * GetPriorityClipboardFormat (USER32.@) */ INT WINAPI GetPriorityClipboardFormat(UINT *list, INT nCount) { int i; TRACE("()\n"); if(CountClipboardFormats() == 0) return 0; for (i = 0; i < nCount; i++) if (IsClipboardFormatAvailable(list[i])) return list[i]; return -1; }
static void UpdateDisplayMenu(void) { UINT uFormat; HMENU hMenu; WCHAR szFormatName[MAX_FMT_NAME_LEN + 1]; hMenu = GetSubMenu(Globals.hMenu, DISPLAY_MENU_POS); while (GetMenuItemCount(hMenu) > 1) { DeleteMenu(hMenu, 1, MF_BYPOSITION); } if (CountClipboardFormats() == 0) return; if (!OpenClipboard(Globals.hMainWnd)) return; AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL); /* Display the supported clipboard formats first */ for (uFormat = EnumClipboardFormats(0); uFormat; uFormat = EnumClipboardFormats(uFormat)) { if (IsClipboardFormatSupported(uFormat)) { RetrieveClipboardFormatName(Globals.hInstance, uFormat, TRUE, szFormatName, ARRAYSIZE(szFormatName)); AppendMenuW(hMenu, MF_STRING, CMD_AUTOMATIC + uFormat, szFormatName); } } /* Now display the unsupported clipboard formats */ for (uFormat = EnumClipboardFormats(0); uFormat; uFormat = EnumClipboardFormats(uFormat)) { if (!IsClipboardFormatSupported(uFormat)) { RetrieveClipboardFormatName(Globals.hInstance, uFormat, TRUE, szFormatName, ARRAYSIZE(szFormatName)); AppendMenuW(hMenu, MF_STRING | MF_GRAYED, 0, szFormatName); } } CloseClipboard(); }
SEXP getClipboardFormats(void) { SEXP ans = R_NilValue; int j, size, format = 0; if(OpenClipboard(NULL)) { size = CountClipboardFormats(); PROTECT(ans = allocVector(INTSXP, size)); for (j = 0; j < size; j++) { format = EnumClipboardFormats(format); INTEGER(ans)[j] = format; } UNPROTECT(1); CloseClipboard(); } return ans; }
static void InitMenuPopup(HMENU hMenu, LPARAM index) { if ((GetMenuItemID(hMenu, 0) == CMD_DELETE) || (GetMenuItemID(hMenu, 1) == CMD_SAVE_AS)) { if (CountClipboardFormats() == 0) { EnableMenuItem(hMenu, CMD_DELETE, MF_GRAYED); EnableMenuItem(hMenu, CMD_SAVE_AS, MF_GRAYED); } else { EnableMenuItem(hMenu, CMD_DELETE, MF_ENABLED); EnableMenuItem(hMenu, CMD_SAVE_AS, MF_ENABLED); } } DrawMenuBar(Globals.hMainWnd); }
static int cliprdr_send_format_list(wfClipboard* clipboard) { int count; int length; UINT32 index; UINT32 numFormats; UINT32 formatId = 0; char formatName[1024]; CLIPRDR_FORMAT* format; CLIPRDR_FORMAT* formats; CLIPRDR_FORMAT_LIST formatList; ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST)); if (!OpenClipboard(clipboard->hwnd)) return -1; count = CountClipboardFormats(); numFormats = (UINT32) count; formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT)); index = 0; while (formatId = EnumClipboardFormats(formatId)) { format = &formats[index++]; format->formatId = formatId; length = 0; format->formatName = NULL; if (formatId >= CF_MAX) { length = GetClipboardFormatNameA(formatId, formatName, sizeof(formatName) - 1); } if (length > 0) { format->formatName = _strdup(formatName); } } CloseClipboard(); formatList.msgFlags = 0; formatList.numFormats = numFormats; formatList.formats = formats; clipboard->context->ClientFormatList(clipboard->context, &formatList); for (index = 0; index < numFormats; index++) { format = &formats[index]; free(format->formatName); } free(formats); return 1; }
/* ************************************ * void WINAPI InitMenu(HWND hwnd, HMENU hmenu) * 功能 根据粘贴板中内容的格式,设置菜单项供用户选择显示方式 * 参数 hwnd,窗口句柄 * hmenu,需要设置的菜单句柄 **************************************/ void WINAPI InitMenu(HWND hwnd, HMENU hmenu) { UINT uFormat; char szFormatName[80]; LPCSTR lpFormatName; UINT fuFlags; UINT idMenuItem; // 判断菜单的第一项是不是auto // 所有的显示根据附加到这个POPUP中 if (GetMenuItemID(hmenu, 0) != ID_AUTO) return; // 将除了第一个以外的其他所有菜单项删除 while (GetMenuItemCount(hmenu) > 1) DeleteMenu(hmenu, 1, MF_BYPOSITION); // Auto项是否设置 fuFlags = fAuto ? MF_BYCOMMAND | MF_CHECKED : MF_BYCOMMAND | MF_UNCHECKED; CheckMenuItem(hmenu, ID_AUTO, fuFlags); // 检测粘贴板中格式的数量 if (CountClipboardFormats() == 0) return; // 打开粘贴板 if (!OpenClipboard(hwnd)) return; // 为每个格式附加一个菜单项 AppendMenu(hmenu, MF_SEPARATOR, 0, NULL); uFormat = EnumClipboardFormats(0); while (uFormat) { // 程序为每一个格式定义了一个在菜单项中显示的名字 lpFormatName = GetPredefinedClipboardFormatName(uFormat); // 如果程序未定义,获取格式的名字 if (lpFormatName == NULL) { // 注意溢出 if (GetClipboardFormatName(uFormat, szFormatName, sizeof(szFormatName))) lpFormatName = szFormatName; else lpFormatName = "(unknown)"; } // 是可显示的格式 if (IsDisplayableFormat(uFormat)) { fuFlags = MF_STRING; idMenuItem = uFormat; } else { fuFlags = MF_STRING | MF_GRAYED; idMenuItem = 0; } // 增加菜单项 AppendMenu(hmenu, fuFlags, idMenuItem, lpFormatName); // 下一个格式,循环 uFormat = EnumClipboardFormats(uFormat); } CloseClipboard(); }
//------------------------------------------------------------------------------ //http://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx DWORD WINAPI Scan_clipboard(LPVOID lParam) { //check if local or not :) if (!LOCAL_SCAN) { h_thread_test[(unsigned int)lParam] = 0; check_treeview(htrv_test, H_tests[(unsigned int)lParam], TRV_STATE_UNCHECK);//db_scan return 0; } //db sqlite3 *db = (sqlite3 *)db_scan; if(!SQLITE_FULL_SPEED)sqlite3_exec(db_scan,"BEGIN TRANSACTION;", NULL, NULL, NULL); //lecture du contenu du presse papier et extraction if (OpenClipboard(0)) { char description[MAX_LINE_SIZE], format[DEFAULT_TMP_SIZE], data[MAX_LINE_SIZE],user[NB_USERNAME_SIZE+1]=""; unsigned int session_id = current_session_id; HGLOBAL hMem; //user DWORD s=NB_USERNAME_SIZE; GetUserName(user,&s); int nb_items = CountClipboardFormats(); if (nb_items > 0) { unsigned int uFormat = EnumClipboardFormats(0); #ifdef CMD_LINE_ONLY_NO_DB printf("\"Clipboard\";\"format\";\"code\";\"description\";\"user\";\"session_id\";\"data\";\r\n"); #endif // CMD_LINE_ONLY_NO_DB while (uFormat && start_scan && GetLastError() == ERROR_SUCCESS && --nb_items>0) { //check if ok if (IsClipboardFormatAvailable(uFormat) == FALSE) { uFormat = EnumClipboardFormats(uFormat); continue; } description[0] = 0; data[0]= 0; if (GetClipboardFormatName(uFormat, description, MAX_LINE_SIZE) != 0) { hMem = GetClipboardData(uFormat); if (hMem != NULL) { switch(uFormat) { case CF_TEXT: //format strncpy(format,"CF_TEXT",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Text",DEFAULT_TMP_SIZE); //datas strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_BITMAP: //format strncpy(format,"CF_BITMAP",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Bitmap Picture",DEFAULT_TMP_SIZE); //do in bitmap to hexa SaveBitmapToHexaStr((HBITMAP)hMem , data, MAX_LINE_SIZE); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_METAFILEPICT: //format strncpy(format,"CF_METAFILEPICT",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Meta-File Picture",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); GlobalUnlock(hMem); break; case CF_SYLK: //format strncpy(format,"CF_SYLK",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Microsoft Symbolic Link (SYLK) data",DEFAULT_TMP_SIZE); //datas snprintf(data,MAX_LINE_SIZE,"%s",(char*)GlobalLock(hMem)); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_OEMTEXT: //format strncpy(format,"CF_OEMTEXT",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Text (OEM)",DEFAULT_TMP_SIZE); //datas strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_DIB: //format strncpy(format,"CF_DIB",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"DIB Bitmap Picture",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_DIF: //format strncpy(format,"CF_DIF",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Software Arts' Data Interchange information",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_TIFF: //format strncpy(format,"CF_TIFF",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Tagged Image File Format (TIFF) Picture",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_PALETTE: //format strncpy(format,"CF_PALETTE",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Colour Palette",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_PENDATA: //format strncpy(format,"CF_PENDATA",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Pen Data",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_UNICODETEXT: //format strncpy(format,"CF_UNICODETEXT",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Text Unicode",DEFAULT_TMP_SIZE); //datas snprintf(data,MAX_LINE_SIZE,"%S",GlobalLock(hMem)); convertStringToSQL(data, MAX_LINE_SIZE);h_thread_test[(unsigned int)lParam] = 0; GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_RIFF: //format strncpy(format,"CF_RIFF",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"RIFF Audio data",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_WAVE: //format strncpy(format,"CF_WAVE",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Wave File",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_ENHMETAFILE: //format strncpy(format,"CF_ENHMETAFILE",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Enhanced Meta-File Picture",DEFAULT_TMP_SIZE); //datas DWORD dwSize = GetEnhMetaFileBits((HENHMETAFILE)hMem, 0, NULL); if (dwSize > 0) { LPBYTE buffer = (LPBYTE)malloc(dwSize); if (buffer != NULL) { if (GetEnhMetaFileBits((HENHMETAFILE)hMem, dwSize, buffer)!=0) { DatatoHexa(buffer, dwSize, data, MAX_LINE_SIZE); } free(buffer); } } addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case CF_HDROP: { //format strncpy(format,"CF_HDROP",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"File List",DEFAULT_TMP_SIZE); HDROP H_DropInfo = (HDROP)hMem; char tmp[MAX_PATH]; DWORD i,nb_path = DragQueryFile(H_DropInfo, 0xFFFFFFFF, tmp, MAX_PATH); long int s2 =MAX_LINE_SIZE; for (i=0;i<nb_path;i++) { //traitement des données ^^ DragQueryFile(H_DropInfo, i, tmp, MAX_PATH); //add if (s2>0) { snprintf(data+strlen(data),s,"%s\r\n",tmp); //strncpy(data+strlen(data),tmp,s); s2-=strlen(data); } } convertStringToSQL(data, MAX_LINE_SIZE); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); } break; case CF_LOCALE: //format strncpy(format,"CF_LOCALE",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Text Locale Identifier",DEFAULT_TMP_SIZE); //datas snprintf(data,MAX_LINE_SIZE,"0x%X",(unsigned int)GlobalLock(hMem)); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case 17: //CF_DIBV5 //format strncpy(format,"CF_DIBV5",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), sizeof(BITMAPV5HEADER), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case 49155: //format strncpy(format,"UNKNOW",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"OwnerLink",DEFAULT_TMP_SIZE); //datas strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case 49156: //format strncpy(format,"UNKNOW",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Native Bitmap Picture",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case 49158: //format strncpy(format,"UNKNOW",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"FileName",DEFAULT_TMP_SIZE); //datas strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case 49159: //format strncpy(format,"UNKNOW",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"FileNameW",DEFAULT_TMP_SIZE); //datas snprintf(data,MAX_LINE_SIZE,"%S",GlobalLock(hMem)); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; case 49298: //format strncpy(format,"UNKNOW",DEFAULT_TMP_SIZE); if (description[0]==0)strncpy(description,"Rich Text Format",DEFAULT_TMP_SIZE); //datas snprintf(data,MAX_LINE_SIZE,"%s",(char*)GlobalLock(hMem)); convertStringToSQL(data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; default: //format strncpy(format,"UNKNOW",DEFAULT_TMP_SIZE); //datas DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE); GlobalUnlock(hMem); addClipboardtoDB(format, uFormat, description, data, user, session_id, db); break; } } } uFormat = EnumClipboardFormats(uFormat); } } CloseClipboard(); } if(!SQLITE_FULL_SPEED)sqlite3_exec(db_scan,"END TRANSACTION;", NULL, NULL, NULL); check_treeview(htrv_test, H_tests[(unsigned int)lParam], TRV_STATE_UNCHECK);//db_scan h_thread_test[(unsigned int)lParam] = 0; return 0; }
/** * Todo * @param void * @param void * @return void */ void Clipboard::GetCurrentData ( CWnd* wnd, V_CF& cf ) { try { // clear the structure ResetClipboardFormats( cf ); // we cannot go further if we have no data if( NULL == wnd ) { HWND hCurrent = GetForegroundWindow(); wnd = CWnd::FromHandle( hCurrent ); if( NULL == wnd ) { return; } } // do we have anything saved? if (CountClipboardFormats() == 0) { return; } // open the clipboard for that window if (!OpenClipboard(wnd->GetSafeHwnd())) { return; } // get the current text data // if there is nothing UINT uFormat = EnumClipboardFormats(0); while (uFormat) { // read that data from the clipbaord ClipboardData *current = ClipboardData::FromClipboard( uFormat, _maxMemory ); if( current ) { // we cannot do much about NULL clipboard data // this is probably private data that we could not use anyway. cf.push_back(current); } // get the next format uFormat = EnumClipboardFormats(uFormat); } // empty the clipboard EmptyClipboard(); // close the clipboard. CloseClipboard(); } catch(... ) { _ASSERT(0); // the main reason for failure is probably because // there is a format in the Clipboard that I am not handling properly // there should be a way of seending me a mail when this happens so we can look into fixing it. } }
void CPageDesignerApp::OnEditEmptyClipboardUpdate(long iid, IUICmdUpdate* pCmdUI) { pCmdUI->Enable(CountClipboardFormats() > 0); }
static void cliprdr_send_format_list(cliprdrContext *cliprdr) { RDP_CB_FORMAT_LIST_EVENT *cliprdr_event; BYTE *format_data; int format = 0; int data_size; int format_count; int len = 0; int namelen; if (!OpenClipboard(cliprdr->hwndClipboard)) { DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError()); return; } format_count = CountClipboardFormats(); data_size = format_count * (4 + MAX_PATH * 2); format_data = (BYTE *)calloc(1, data_size); assert(format_data != NULL); while (format = EnumClipboardFormats(format)) { Write_UINT32(format_data + len, format); len += 4; if ((cliprdr->capabilities & CAPS_USE_LONG_FORMAT_NAMES) != 0) { if (format >= CF_MAX) { namelen = GetClipboardFormatNameW(format, (LPWSTR)(format_data + len), MAX_PATH); len += namelen * sizeof(WCHAR); } len += 2; /* end of Unicode string */ } else { if (format >= CF_MAX) { static wchar_t wName[MAX_PATH] = {0}; int wLen; ZeroMemory(wName, MAX_PATH*2); wLen = GetClipboardFormatNameW(format, wName, MAX_PATH); if (wLen < 16) { memcpy(format_data + len, wName, wLen * sizeof(WCHAR)); } else { memcpy(format_data + len, wName, 32); /* truncate the long name to 32 bytes */ } } len += 32; } } CloseClipboard(); cliprdr_event = (RDP_CB_FORMAT_LIST_EVENT *) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL); cliprdr_event->raw_format_data = (BYTE *)calloc(1, len); assert(cliprdr_event->raw_format_data != NULL); CopyMemory(cliprdr_event->raw_format_data, format_data, len); cliprdr_event->raw_format_data_size = len; free(format_data); freerdp_channels_send_event(cliprdr->channels, (wMessage *) cliprdr_event); }
static void test_RegisterClipboardFormatA(void) { ATOM atom_id; UINT format_id, format_id2; char buf[256]; int len; BOOL ret; format_id = RegisterClipboardFormatA("my_cool_clipboard_format"); ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id); format_id2 = RegisterClipboardFormatA("MY_COOL_CLIPBOARD_FORMAT"); ok(format_id2 == format_id, "invalid clipboard format id %04x\n", format_id2); len = GetClipboardFormatNameA(format_id, buf, 256); ok(len == lstrlenA("my_cool_clipboard_format"), "wrong format name length %d\n", len); ok(!lstrcmpA(buf, "my_cool_clipboard_format"), "wrong format name \"%s\"\n", buf); lstrcpyA(buf, "foo"); SetLastError(0xdeadbeef); len = GetAtomNameA((ATOM)format_id, buf, 256); ok(len == 0, "GetAtomNameA should fail\n"); test_last_error(ERROR_INVALID_HANDLE); todo_wine { lstrcpyA(buf, "foo"); SetLastError(0xdeadbeef); len = GlobalGetAtomNameA((ATOM)format_id, buf, 256); ok(len == 0, "GlobalGetAtomNameA should fail\n"); test_last_error(ERROR_INVALID_HANDLE); } SetLastError(0xdeadbeef); atom_id = FindAtomA("my_cool_clipboard_format"); ok(atom_id == 0, "FindAtomA should fail\n"); test_last_error(ERROR_FILE_NOT_FOUND); if (0) { /* this relies on the clipboard and global atom table being different */ SetLastError(0xdeadbeef); atom_id = GlobalFindAtomA("my_cool_clipboard_format"); ok(atom_id == 0, "GlobalFindAtomA should fail\n"); test_last_error(ERROR_FILE_NOT_FOUND); for (format_id = 0; format_id < 0xffff; format_id++) { SetLastError(0xdeadbeef); len = GetClipboardFormatNameA(format_id, buf, 256); if (format_id < 0xc000) { ok(!len, "GetClipboardFormatNameA should fail, but it returned %d (%s)\n", len, buf); test_last_error(ERROR_INVALID_PARAMETER); } else { if (len) trace("%04x: %s\n", format_id, len ? buf : ""); else test_last_error(ERROR_INVALID_HANDLE); } } } ret = OpenClipboard(0); ok( ret, "OpenClipboard error %d\n", GetLastError()); trace("# of formats available: %d\n", CountClipboardFormats()); format_id = 0; while ((format_id = EnumClipboardFormats(format_id))) { ok(IsClipboardFormatAvailable(format_id), "format %04x was listed as available\n", format_id); len = GetClipboardFormatNameA(format_id, buf, 256); trace("%04x: %s\n", format_id, len ? buf : ""); } ret = EmptyClipboard(); ok( ret, "EmptyClipboard error %d\n", GetLastError()); ret =CloseClipboard(); ok( ret, "CloseClipboard error %d\n", GetLastError()); if (CountClipboardFormats()) { SetLastError(0xdeadbeef); ok(!EnumClipboardFormats(0), "EnumClipboardFormats should fail if clipboard wasn't open\n"); ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN, "Last error should be set to ERROR_CLIPBOARD_NOT_OPEN, not %d\n", GetLastError()); } SetLastError(0xdeadbeef); ok(!EmptyClipboard(), "EmptyClipboard should fail if clipboard wasn't open\n"); ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN || broken(GetLastError() == 0xdeadbeef), /* wow64 */ "Wrong error %u\n", GetLastError()); }
/*! クリップボードのデータをいただく・同じモノが、DocInsDelCtrl.cpp にある @param[in] pVoid 特になし @return 確保した文字列・mallocしてるので、函数呼んだ方でfree忘れないように */ LPTSTR ClipboardDataGet( LPVOID pVoid ) { LPTSTR ptString = NULL, ptClipTxt; LPSTR pcStr, pcClipTp; // 変換用臨時 DWORD cbSize; UINT dEnumFmt; INT ixCount, iC; HANDLE hClipData; // クリップボードの中身をチェキ・どっちにしてもユニコードテキストフラグはある if( IsClipboardFormatAvailable( CF_UNICODETEXT ) ) { OpenClipboard( NULL ); // クリップボードをオーポンする // 開けっ放しだと他のアプリに迷惑なのですぐ閉めるように dEnumFmt = 0; // 初期値は0 ixCount = CountClipboardFormats( ); for( iC = 0; ixCount > iC; iC++ ) { // 順番に列挙して、先にヒットしたフォーマットで扱う dEnumFmt = EnumClipboardFormats( dEnumFmt ); if( CF_UNICODETEXT == dEnumFmt || CF_TEXT == dEnumFmt ){ break; } } if( 0 == dEnumFmt ){ return NULL; } // それ以上列挙が無いか、函数失敗なら0になる // クリップボードのデータをゲッツ! // ハンドルのオーナーはクリップボードなので、こちらからは操作しないように // 中身の変更などもってのほかである hClipData = GetClipboardData( dEnumFmt ); if( CF_UNICODETEXT == dEnumFmt ) { // 取得データを処理。TEXTなら、ハンドルはグローバルメモリハンドル // 新たにコピーされたらハンドルは無効になるので、中身をコピーせよ ptClipTxt = (LPTSTR)GlobalLock( hClipData ); cbSize = GlobalSize( (HGLOBAL)hClipData ); // 確保出来るのはバイトサイズ・テキストだと末尾のNULLターミネータ含む if( 0 < cbSize ) { ptString = (LPTSTR)malloc( cbSize ); StringCchCopy( ptString, (cbSize / 2), ptClipTxt ); } } else // 非ユニコードが優先されている場合 { pcClipTp = (LPSTR)GlobalLock( hClipData ); cbSize = GlobalSize( (HGLOBAL)hClipData ); if( 0 < cbSize ) { pcStr = (LPSTR)malloc( cbSize ); StringCchCopyA( pcStr, cbSize, pcClipTp ); ptString = SjisDecodeAlloc( pcStr ); // SJISの内容をユニコードにする free( pcStr ); } } // 使い終わったら閉じておく GlobalUnlock( hClipData ); CloseClipboard( ); } return ptString; }
void WriteClipboardFile(LPCWSTR lpFileName, WORD wFileIdentifier) { CLIPFILEHEADER ClipFileHeader; CLIPFORMATHEADER ClipFormatArray; NTCLIPFILEHEADER NtClipFileHeader; NTCLIPFORMATHEADER NtClipFormatArray; PVOID pClipFileHeader; PVOID pClipFormatArray; DWORD SizeOfFileHeader, SizeOfFormatHeader; WORD wFormatCount; DWORD dwFormatID; DWORD dwLenData; DWORD dwOffData; // PVOID szName; HANDLE hFile; DWORD dwBytesWritten; int i; /* Create the file for write access */ hFile = CreateFileW(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { ShowLastWin32Error(Globals.hMainWnd); goto done; } wFormatCount = CountClipboardFormats(); /* Select the file format and setup the header according to the clipboard file format ID */ switch (wFileIdentifier) { case CLIP_FMT_31: SizeOfFileHeader = sizeof(CLIPFILEHEADER); SizeOfFormatHeader = sizeof(CLIPFORMATHEADER); pClipFileHeader = &ClipFileHeader; pClipFormatArray = &ClipFormatArray; ClipFileHeader.wFileIdentifier = CLIP_FMT_31; // wFileIdentifier ClipFileHeader.wFormatCount = wFormatCount; break; case CLIP_FMT_NT: case CLIP_FMT_BK: SizeOfFileHeader = sizeof(NTCLIPFILEHEADER); SizeOfFormatHeader = sizeof(NTCLIPFORMATHEADER); pClipFileHeader = &NtClipFileHeader; pClipFormatArray = &NtClipFormatArray; NtClipFileHeader.wFileIdentifier = CLIP_FMT_NT; // wFileIdentifier NtClipFileHeader.wFormatCount = wFormatCount; break; default: MessageBoxRes(Globals.hMainWnd, Globals.hInstance, ERROR_INVALID_FILE_FORMAT, 0, MB_ICONSTOP | MB_OK); goto done; } /* Write the header */ SetFilePointer(hFile, 0, NULL, FILE_BEGIN); if (!WriteFile(hFile, pClipFileHeader, SizeOfFileHeader, &dwBytesWritten, NULL) || dwBytesWritten != SizeOfFileHeader) { ShowLastWin32Error(Globals.hMainWnd); goto done; } /* Compute where the data should start (after the file header and the format array) */ dwOffData = SizeOfFileHeader + wFormatCount * SizeOfFormatHeader; /* Loop through each format and save the data */ i = 0; dwFormatID = EnumClipboardFormats(0); while (dwFormatID) { if (i >= wFormatCount) { /* Must never happen! */ assert(FALSE); break; } /* Write the clipboard data at the specified offset, and retrieve its length */ if (!ClipboardWriteMemory(hFile, dwFormatID, dwOffData, &dwLenData)) goto Cont; /* Write the format data header */ switch (wFileIdentifier) { case CLIP_FMT_31: ZeroMemory(pClipFormatArray, sizeof(CLIPFORMATHEADER)); ((CLIPFORMATHEADER*)pClipFormatArray)->dwFormatID = dwFormatID; ((CLIPFORMATHEADER*)pClipFormatArray)->dwLenData = dwLenData; ((CLIPFORMATHEADER*)pClipFormatArray)->dwOffData = dwOffData; RetrieveClipboardFormatName(Globals.hInstance, dwFormatID, FALSE, ((CLIPFORMATHEADER*)pClipFormatArray)->szName, ARRAYSIZE(((CLIPFORMATHEADER*)pClipFormatArray)->szName)); break; case CLIP_FMT_NT: case CLIP_FMT_BK: ZeroMemory(pClipFormatArray, sizeof(NTCLIPFORMATHEADER)); ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwFormatID = dwFormatID; ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwLenData = dwLenData; ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwOffData = dwOffData; RetrieveClipboardFormatName(Globals.hInstance, dwFormatID, TRUE, ((NTCLIPFORMATHEADER*)pClipFormatArray)->szName, ARRAYSIZE(((NTCLIPFORMATHEADER*)pClipFormatArray)->szName)); break; } if (SetFilePointer(hFile, SizeOfFileHeader + i * SizeOfFormatHeader, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { ShowLastWin32Error(Globals.hMainWnd); goto done; } if (!WriteFile(hFile, pClipFormatArray, SizeOfFormatHeader, &dwBytesWritten, NULL)) { ShowLastWin32Error(Globals.hMainWnd); goto done; } /* Adjust the offset for the next data stream */ dwOffData += dwLenData; Cont: i++; dwFormatID = EnumClipboardFormats(dwFormatID); } done: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); return; }
static void test_RegisterClipboardFormatA(void) { ATOM atom_id; UINT format_id, format_id2; char buf[256]; int len; BOOL ret; HANDLE handle; format_id = RegisterClipboardFormatA("my_cool_clipboard_format"); ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id); format_id2 = RegisterClipboardFormatA("MY_COOL_CLIPBOARD_FORMAT"); ok(format_id2 == format_id, "invalid clipboard format id %04x\n", format_id2); len = GetClipboardFormatNameA(format_id, buf, 256); ok(len == lstrlenA("my_cool_clipboard_format"), "wrong format name length %d\n", len); ok(!lstrcmpA(buf, "my_cool_clipboard_format"), "wrong format name \"%s\"\n", buf); lstrcpyA(buf, "foo"); SetLastError(0xdeadbeef); len = GetAtomNameA((ATOM)format_id, buf, 256); ok(len == 0, "GetAtomNameA should fail\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "err %d\n", GetLastError()); todo_wine { lstrcpyA(buf, "foo"); SetLastError(0xdeadbeef); len = GlobalGetAtomNameA((ATOM)format_id, buf, 256); ok(len == 0, "GlobalGetAtomNameA should fail\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "err %d\n", GetLastError()); } SetLastError(0xdeadbeef); atom_id = FindAtomA("my_cool_clipboard_format"); ok(atom_id == 0, "FindAtomA should fail\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "err %d\n", GetLastError()); if (0) { /* this relies on the clipboard and global atom table being different */ SetLastError(0xdeadbeef); atom_id = GlobalFindAtomA("my_cool_clipboard_format"); ok(atom_id == 0, "GlobalFindAtomA should fail\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "err %d\n", GetLastError()); } for (format_id = 0; format_id < 0xffff; format_id++) { SetLastError(0xdeadbeef); len = GetClipboardFormatNameA(format_id, buf, 256); if (format_id < 0xc000) ok(!len, "GetClipboardFormatNameA should fail, but it returned %d (%s)\n", len, buf); else if (len && winetest_debug > 1) trace("%04x: %s\n", format_id, len ? buf : ""); } ret = OpenClipboard(0); ok( ret, "OpenClipboard error %d\n", GetLastError()); /* try some invalid/unregistered formats */ SetLastError( 0xdeadbeef ); handle = SetClipboardData( 0, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 )); ok( !handle, "SetClipboardData succeeded\n" ); ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN, "wrong error %u\n", GetLastError()); handle = SetClipboardData( 0x1234, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 )); ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError()); handle = SetClipboardData( 0x123456, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 )); ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError()); handle = SetClipboardData( 0xffff8765, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 )); ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError()); ok( IsClipboardFormatAvailable( 0x1234 ), "format missing\n" ); ok( IsClipboardFormatAvailable( 0x123456 ), "format missing\n" ); ok( IsClipboardFormatAvailable( 0xffff8765 ), "format missing\n" ); ok( !IsClipboardFormatAvailable( 0 ), "format available\n" ); ok( !IsClipboardFormatAvailable( 0x3456 ), "format available\n" ); ok( !IsClipboardFormatAvailable( 0x8765 ), "format available\n" ); trace("# of formats available: %d\n", CountClipboardFormats()); format_id = 0; while ((format_id = EnumClipboardFormats(format_id))) { ok(IsClipboardFormatAvailable(format_id), "format %04x was listed as available\n", format_id); len = GetClipboardFormatNameA(format_id, buf, 256); trace("%04x: %s\n", format_id, len ? buf : ""); } ret = EmptyClipboard(); ok( ret, "EmptyClipboard error %d\n", GetLastError()); ret =CloseClipboard(); ok( ret, "CloseClipboard error %d\n", GetLastError()); if (CountClipboardFormats()) { SetLastError(0xdeadbeef); ok(!EnumClipboardFormats(0), "EnumClipboardFormats should fail if clipboard wasn't open\n"); ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN, "Last error should be set to ERROR_CLIPBOARD_NOT_OPEN, not %d\n", GetLastError()); } SetLastError(0xdeadbeef); ok(!EmptyClipboard(), "EmptyClipboard should fail if clipboard wasn't open\n"); ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN || broken(GetLastError() == 0xdeadbeef), /* wow64 */ "Wrong error %u\n", GetLastError()); format_id = RegisterClipboardFormatA("#1234"); ok(format_id == 1234, "invalid clipboard format id %04x\n", format_id); }
int scrap_get_types_win (char** types) { UINT format = 0; char **tmptypes; int count = -1; int i, len, size; char tmp[100] = { '\0' }; if (!OpenClipboard (_sdlwindow)) { SDL_SetError ("could not access clipboard"); return -1; } size = CountClipboardFormats (); if (size == 0) { CloseClipboard (); return 0; /* No clipboard data. */ } for (i = 0; i < size; i++) { format = EnumClipboardFormats (format); if (format == 0) { /* Something wicked happened. */ while (i > 0) free (types[i]); free (types); CloseClipboard (); SDL_SetError ("error on retrieving the formats"); return -1; } /* No predefined name, get the (truncated) name. */ len = _lookup_clipboard_format (format, tmp, 100); if (len == 0) continue; count++; tmptypes = realloc (types, sizeof (char *) * (count + 1)); if (!tmptypes) { while (count > 0) { free (types[count]); count--; } free (types); CloseClipboard (); SDL_SetError ("could allocate memory"); return -1; } types = tmptypes; types[count] = malloc (sizeof (char) * (len + 1)); if (!types[count]) { while (count > 0) { free (types[count]); count--; } free (types); CloseClipboard (); SDL_SetError ("could allocate memory"); return -1; } memset (types[count], 0, len + 1); memcpy (types[count], tmp, len); } tmptypes = realloc (types, sizeof (char *) * (count + 1)); if (!tmptypes) { while (count > 0) { free (types[count]); count--; } free (types); CloseClipboard (); SDL_SetError ("could allocate memory"); return -1; } types = tmptypes; types[count] = NULL; CloseClipboard (); return 1; }
void MainWindow::DoPaste(bool pasteJunkPaths) { CString errStr, buildStr; UINT format = 0; UINT myFormat; bool isOpen = false; if (fpContentList == NULL || fpOpenArchive->IsReadOnly()) { ASSERT(false); return; } myFormat = RegisterClipboardFormat(kClipboardFmtName); if (myFormat == 0) { CheckedLoadString(&errStr, IDS_CLIPBOARD_REGFAILED); ShowFailureMsg(this, errStr, IDS_FAILED); goto bail; } LOGI("myFormat = %u", myFormat); if (OpenClipboard() == false) { CheckedLoadString(&errStr, IDS_CLIPBOARD_OPENFAILED); ShowFailureMsg(this, errStr, IDS_FAILED); goto bail;; } isOpen = true; LOGI("Found %d clipboard formats", CountClipboardFormats()); while ((format = EnumClipboardFormats(format)) != 0) { CString tmpStr; tmpStr.Format(L" %u", format); buildStr += tmpStr; } LOGI(" %ls", (LPCWSTR) buildStr); #if 0 if (IsClipboardFormatAvailable(CF_HDROP)) { errStr.LoadString(IDS_CLIPBOARD_NO_HDROP); ShowFailureMsg(this, errStr, IDS_FAILED); goto bail; } #endif /* impossible unless OnUpdateEditPaste was bypassed */ if (!IsClipboardFormatAvailable(myFormat)) { CheckedLoadString(&errStr, IDS_CLIPBOARD_NOTFOUND); ShowFailureMsg(this, errStr, IDS_FAILED); goto bail; } LOGI("+++ total data on clipboard: %ld bytes", GetClipboardContentLen()); HGLOBAL hGlobal; LPVOID pGlobal; hGlobal = GetClipboardData(myFormat); if (hGlobal == NULL) { ASSERT(false); goto bail; } pGlobal = GlobalLock(hGlobal); ASSERT(pGlobal != NULL); errStr = ProcessClipboard(pGlobal, GlobalSize(hGlobal), pasteJunkPaths); fpContentList->Reload(); if (!errStr.IsEmpty()) ShowFailureMsg(this, errStr, IDS_FAILED); else SuccessBeep(); GlobalUnlock(hGlobal); bail: if (isOpen) CloseClipboard(); }