Added code for printing HRESULTs on Windows. (There is no HRESULT-to-string function because HRESULTs were designed to be extensible in vendor-specific ways.)

This commit is contained in:
Pietro Gagliardi 2014-08-25 01:49:11 -04:00
parent 95c42353fb
commit 2c26f3e4ca
2 changed files with 20 additions and 10 deletions

View File

@ -16,6 +16,11 @@ func xpanic(msg *C.char, lasterr C.DWORD) {
panic(fmt.Errorf("%s: %s", C.GoString(msg), syscall.Errno(lasterr)))
}
//export xpanichresult
func xpanichresult(msg *C.char, hresult C.HRESULT) {
panic(fmt.Errorf("%s; HRESULT: 0x%X", C.GoString(msg), hresult))
}
//export xmissedmsg
func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f)))

View File

@ -193,10 +193,13 @@ static HTHEME theme = NULL;
static void openTheme(HWND hwnd)
{
if (theme != NULL)
// TODO save HRESULT
if (CloseThemeData(theme) != S_OK)
xpanic("error closing theme", GetLastError());
HRESULT res;
if (theme != NULL) {
res = CloseThemeData(theme);
if (res != S_OK)
xpanichresult("error closing theme", res);
}
// ignore error; if it can't be done, we can fall back to DrawFrameControl()
theme = OpenThemeData(hwnd, L"button");
}
@ -215,10 +218,11 @@ static int themestates[checkboxnStates] = {
static SIZE getStateSize(HDC dc, int cbState)
{
SIZE s;
HRESULT res;
// TODO use HRESULT
if (GetThemePartSize(theme, dc, BP_CHECKBOX, themestates[cbState], NULL, TS_DRAW, &s) != S_OK)
xpanic("error getting theme part size", GetLastError());
res = GetThemePartSize(theme, dc, BP_CHECKBOX, themestates[cbState], NULL, TS_DRAW, &s);
if (res != S_OK)
xpanichresult("error getting theme part size", res);
return s;
}
@ -230,6 +234,7 @@ static HBITMAP drawThemeImage(HDC dc, int width, int height, int cbState)
RECT r;
HDC drawDC;
HBITMAP prevbitmap;
HRESULT res;
r.left = 0;
r.top = 0;
@ -253,9 +258,9 @@ static HBITMAP drawThemeImage(HDC dc, int width, int height, int cbState)
prevbitmap = SelectObject(drawDC, bitmap);
if (prevbitmap == NULL)
xpanic("error selecting checkbox image list bitmap into DC", GetLastError());
// TODO get HRESULT
if (DrawThemeBackground(theme, drawDC, BP_CHECKBOX, themestates[cbState], &r, NULL) != S_OK)
xpanic("error drawing checkbox image", GetLastError());
res = DrawThemeBackground(theme, drawDC, BP_CHECKBOX, themestates[cbState], &r, NULL);
if (res != S_OK)
xpanichresult("error drawing checkbox image", res);
if (SelectObject(drawDC, prevbitmap) != bitmap)
xpanic("error selecting previous bitmap into checkbox image's DC", GetLastError());
if (DeleteDC(drawDC) == 0)