2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Clipboard Viewer
4 * FILE: base/applications/clipbrd/winutils.c
5 * PURPOSE: Miscellaneous helper functions.
6 * PROGRAMMERS: Ricardo Hanke
11 void ShowLastWin32Error(HWND hwndParent
)
14 LPWSTR lpMsgBuf
= NULL
;
16 dwError
= GetLastError();
17 if (dwError
== NO_ERROR
)
20 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
21 NULL
, dwError
, 0, (LPWSTR
)&lpMsgBuf
, 0, NULL
);
22 MessageBoxW(hwndParent
, lpMsgBuf
, NULL
, MB_OK
| MB_ICONERROR
);
26 void BringWindowToFront(HWND hWnd
)
30 ShowWindow(hWnd
, SW_RESTORE
);
31 SetForegroundWindow(hWnd
);
35 SetForegroundWindow(hWnd
);
39 int DrawTextFromResource(HINSTANCE hInstance
, UINT uID
, HDC hDC
, LPRECT lpRect
, UINT uFormat
)
44 nCount
= LoadStringW(hInstance
, uID
, (LPWSTR
)&lpBuffer
, 0);
47 return DrawTextW(hDC
, lpBuffer
, nCount
, lpRect
, uFormat
);
55 int MessageBoxRes(HWND hWnd
, HINSTANCE hInstance
, UINT uText
, UINT uCaption
, UINT uType
)
59 ZeroMemory(&mb
, sizeof(mb
));
60 mb
.cbSize
= sizeof(mb
);
62 mb
.hInstance
= hInstance
;
63 mb
.lpszText
= MAKEINTRESOURCEW(uText
);
64 mb
.lpszCaption
= MAKEINTRESOURCEW(uCaption
);
66 mb
.dwLanguageId
= MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
);
68 return MessageBoxIndirectW(&mb
);
71 void DrawTextFromClipboard(HDC hDC
, LPRECT lpRect
, UINT uFormat
)
76 if (!OpenClipboard(NULL
))
79 hGlobal
= GetClipboardData(CF_UNICODETEXT
);
83 lpchText
= GlobalLock(hGlobal
);
87 DrawTextW(hDC
, lpchText
, -1, lpRect
, uFormat
);
88 GlobalUnlock(hGlobal
);
92 void BitBltFromClipboard(HDC hdcDest
, int nXDest
, int nYDest
, int nWidth
, int nHeight
, int nXSrc
, int nYSrc
, DWORD dwRop
)
97 if (!OpenClipboard(NULL
))
100 hdcMem
= CreateCompatibleDC(hdcDest
);
103 hbm
= (HBITMAP
)GetClipboardData(CF_BITMAP
);
104 SelectObject(hdcMem
, hbm
);
105 BitBlt(hdcDest
, nXDest
, nYDest
, nWidth
, nHeight
, hdcMem
, nXSrc
, nYSrc
, dwRop
);
111 void SetDIBitsToDeviceFromClipboard(UINT uFormat
, HDC hdc
, int XDest
, int YDest
, int XSrc
, int YSrc
, UINT uStartScan
, UINT fuColorUse
)
113 LPBITMAPINFOHEADER lpInfoHeader
;
118 if (!OpenClipboard(NULL
))
121 hGlobal
= GetClipboardData(uFormat
);
125 lpInfoHeader
= GlobalLock(hGlobal
);
129 if (lpInfoHeader
->biBitCount
< 16)
131 iPalSize
= (1 << lpInfoHeader
->biBitCount
) * 4;
138 lpBits
= (LPBYTE
)lpInfoHeader
+ lpInfoHeader
->biSize
+ iPalSize
;
140 SetDIBitsToDevice(hdc
, XDest
, YDest
, lpInfoHeader
->biWidth
, lpInfoHeader
->biHeight
, XSrc
, YSrc
, uStartScan
, lpInfoHeader
->biHeight
, lpBits
, (LPBITMAPINFO
)lpInfoHeader
, fuColorUse
);
142 GlobalUnlock(hGlobal
);
146 void PlayMetaFileFromClipboard(HDC hdc
, const RECT
*lpRect
)
151 if (!OpenClipboard(NULL
))
154 hGlobal
= GetClipboardData(CF_METAFILEPICT
);
158 mp
= (LPMETAFILEPICT
)GlobalLock(hGlobal
);
162 SetMapMode(hdc
, mp
->mm
);
163 SetViewportExtEx(hdc
, lpRect
->right
, lpRect
->bottom
, NULL
);
164 SetViewportOrgEx(hdc
, lpRect
->left
, lpRect
->top
, NULL
);
165 PlayMetaFile(hdc
, mp
->hMF
);
166 GlobalUnlock(hGlobal
);
170 void PlayEnhMetaFileFromClipboard(HDC hdc
, const RECT
*lpRect
)
174 if (!OpenClipboard(NULL
))
177 hEmf
= GetClipboardData(CF_ENHMETAFILE
);
178 PlayEnhMetaFile(hdc
, hEmf
, lpRect
);