// ============================== // CONTENT // ============================== // CLIPBOARD_GET_VALUE - char* clipboard_get_value() // CLIPBOARD_SET_VALUE - bool clipboard_set_value(char* value) // CLIPBOARD_GET_FILE_DIRECTORY - char* clipboard_get_file_directory() // CLIPBOARD_GET_IMAGE - HBITMAP clipboard_get_image() // CLIPBOARD_GET_FORMAT_NAME - char* clipboard_get_format_name() // ============================== // ============================== BEGIN // REQUIREMENTS // ============================== MINIMUM SUPPORT // Windows_XP // Windows_Server_2003 // ============================== REQUIRE DLL (3) // User32.dll // Kernel32.dll // Shell32.dll (version 4.0+) // ============================== REQUIRE LIBRARIES (3) // User32.lib // Kernel32.lib // Shell32.lib // ============================== REQUIRE INCLUDES (4) #include #include #include #include // ============================== REQUIRE FUNCTIONS (0) // ============================== END // REQUIREMENTS // ============================== #ifndef CLIPBOARD_H #define CLIPBOARD_H // ============================== BEGIN // CLIPBOARD_GET_VALUE // ============================== PUBLIC // ============================== ABOUT // Returns text value from clipboard (Text with CTRL+V). // ============================== MINIMUM SUPPORT // Windows_XP // Windows_Server_2003 // ============================== REQUIRE DLL (2) // User32.dll // Kernel32.dll // ============================== REQUIRE LIBRARIES (2) // User32.lib // Kernel32.lib // ============================== REQUIRE INCLUDES (1) #include // ============================== USING FUNCTIONS (6) // =============== SYSTEM // OpenClipboard() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // IsClipboardFormatAvailable() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GetClipboardData() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GlobalLock() - winbase.h (windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP, Windows_Server_2003 // GlobalUnlock() - winbase.h (windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP, Windows_Server_2003 // CloseClipboard() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // ============================== USING DATA_TYPES (2) // =============== MACHINE // static_cast // =============== SYSTEM // HANDLE - BaseTsd.h, WinDef.h, WinNT.h (windows.h) | Windows_XP, Windows_Server_2003 // ============================== USING CONSTANTS (2) // =============== MACHINE // nullptr // =============== SYSTEM // CF_TEXT - IsClipboardFormatAvailable() // ============================== USING VARIABLES (0) // ============================== CODE char* clipboard_get_value() { char* clipboard_value = new char[1];clipboard_value[0] = 0; // Open lipboard - And prevents other applications from modifying the clipboard content. if (OpenClipboard(nullptr)) { // If clipboard format is text if (IsClipboardFormatAvailable(CF_TEXT)) { // Get handle of clipboard object for ANSI text HANDLE handle_object = GetClipboardData(CF_TEXT); // CF_TEXT|CF_UNICODETEXT|CF_OEMTEXT if (handle_object != nullptr) { // Lock the handle to get the actual text pointer clipboard_value = static_cast(GlobalLock(handle_object)); GlobalUnlock(handle_object); // Release the lock } } CloseClipboard(); // Release the clipboard } return clipboard_value; } // ============================== END // CLIPBOARD_GET_VALUE // ============================== // ============================== BEGIN // CLIPBOARD_SET_VALUE // ============================== // ============================== ABOUT // Set value into clipboard. // ============================== MINIMUM SUPPORT // Windows_XP // Windows_Server_2003 // ============================== REQUIRE DLL (2) // User32.dll // Kernel32.dll // ============================== REQUIRE LIBRARIES (2) // User32.lib // Kernel32.lib // ============================== REQUIRE INCLUDES (2) #include #include // ============================== USING FUNCTIONS (8) // =============== SYSTEM // OpenClipboard() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // EmptyClipboard() - winuser.h (Windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GlobalAlloc() - winbase.h (Windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP | Windows_Server_2003 // GlobalLock() - winbase.h (windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP, Windows_Server_2003 // strcpy() - string.h // SetClipboardData() - winuser.h (Windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GlobalUnlock() - winbase.h (Windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP, Windows_Server_2003 // CloseClipboard() - winuser.h (Windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // ============================== USING DATA_TYPES (1) // HGLOBAL - BaseTsd.h, WinDef.h, WinNT.h (windows.h) | Windows_XP, Windows_Server_2003 // ============================== USING CONSTANTS (2) // GMEM_DDESHARE - GlobalAlloc() // CF_TEXT - SetClipboardData() // ============================== USING VARIABLES (0) // ============================== CODE bool clipboard_set_value(char* value) { bool return_executed = true; // ===== CHAR_ARRAY_GET_LENGTH - BEGIN int value_length = 0; while (value[value_length] != 0) // Until EOF { value_length++; } // ===== CHAR_ARRAY_GET_LENGTH - END // Open lipboard - And prevents other applications from modifying the clipboard content. if (OpenClipboard(NULL)) { EmptyClipboard(); // Empties the clipboard and frees handles to data in the clipboard. HGLOBAL hglobal_object = GlobalAlloc(GMEM_DDESHARE, value_length + 1); if (hglobal_object != NULL) { char* clipboard_data = (char*) GlobalLock(hglobal_object); strcpy(clipboard_data, value); if (SetClipboardData(CF_TEXT, hglobal_object) != NULL) { return_executed = true; } } GlobalUnlock(hglobal_object); } CloseClipboard(); return return_executed; } // ============================== END // CLIPBOARD_SET_VALUE // ============================== // ============================== BEGIN // CLIPBOARD_GET_FILE_DIRECTORY // ============================== PUBLIC // ============================== ABOUT // Returns file directory from clipboard. // ============================== MINIMUM SUPPORT // Windows_XP // Windows_Server_2003 // ============================== REQUIRE DLL (3) // User32.dll // Kernel32.dll // Shell32.dll (version 4.0+) // ============================== REQUIRE LIBRARIES (3) // User32.lib // Kernel32.lib // Shell32.lib // ============================== REQUIRE INCLUDES (2) #include #include // ============================== USING FUNCTIONS (8) // =============== SYSTEM // OpenClipboard() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // IsClipboardFormatAvailable() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GetClipboardData() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GlobalLock() - winbase.h (windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP, Windows_Server_2003 // DragQueryFile() - shellapi.h | Shell32.lib | Shell32.dll (version 4.0+) | Windows_XP, Windows_2000_Server // DragFinish() - shellapi.h | Shell32.lib | Shell32.dll (version 4.0+) | Windows_XP, Windows_2000_Server // GlobalUnlock() - winbase.h (Windows.h) | Kernel32.lib | Kernel32.dll | Windows_XP, Windows_Server_2003 // CloseClipboard() - winuser.h (Windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // ============================== USING DATA_TYPES (2) // HGLOBAL - BaseTsd.h, WinDef.h, WinNT.h (windows.h) | Windows_XP, Windows_Server_2003 // HDROP - BaseTsd.h, WinDef.h, WinNT.h (windows.h) | Windows_XP, Windows_Server_2003 // ============================== USING CONSTANTS (1) // CF_HDROP - IsClipboardFormatAvailable() // ============================== USING VARIABLES (0) // ============================== CODE char* clipboard_get_file_directory() { char* file_directory = new char[1];file_directory[0] = 0; // Open lipboard - And prevents other applications from modifying the clipboard content. if (OpenClipboard(nullptr)) { // Get handle of clipboard object for ANSI text if (IsClipboardFormatAvailable(CF_HDROP)) { HGLOBAL hglobal_object = (HGLOBAL) GetClipboardData(CF_HDROP); // CF_HDROP - FAILS ON 10 000 FILES if (hglobal_object != nullptr) { // Lock the handle to get the actual text pointer HDROP hdrop_object = (HDROP) GlobalLock(hglobal_object); if (hdrop_object != nullptr) { //UINT multiple_files_length = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0); int multiple_files_index = 0; // REQUEST JUST FIRST FILE int file_directory_length = DragQueryFile(hdrop_object, multiple_files_index, 0, 0); file_directory = new char[file_directory_length]; DragQueryFile(hdrop_object, multiple_files_index, file_directory, file_directory_length + 1); file_directory[file_directory_length] = 0; // Set EOF DragFinish(hdrop_object); // Releases memory that the system allocated } GlobalUnlock(hglobal_object); // Release the lock } } CloseClipboard(); // Release the clipboard } return file_directory; } // ============================== END // CLIPBOARD_GET_FILE_DIRECTORY // ============================== // ============================== BEGIN // CLIPBOARD_GET_IMAGE // ============================== PUBLIC // ============================== ABOUT // Returns image from clipboard. // ============================== MINIMUM SUPPORT // Windows_2000_Professional // Windows_2000_Server // ============================== REQUIRE DLL (1) // User32.dll // ============================== REQUIRE LIBRARIES (1) // User32.lib // ============================== REQUIRE INCLUDES (1) #include // ============================== USING FUNCTIONS (4) // =============== SYSTEM // OpenClipboard() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // IsClipboardFormatAvailable() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // GetClipboardData() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // CloseClipboard() - winuser.h (Windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // ============================== USING DATA_TYPES (1) // HBITMAP - (MAYBE windows.h) // ============================== USING CONSTANTS (1) // CF_BITMAP - IsClipboardFormatAvailable() // ============================== USING VARIABLES (0) // ============================== CODE HBITMAP clipboard_get_image() { HBITMAP return_image = NULL; // Open lipboard - And prevents other applications from modifying the clipboard content. if (OpenClipboard(nullptr)) { if (IsClipboardFormatAvailable(CF_BITMAP)) { // Get handle of clipboard object return_image = (HBITMAP) GetClipboardData(CF_BITMAP); } } CloseClipboard(); // Release the clipboard return return_image; } // ============================== END // CLIPBOARD_GET_IMAGE // ============================== // ============================== BEGIN // CLIPBOARD_GET_FORMAT_NAME // ============================== PUBLIC // ============================== ABOUT // Returns data type format saved into clipboard. // ============================== MINIMUM SUPPORT // Windows_2000_Professional // Windows_2000_Server // ============================== REQUIRE DLL (1) // User32.dll // ============================== REQUIRE LIBRARIES (1) // User32.lib // ============================== REQUIRE INCLUDES (1) #include // ============================== USING FUNCTIONS (3) // =============== SYSTEM // OpenClipboard() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // IsClipboardFormatAvailable() - winuser.h (windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // CloseClipboard() - winuser.h (Windows.h) | User32.lib | User32.dll | Windows_2000_Professional, Windows_2000_Server // ============================== USING DATA_TYPES (0) // ============================== USING CONSTANTS (3) // CF_TEXT - IsClipboardFormatAvailable() // CF_HDROP - IsClipboardFormatAvailable() // CF_BITMAP - IsClipboardFormatAvailable() // ============================== USING VARIABLES (0) // ============================== CODE char* clipboard_get_format_name() { char* format_name = (char*) ""; // Open lipboard - And prevents other applications from modifying the clipboard content. if (OpenClipboard(NULL)) { if (IsClipboardFormatAvailable(CF_TEXT)) { format_name = (char*) "text"; } else if (IsClipboardFormatAvailable(CF_HDROP)) { format_name = (char*) "directory"; } else if (IsClipboardFormatAvailable(CF_BITMAP)) { format_name = (char*) "image"; } } CloseClipboard(); return format_name; } // ============================== END // CLIPBOARD_GET_FORMAT_NAME // ============================== #endif // CLIPBOARD_H