From 93ead4043eeef17abbf23fe4abc403ac6ac89639 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 5 May 2015 13:12:48 -0400 Subject: [PATCH] Added a wrapper around MapWindowRect() to simplify error handling. This will be needed for future changes to windows/container.c. --- windows/container.c | 9 +-------- windows/uipriv_windows.h | 1 + windows/util.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/windows/container.c b/windows/container.c index daf15408..ae2347c6 100644 --- a/windows/container.c +++ b/windows/container.c @@ -21,7 +21,6 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) HDC cdc; HBITMAP bitmap, prevbitmap; HBRUSH brush; - DWORD le; parent = hwnd; for (;;) { @@ -61,13 +60,7 @@ static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) if (GetWindowRect(hwnd, &r) == 0) logLastError("error getting control's window rect in getControlBackgroundBrush()"); // the above is a window rect in screen coordinates; convert to parent coordinates - SetLastError(0); - if (MapWindowRect(NULL, parent, &r) == 0) { - le = GetLastError(); - SetLastError(le); // just to be safe - if (le != 0) - logLastError("error getting coordinates to change brush origin to in getControlBackgroundBrush()"); - } + mapWindowRect(NULL, parent, &r); if (SetBrushOrgEx(dc, -r.left, -r.top, NULL) == 0) logLastError("error setting brush origin in getControlBackgroundBrush()"); diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index 2fcf5b59..1d1fa4a4 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -51,6 +51,7 @@ extern HBRUSH hollowBrush; // util.c extern int windowClassOf(HWND, ...); +extern void mapWindowRect(HWND, HWND, RECT *); // text.c extern WCHAR *toUTF16(const char *); diff --git a/windows/util.c b/windows/util.c index 776a154a..8cb48837 100644 --- a/windows/util.c +++ b/windows/util.c @@ -81,3 +81,17 @@ void complain(const char *fmt, ...) va_end(ap); abort(); } + +// wrapper around MapWindowRect() that handles the complex error handling +void mapWindowRect(HWND from, HWND to, RECT *r) +{ + DWORD le; + + SetLastError(0); + if (MapWindowRect(from, to, r) == 0) { + le = GetLastError(); + SetLastError(le); // just to be safe + if (le != 0) + logLastError("error calling MapWindowRect() in mapWindowRect()"); + } +}