[CLIPBRD]

Add a clipboard viewer utility to ReactOS, courtesy Ricardo Hanke. Icon by Jared Smudde.
CORE-10353

svn path=/trunk/; revision=69776
This commit is contained in:
Hermès Bélusca-Maïto 2015-11-01 16:25:19 +00:00
parent f1176e4c81
commit dee57c2bf4
14 changed files with 1006 additions and 0 deletions

View file

@ -3,6 +3,7 @@ add_subdirectory(atactl)
add_subdirectory(cacls)
add_subdirectory(calc)
add_subdirectory(charmap)
add_subdirectory(clipbrd)
add_subdirectory(cmdutils)
add_subdirectory(control)
add_subdirectory(dxdiag)

View file

@ -0,0 +1,12 @@
list(APPEND SOURCE
clipbrd.c
cliputils.c
winutils.c
precomp.h)
add_executable(clipbrd ${SOURCE} clipbrd.rc)
add_pch(clipbrd precomp.h SOURCE)
set_module_type(clipbrd win32gui UNICODE)
add_importlibs(clipbrd hhctrl user32 gdi32 comctl32 comdlg32 advapi32 shell32 msvcrt kernel32)
add_cd_file(TARGET clipbrd DESTINATION reactos/system32 FOR all)

View file

@ -0,0 +1,363 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/clipbrd.c
* PURPOSE: Provides a view of the contents of the ReactOS clipboard.
* PROGRAMMERS: Ricardo Hanke
*/
#include "precomp.h"
static const WCHAR szClassName[] = L"ClipBookWClass";
CLIPBOARD_GLOBALS Globals;
static void SetDisplayFormat(UINT uFormat)
{
CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_UNCHECKED);
Globals.uCheckedItem = uFormat + CMD_AUTOMATIC;
CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_CHECKED);
if (uFormat == 0)
{
Globals.uDisplayFormat = GetAutomaticClipboardFormat();
}
else
{
Globals.uDisplayFormat = uFormat;
}
InvalidateRect(Globals.hMainWnd, NULL, TRUE);
UpdateWindow(Globals.hMainWnd);
}
static void InitMenuPopup(HMENU hMenu, LPARAM index)
{
if (GetMenuItemID(hMenu, 0) == CMD_DELETE)
{
if (CountClipboardFormats() == 0)
{
EnableMenuItem(hMenu, CMD_DELETE, MF_GRAYED);
}
else
{
EnableMenuItem(hMenu, CMD_DELETE, MF_ENABLED);
}
}
DrawMenuBar(Globals.hMainWnd);
}
void UpdateDisplayMenu(void)
{
UINT uFormat;
WCHAR szFormatName[MAX_STRING_LEN];
HMENU hMenu;
hMenu = GetSubMenu(Globals.hMenu, DISPLAY_MENU_POS);
while (GetMenuItemCount(hMenu) > 1)
{
DeleteMenu(hMenu, 1, MF_BYPOSITION);
}
if (CountClipboardFormats() == 0)
return;
if (!OpenClipboard(NULL))
return;
AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
uFormat = EnumClipboardFormats(0);
while (uFormat)
{
RetrieveClipboardFormatName(Globals.hInstance, uFormat, szFormatName, ARRAYSIZE(szFormatName));
if (!IsClipboardFormatSupported(uFormat))
{
AppendMenuW(hMenu, MF_STRING | MF_GRAYED, 0, szFormatName);
}
else
{
AppendMenuW(hMenu, MF_STRING, CMD_AUTOMATIC + uFormat, szFormatName);
}
uFormat = EnumClipboardFormats(uFormat);
}
CloseClipboard();
}
static int ClipboardCommandHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case CMD_EXIT:
{
PostMessageW(Globals.hMainWnd, WM_CLOSE, 0, 0);
break;
}
case CMD_DELETE:
{
if (MessageBoxRes(Globals.hMainWnd, Globals.hInstance, STRING_DELETE_MSG, STRING_DELETE_TITLE, MB_ICONWARNING | MB_YESNO) == IDYES)
{
DeleteClipboardContent();
}
break;
}
case CMD_AUTOMATIC:
{
SetDisplayFormat(0);
break;
}
case CMD_HELP:
{
HtmlHelpW(Globals.hMainWnd, L"clipbrd.chm", 0, 0);
break;
}
case CMD_ABOUT:
{
WCHAR szTitle[MAX_STRING_LEN];
LoadStringW(Globals.hInstance, STRING_CLIPBOARD, szTitle, ARRAYSIZE(szTitle));
ShellAboutW(Globals.hMainWnd, szTitle, 0, NULL);
break;
}
default:
{
break;
}
}
return 0;
}
static void ClipboardPaintHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rc);
switch (Globals.uDisplayFormat)
{
case CF_NONE:
{
break;
}
case CF_UNICODETEXT:
{
DrawTextFromClipboard(hdc, &rc, DT_LEFT);
break;
}
case CF_BITMAP:
{
BitBltFromClipboard(hdc, rc.left, rc.top, rc.right, rc.bottom, 0, 0, SRCCOPY);
break;
}
case CF_DIB:
{
SetDIBitsToDeviceFromClipboard(CF_DIB, hdc, rc.left, rc.top, 0, 0, 0, DIB_RGB_COLORS);
break;
}
case CF_DIBV5:
{
SetDIBitsToDeviceFromClipboard(CF_DIBV5, hdc, rc.left, rc.top, 0, 0, 0, DIB_RGB_COLORS);
break;
}
case CF_ENHMETAFILE:
{
PlayEnhMetaFileFromClipboard(hdc, &rc);
break;
}
case CF_METAFILEPICT:
{
PlayMetaFileFromClipboard(hdc, &rc);
break;
}
default:
{
DrawTextFromResource(Globals.hInstance, ERROR_UNSUPPORTED_FORMAT, hdc, &rc, DT_CENTER | DT_WORDBREAK);
break;
}
}
EndPaint(hWnd, &ps);
}
static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT:
{
ClipboardPaintHandler(hWnd, uMsg, wParam, lParam);
break;
}
case WM_SIZE:
{
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
break;
}
case WM_CREATE:
{
Globals.hMenu = GetMenu(hWnd);
Globals.hWndNext = SetClipboardViewer(hWnd);
UpdateDisplayMenu();
SetDisplayFormat(0);
break;
}
case WM_CLOSE:
{
DestroyWindow(hWnd);
break;
}
case WM_DESTROY:
{
ChangeClipboardChain(hWnd, Globals.hWndNext);
PostQuitMessage(0);
break;
}
case WM_CHANGECBCHAIN:
{
if ((HWND)wParam == Globals.hWndNext)
{
Globals.hWndNext = (HWND)lParam;
}
else if (Globals.hWndNext != NULL)
{
SendMessageW(Globals.hWndNext, uMsg, wParam, lParam);
}
break;
}
case WM_DRAWCLIPBOARD:
{
UpdateDisplayMenu();
SetDisplayFormat(0);
SendMessageW(Globals.hWndNext, uMsg, wParam, lParam);
break;
}
case WM_COMMAND:
{
if ((LOWORD(wParam) > CMD_AUTOMATIC))
{
SetDisplayFormat(LOWORD(wParam) - CMD_AUTOMATIC);
}
else
{
ClipboardCommandHandler(hWnd, uMsg, wParam, lParam);
}
break;
}
case WM_INITMENUPOPUP:
{
InitMenuPopup((HMENU)wParam, lParam);
break;
}
default:
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
return 0;
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccel;
HWND hPrevWindow;
WNDCLASSEXW wndclass;
WCHAR szBuffer[MAX_STRING_LEN];
hPrevWindow = FindWindowW(szClassName, NULL);
if (hPrevWindow)
{
BringWindowToFront(hPrevWindow);
return 0;
}
ZeroMemory(&Globals, sizeof(Globals));
Globals.hInstance = hInstance;
ZeroMemory(&wndclass, sizeof(wndclass));
wndclass.cbSize = sizeof(wndclass);
wndclass.lpfnWndProc = MainWndProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(CLIP_ICON));
wndclass.hCursor = LoadCursorW(0, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = MAKEINTRESOURCEW(MAIN_MENU);
wndclass.lpszClassName = szClassName;
if (!RegisterClassExW(&wndclass))
{
ShowLastWin32Error(NULL);
return 0;
}
LoadStringW(hInstance, STRING_CLIPBOARD, szBuffer, ARRAYSIZE(szBuffer));
Globals.hMainWnd = CreateWindowExW(WS_EX_CLIENTEDGE,
szClassName,
szBuffer,
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
Globals.hInstance,
NULL);
if (!Globals.hMainWnd)
{
ShowLastWin32Error(NULL);
return 0;
}
ShowWindow(Globals.hMainWnd, nCmdShow);
UpdateWindow(Globals.hMainWnd);
hAccel = LoadAcceleratorsW(Globals.hInstance, MAKEINTRESOURCEW(ID_ACCEL));
if (!hAccel)
{
ShowLastWin32Error(Globals.hMainWnd);
}
while (GetMessageW(&msg, 0, 0, 0))
{
if (!TranslateAcceleratorW(Globals.hMainWnd, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
return (int)msg.wParam;
}

View file

@ -0,0 +1,26 @@
#include <windef.h>
#include <winuser.h>
#include "resources.h"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Clipboard Viewer"
#define REACTOS_STR_INTERNAL_NAME "clipbrd"
#define REACTOS_STR_ORIGINAL_FILENAME "clipbrd.exe"
#include <reactos/version.rc>
CLIP_ICON ICON "res/clipbrd.ico"
#include <reactos/manifest_exe.rc>
/* UTF-8 */
#pragma code_page(65001)
#ifdef LANGUAGE_DE_DE
#include "lang/de-DE.rc"
#endif
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif
#ifdef LANGUAGE_FR_FR
#include "lang/fr-FR.rc"
#endif

View file

@ -0,0 +1,143 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/cliputils.c
* PURPOSE: Clipboard helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
#include "precomp.h"
int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR lpszFormat, UINT cch)
{
switch (uFormat)
{
case CF_TEXT:
{
return LoadStringW(hInstance, STRING_CF_TEXT, lpszFormat, cch);
}
case CF_BITMAP:
{
return LoadStringW(hInstance, STRING_CF_BITMAP, lpszFormat, cch);
}
case CF_OEMTEXT:
{
return LoadStringW(hInstance, STRING_CF_OEMTEXT, lpszFormat, cch);
}
case CF_UNICODETEXT:
{
return LoadStringW(hInstance, STRING_CF_UNICODETEXT, lpszFormat, cch);
}
case CF_DIB:
{
return LoadStringW(hInstance, STRING_CF_DIB, lpszFormat, cch);
}
case CF_LOCALE:
{
return LoadStringW(hInstance, STRING_CF_LOCALE, lpszFormat, cch);
}
case CF_ENHMETAFILE:
{
return LoadStringW(hInstance, STRING_CF_ENHMETAFILE, lpszFormat, cch);
}
case CF_METAFILEPICT:
{
return LoadStringW(hInstance, STRING_CF_METAFILEPICT, lpszFormat, cch);
}
case CF_PALETTE:
{
return LoadStringW(hInstance, STRING_CF_PALETTE, lpszFormat, cch);
}
case CF_DIBV5:
{
return LoadStringW(hInstance, STRING_CF_DIBV5, lpszFormat, cch);
}
case CF_SYLK:
{
return LoadStringW(hInstance, STRING_CF_SYLK, lpszFormat, cch);
}
case CF_DIF:
{
return LoadStringW(hInstance, STRING_CF_DIF, lpszFormat, cch);
}
case CF_HDROP:
{
return LoadStringW(hInstance, STRING_CF_HDROP, lpszFormat, cch);
}
default:
{
return 0;
}
}
}
void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR lpszFormat, UINT cch)
{
if (!GetPredefinedClipboardFormatName(hInstance, uFormat, lpszFormat, cch))
{
if (!GetClipboardFormatName(uFormat, lpszFormat, cch))
{
LoadStringW(hInstance, STRING_CF_UNKNOWN, lpszFormat, cch);
}
}
}
void DeleteClipboardContent(void)
{
if (!OpenClipboard(NULL))
{
ShowLastWin32Error(Globals.hMainWnd);
return;
}
if (!EmptyClipboard())
{
ShowLastWin32Error(Globals.hMainWnd);
}
if (!CloseClipboard())
{
ShowLastWin32Error(Globals.hMainWnd);
}
}
UINT GetAutomaticClipboardFormat(void)
{
UINT uFormatList[] = {CF_UNICODETEXT, CF_ENHMETAFILE, CF_METAFILEPICT, CF_DIBV5, CF_DIB, CF_BITMAP};
return GetPriorityClipboardFormat(uFormatList, 6);
}
BOOL IsClipboardFormatSupported(UINT uFormat)
{
switch (uFormat)
{
case CF_UNICODETEXT:
case CF_BITMAP:
case CF_ENHMETAFILE:
case CF_METAFILEPICT:
case CF_DIB:
case CF_DIBV5:
{
return TRUE;
}
default:
{
return FALSE;
}
}
}

View file

@ -0,0 +1,13 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/cliputils.h
* PURPOSE: Clipboard helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR lpszFormat, UINT cch);
void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR lpszFormat, UINT cch);
void DeleteClipboardContent(void);
UINT GetAutomaticClipboardFormat(void);
BOOL IsClipboardFormatSupported(UINT uFormat);

View file

@ -0,0 +1,61 @@
LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL
ID_ACCEL ACCELERATORS
BEGIN
VK_DELETE, CMD_DELETE, VIRTKEY
END
MAIN_MENU MENU
BEGIN
POPUP "&Datei"
BEGIN
MENUITEM "Ö&ffnen...", CMD_OPEN, GRAYED
MENUITEM "Speichern &unter...", CMD_SAVE_AS, GRAYED
MENUITEM SEPARATOR
MENUITEM "&Beenden", CMD_EXIT
END
POPUP "&Bearbeiten"
BEGIN
MENUITEM "&Löschen\tEntf", CMD_DELETE
END
POPUP "&Anzeige"
BEGIN
MENUITEM "&Automatisch", CMD_AUTOMATIC
END
POPUP "&Hilfe"
BEGIN
MENUITEM "&Hilfethemen", CMD_HELP
MENUITEM SEPARATOR
MENUITEM "Inf&o", CMD_ABOUT
END
END
STRINGTABLE
BEGIN
STRING_CLIPBOARD "Zwischenablage"
STRING_DELETE_MSG "Soll der Inhalt der Zwischenablage gelöscht werden?"
STRING_DELETE_TITLE "Zwischenablage löschen"
END
STRINGTABLE
BEGIN
STRING_CF_UNKNOWN "Unbekanntes Format"
STRING_CF_TEXT "Text"
STRING_CF_BITMAP "Bitmap"
STRING_CF_OEMTEXT "OEM-Text"
STRING_CF_UNICODETEXT "Unicodetext"
STRING_CF_DIB "DIB-Bitmap"
STRING_CF_LOCALE "Gebietsschema"
STRING_CF_ENHMETAFILE "Erweiterte Metadatei"
STRING_CF_METAFILEPICT "Metadatei"
STRING_CF_PALETTE "Farbpalette"
STRING_CF_DIBV5 "DIB-Bitmap (Version 5)"
STRING_CF_SYLK "Symbolic Link Format"
STRING_CF_DIF "Data Interchange Format"
STRING_CF_HDROP "Drop-Daten"
END
STRINGTABLE
BEGIN
ERROR_UNSUPPORTED_FORMAT "Die Daten in der Zwischenablage liegen in einem Format vor, welches nicht angezeigt werden kann."
END

View file

@ -0,0 +1,61 @@
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
ID_ACCEL ACCELERATORS
BEGIN
VK_DELETE, CMD_DELETE, VIRTKEY
END
MAIN_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...", CMD_OPEN, GRAYED
MENUITEM "Save &as...", CMD_SAVE_AS, GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", CMD_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "&Delete\tDel", CMD_DELETE
END
POPUP "&Display"
BEGIN
MENUITEM "&Automatic", CMD_AUTOMATIC
END
POPUP "&Help"
BEGIN
MENUITEM "&Help Topics", CMD_HELP
MENUITEM SEPARATOR
MENUITEM "&About", CMD_ABOUT
END
END
STRINGTABLE
BEGIN
STRING_CLIPBOARD "Clipboard"
STRING_DELETE_MSG "Clear contents of the Clipboard?"
STRING_DELETE_TITLE "Clear Clipboard"
END
STRINGTABLE
BEGIN
STRING_CF_UNKNOWN "Unknown Format"
STRING_CF_TEXT "Text"
STRING_CF_BITMAP "Bitmap"
STRING_CF_OEMTEXT "OEM Text"
STRING_CF_UNICODETEXT "Unicode Text"
STRING_CF_DIB "DIB Bitmap"
STRING_CF_LOCALE "Locale Data"
STRING_CF_ENHMETAFILE "Enhanced Metafile"
STRING_CF_METAFILEPICT "Metafile"
STRING_CF_PALETTE "Color Palette"
STRING_CF_DIBV5 "DIB Bitmap (Version 5)"
STRING_CF_SYLK "Symbolic Link Format"
STRING_CF_DIF "Data Interchange Format"
STRING_CF_HDROP "Drop Data"
END
STRINGTABLE
BEGIN
ERROR_UNSUPPORTED_FORMAT "The clipboard contains data in a format, that cannot be displayed."
END

View file

@ -0,0 +1,61 @@
LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL
ID_ACCEL ACCELERATORS
BEGIN
VK_DELETE, CMD_DELETE, VIRTKEY
END
MAIN_MENU MENU
BEGIN
POPUP "&Fichier"
BEGIN
MENUITEM "&Ouvrir...", CMD_OPEN, GRAYED
MENUITEM "&Enregistrer sous...", CMD_SAVE_AS, GRAYED
MENUITEM SEPARATOR
MENUITEM "&Quitter", CMD_EXIT
END
POPUP "&Edition"
BEGIN
MENUITEM "&Supprimer\tSuppr", CMD_DELETE
END
POPUP "&Affichage"
BEGIN
MENUITEM "&Automatique", CMD_AUTOMATIC
END
POPUP "&Aide"
BEGIN
MENUITEM "&Rubriques d'aide", CMD_HELP
MENUITEM SEPARATOR
MENUITEM "&À propos...", CMD_ABOUT
END
END
STRINGTABLE
BEGIN
STRING_CLIPBOARD "Presse-papiers"
STRING_DELETE_MSG "Voulez-vous effacer le contenu du Presse-papiers ?"
STRING_DELETE_TITLE "Effacer le Presse-papiers"
END
STRINGTABLE
BEGIN
STRING_CF_UNKNOWN "Format inconnu"
STRING_CF_TEXT "Texte"
STRING_CF_BITMAP "Bitmap"
STRING_CF_OEMTEXT "Texte OEM"
STRING_CF_UNICODETEXT "Texte Unicode"
STRING_CF_DIB "DIB Bitmap"
STRING_CF_LOCALE "Locale Data"
STRING_CF_ENHMETAFILE "Enhanced Metafile"
STRING_CF_METAFILEPICT "Metafile"
STRING_CF_PALETTE "Color Palette"
STRING_CF_DIBV5 "DIB Bitmap (Version 5)"
STRING_CF_SYLK "Symbolic Link Format"
STRING_CF_DIF "Data Interchange Format"
STRING_CF_HDROP "Drop Data"
END
STRINGTABLE
BEGIN
ERROR_UNSUPPORTED_FORMAT "Le Presse-Papiers contient des données dans un format qui ne peut être affiché."
END

View file

@ -0,0 +1,33 @@
#ifndef _CLIPBRD_PCH_
#define _CLIPBRD_PCH_
#pragma once
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <wingdi.h>
#include <shellapi.h>
#include <htmlhelp.h>
#include "resources.h"
#include "cliputils.h"
#include "winutils.h"
#define MAX_STRING_LEN 255
#define DISPLAY_MENU_POS 2
#define CF_NONE 0
typedef struct _CLIPBOARD_GLOBALS
{
HINSTANCE hInstance;
HWND hMainWnd;
HWND hWndNext;
HMENU hMenu;
UINT uDisplayFormat;
UINT uCheckedItem;
} CLIPBOARD_GLOBALS;
extern CLIPBOARD_GLOBALS Globals;
#endif /* _CLIPBRD_PCH_ */

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -0,0 +1,35 @@
#pragma once
#define MAIN_MENU 100
#define CLIP_ICON 101
#define ID_ACCEL 102
#define CMD_OPEN 100
#define CMD_SAVE_AS 101
#define CMD_EXIT 102
#define CMD_DELETE 103
#define CMD_HELP 105
#define CMD_ABOUT 106
#define CMD_AUTOMATIC 1000
#define STRING_CLIPBOARD 100
#define STRING_DELETE_MSG 101
#define STRING_DELETE_TITLE 102
#define STRING_CF_UNKNOWN 200
#define STRING_CF_TEXT 201
#define STRING_CF_BITMAP 202
#define STRING_CF_OEMTEXT 203
#define STRING_CF_UNICODETEXT 204
#define STRING_CF_DIB 205
#define STRING_CF_LOCALE 206
#define STRING_CF_ENHMETAFILE 207
#define STRING_CF_METAFILEPICT 208
#define STRING_CF_PALETTE 209
#define STRING_CF_DIBV5 210
#define STRING_CF_SYLK 211
#define STRING_CF_DIF 212
#define STRING_CF_HDROP 213
#define ERROR_UNSUPPORTED_FORMAT 300

View file

@ -0,0 +1,180 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/winutils.c
* PURPOSE: Miscellaneous helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
#include "precomp.h"
void ShowLastWin32Error(HWND hwndParent)
{
DWORD dwError;
LPWSTR lpMsgBuf = NULL;
dwError = GetLastError();
if (dwError == NO_ERROR)
return;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwError, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
MessageBoxW(hwndParent, lpMsgBuf, NULL, MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
}
void BringWindowToFront(HWND hWnd)
{
if (IsIconic(hWnd))
{
ShowWindow(hWnd, SW_RESTORE);
SetForegroundWindow(hWnd);
}
else
{
SetForegroundWindow(hWnd);
}
}
int DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat)
{
LPWSTR lpBuffer;
int nCount;
nCount = LoadStringW(hInstance, uID, (LPWSTR)&lpBuffer, 0);
if (nCount)
{
return DrawTextW(hDC, lpBuffer, nCount, lpRect, uFormat);
}
else
{
return 0;
}
}
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType)
{
MSGBOXPARAMSW mb;
ZeroMemory(&mb, sizeof(mb));
mb.cbSize = sizeof(mb);
mb.hwndOwner = hWnd;
mb.hInstance = hInstance;
mb.lpszText = MAKEINTRESOURCEW(uText);
mb.lpszCaption = MAKEINTRESOURCEW(uCaption);
mb.dwStyle = uType;
mb.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
return MessageBoxIndirectW(&mb);
}
void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat)
{
HGLOBAL hGlobal;
LPWSTR lpchText;
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(CF_UNICODETEXT);
if (!hGlobal)
return;
lpchText = GlobalLock(hGlobal);
if (!lpchText)
return;
DrawTextW(hDC, lpchText, -1, lpRect, uFormat);
GlobalUnlock(hGlobal);
CloseClipboard();
}
void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop)
{
HDC hdcMem;
HBITMAP hbm;
if (!OpenClipboard(NULL))
return;
hdcMem = CreateCompatibleDC(hdcDest);
if (hdcMem)
{
hbm = (HBITMAP)GetClipboardData(CF_BITMAP);
SelectObject(hdcMem, hbm);
BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcMem, nXSrc, nYSrc, dwRop);
DeleteDC(hdcMem);
}
CloseClipboard();
}
void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest, int XSrc, int YSrc, UINT uStartScan, UINT fuColorUse)
{
LPBITMAPINFOHEADER lpInfoHeader;
LPBYTE lpBits;
HGLOBAL hGlobal;
INT iPalSize;
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(CF_DIBV5);
if (!hGlobal)
return;
lpInfoHeader = GlobalLock(hGlobal);
if (!lpInfoHeader)
return;
if (lpInfoHeader->biBitCount < 16)
{
iPalSize = (1 << lpInfoHeader->biBitCount) * 4;
}
else
{
iPalSize = 0;
}
lpBits = (LPBYTE)lpInfoHeader + lpInfoHeader->biSize + iPalSize;
SetDIBitsToDevice(hdc, XDest, YDest, lpInfoHeader->biWidth, lpInfoHeader->biHeight, XSrc, YSrc, uStartScan, lpInfoHeader->biHeight, lpBits, (LPBITMAPINFO)lpInfoHeader, fuColorUse);
GlobalUnlock(hGlobal);
CloseClipboard();
}
void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
{
LPMETAFILEPICT mp;
HGLOBAL hGlobal;
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(CF_METAFILEPICT);
if (!hGlobal)
return;
mp = (LPMETAFILEPICT)GlobalLock(hGlobal);
if (!mp)
return;
SetMapMode(hdc, mp->mm);
SetViewportExtEx(hdc, lpRect->right, lpRect->bottom, NULL);
SetViewportOrgEx(hdc, lpRect->left, lpRect->top, NULL);
PlayMetaFile(hdc, mp->hMF);
GlobalUnlock(hGlobal);
CloseClipboard();
}
void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
{
HENHMETAFILE hEmf;
if (!OpenClipboard(NULL))
return;
hEmf = GetClipboardData(CF_ENHMETAFILE);
PlayEnhMetaFile(hdc, hEmf, lpRect);
CloseClipboard();
}

View file

@ -0,0 +1,17 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/winutils.c
* PURPOSE: Miscellaneous helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
void ShowLastWin32Error(HWND hwndParent);
void BringWindowToFront(HWND hWnd);
int DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat);
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType);
void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat);
void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop);
void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest, int XSrc, int YSrc, UINT uStartScan, UINT fuColorUse);
void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect);
void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect);