[CLIPBRD]

- Display the application icon in program's about dialog.
- Add missing DT_NOPREFIX flag to DrawText() calls.
- Let ShowLastWin32Error() show an error message even if the last error code is zero.
- Remove the calls to OpenClipboard() and CloseClipboard() from the functions in winutils.c and let the caller open and close the clipboard instead.

Patch by Ricardo Hanke

CORE-10657

svn path=/trunk/; revision=70328
This commit is contained in:
Hermès Bélusca-Maïto 2015-12-12 20:34:21 +00:00
parent c1d7cca159
commit 1153d6397c
2 changed files with 14 additions and 26 deletions

View file

@ -234,8 +234,12 @@ static int ClipboardCommandHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
case CMD_ABOUT: case CMD_ABOUT:
{ {
WCHAR szTitle[MAX_STRING_LEN]; WCHAR szTitle[MAX_STRING_LEN];
HICON hIcon;
hIcon = LoadIconW(Globals.hInstance, MAKEINTRESOURCE(CLIP_ICON));
LoadStringW(Globals.hInstance, STRING_CLIPBOARD, szTitle, ARRAYSIZE(szTitle)); LoadStringW(Globals.hInstance, STRING_CLIPBOARD, szTitle, ARRAYSIZE(szTitle));
ShellAboutW(Globals.hMainWnd, szTitle, 0, NULL); ShellAboutW(Globals.hMainWnd, szTitle, 0, hIcon);
DeleteObject(hIcon);
break; break;
} }
@ -253,6 +257,11 @@ static void ClipboardPaintHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
PAINTSTRUCT ps; PAINTSTRUCT ps;
RECT rc; RECT rc;
if (!OpenClipboard(NULL))
{
return;
}
hdc = BeginPaint(hWnd, &ps); hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rc); GetClientRect(hWnd, &rc);
@ -265,7 +274,7 @@ static void ClipboardPaintHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
case CF_UNICODETEXT: case CF_UNICODETEXT:
{ {
DrawTextFromClipboard(hdc, &rc, DT_LEFT); DrawTextFromClipboard(hdc, &rc, DT_LEFT | DT_NOPREFIX);
break; break;
} }
@ -301,13 +310,14 @@ static void ClipboardPaintHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
default: default:
{ {
DrawTextFromResource(Globals.hInstance, ERROR_UNSUPPORTED_FORMAT, hdc, &rc, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX);
DrawTextFromResource(Globals.hInstance, ERROR_UNSUPPORTED_FORMAT, hdc, &rc, DT_CENTER | DT_WORDBREAK);
break; break;
} }
} }
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
CloseClipboard();
} }
static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

View file

@ -14,8 +14,6 @@ void ShowLastWin32Error(HWND hwndParent)
LPWSTR lpMsgBuf = NULL; LPWSTR lpMsgBuf = NULL;
dwError = GetLastError(); dwError = GetLastError();
if (dwError == NO_ERROR)
return;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwError, 0, (LPWSTR)&lpMsgBuf, 0, NULL); NULL, dwError, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
@ -73,9 +71,6 @@ void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat)
HGLOBAL hGlobal; HGLOBAL hGlobal;
LPWSTR lpchText; LPWSTR lpchText;
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(CF_UNICODETEXT); hGlobal = GetClipboardData(CF_UNICODETEXT);
if (!hGlobal) if (!hGlobal)
return; return;
@ -86,7 +81,6 @@ void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat)
DrawTextW(hDC, lpchText, -1, lpRect, uFormat); DrawTextW(hDC, lpchText, -1, lpRect, uFormat);
GlobalUnlock(hGlobal); GlobalUnlock(hGlobal);
CloseClipboard();
} }
void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop) void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop)
@ -94,9 +88,6 @@ void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nH
HDC hdcMem; HDC hdcMem;
HBITMAP hbm; HBITMAP hbm;
if (!OpenClipboard(NULL))
return;
hdcMem = CreateCompatibleDC(hdcDest); hdcMem = CreateCompatibleDC(hdcDest);
if (hdcMem) if (hdcMem)
{ {
@ -105,7 +96,6 @@ void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nH
BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcMem, nXSrc, nYSrc, dwRop); BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcMem, nXSrc, nYSrc, dwRop);
DeleteDC(hdcMem); DeleteDC(hdcMem);
} }
CloseClipboard();
} }
void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest, int XSrc, int YSrc, UINT uStartScan, UINT fuColorUse) void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest, int XSrc, int YSrc, UINT uStartScan, UINT fuColorUse)
@ -115,9 +105,6 @@ void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest,
HGLOBAL hGlobal; HGLOBAL hGlobal;
INT iPalSize; INT iPalSize;
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(uFormat); hGlobal = GetClipboardData(uFormat);
if (!hGlobal) if (!hGlobal)
return; return;
@ -140,7 +127,6 @@ void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest,
SetDIBitsToDevice(hdc, XDest, YDest, lpInfoHeader->biWidth, lpInfoHeader->biHeight, XSrc, YSrc, uStartScan, lpInfoHeader->biHeight, lpBits, (LPBITMAPINFO)lpInfoHeader, fuColorUse); SetDIBitsToDevice(hdc, XDest, YDest, lpInfoHeader->biWidth, lpInfoHeader->biHeight, XSrc, YSrc, uStartScan, lpInfoHeader->biHeight, lpBits, (LPBITMAPINFO)lpInfoHeader, fuColorUse);
GlobalUnlock(hGlobal); GlobalUnlock(hGlobal);
CloseClipboard();
} }
void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect) void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
@ -148,9 +134,6 @@ void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
LPMETAFILEPICT mp; LPMETAFILEPICT mp;
HGLOBAL hGlobal; HGLOBAL hGlobal;
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(CF_METAFILEPICT); hGlobal = GetClipboardData(CF_METAFILEPICT);
if (!hGlobal) if (!hGlobal)
return; return;
@ -164,17 +147,12 @@ void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
SetViewportOrgEx(hdc, lpRect->left, lpRect->top, NULL); SetViewportOrgEx(hdc, lpRect->left, lpRect->top, NULL);
PlayMetaFile(hdc, mp->hMF); PlayMetaFile(hdc, mp->hMF);
GlobalUnlock(hGlobal); GlobalUnlock(hGlobal);
CloseClipboard();
} }
void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect) void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect)
{ {
HENHMETAFILE hEmf; HENHMETAFILE hEmf;
if (!OpenClipboard(NULL))
return;
hEmf = GetClipboardData(CF_ENHMETAFILE); hEmf = GetClipboardData(CF_ENHMETAFILE);
PlayEnhMetaFile(hdc, hEmf, lpRect); PlayEnhMetaFile(hdc, hEmf, lpRect);
CloseClipboard();
} }