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:
parent
95c42353fb
commit
2c26f3e4ca
|
@ -16,6 +16,11 @@ func xpanic(msg *C.char, lasterr C.DWORD) {
|
||||||
panic(fmt.Errorf("%s: %s", C.GoString(msg), syscall.Errno(lasterr)))
|
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
|
//export xmissedmsg
|
||||||
func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
|
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)))
|
panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f)))
|
||||||
|
|
|
@ -193,10 +193,13 @@ static HTHEME theme = NULL;
|
||||||
|
|
||||||
static void openTheme(HWND hwnd)
|
static void openTheme(HWND hwnd)
|
||||||
{
|
{
|
||||||
if (theme != NULL)
|
HRESULT res;
|
||||||
// TODO save HRESULT
|
|
||||||
if (CloseThemeData(theme) != S_OK)
|
if (theme != NULL) {
|
||||||
xpanic("error closing theme", GetLastError());
|
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()
|
// ignore error; if it can't be done, we can fall back to DrawFrameControl()
|
||||||
theme = OpenThemeData(hwnd, L"button");
|
theme = OpenThemeData(hwnd, L"button");
|
||||||
}
|
}
|
||||||
|
@ -215,10 +218,11 @@ static int themestates[checkboxnStates] = {
|
||||||
static SIZE getStateSize(HDC dc, int cbState)
|
static SIZE getStateSize(HDC dc, int cbState)
|
||||||
{
|
{
|
||||||
SIZE s;
|
SIZE s;
|
||||||
|
HRESULT res;
|
||||||
|
|
||||||
// TODO use HRESULT
|
res = GetThemePartSize(theme, dc, BP_CHECKBOX, themestates[cbState], NULL, TS_DRAW, &s);
|
||||||
if (GetThemePartSize(theme, dc, BP_CHECKBOX, themestates[cbState], NULL, TS_DRAW, &s) != S_OK)
|
if (res != S_OK)
|
||||||
xpanic("error getting theme part size", GetLastError());
|
xpanichresult("error getting theme part size", res);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +234,7 @@ static HBITMAP drawThemeImage(HDC dc, int width, int height, int cbState)
|
||||||
RECT r;
|
RECT r;
|
||||||
HDC drawDC;
|
HDC drawDC;
|
||||||
HBITMAP prevbitmap;
|
HBITMAP prevbitmap;
|
||||||
|
HRESULT res;
|
||||||
|
|
||||||
r.left = 0;
|
r.left = 0;
|
||||||
r.top = 0;
|
r.top = 0;
|
||||||
|
@ -253,9 +258,9 @@ static HBITMAP drawThemeImage(HDC dc, int width, int height, int cbState)
|
||||||
prevbitmap = SelectObject(drawDC, bitmap);
|
prevbitmap = SelectObject(drawDC, bitmap);
|
||||||
if (prevbitmap == NULL)
|
if (prevbitmap == NULL)
|
||||||
xpanic("error selecting checkbox image list bitmap into DC", GetLastError());
|
xpanic("error selecting checkbox image list bitmap into DC", GetLastError());
|
||||||
// TODO get HRESULT
|
res = DrawThemeBackground(theme, drawDC, BP_CHECKBOX, themestates[cbState], &r, NULL);
|
||||||
if (DrawThemeBackground(theme, drawDC, BP_CHECKBOX, themestates[cbState], &r, NULL) != S_OK)
|
if (res != S_OK)
|
||||||
xpanic("error drawing checkbox image", GetLastError());
|
xpanichresult("error drawing checkbox image", res);
|
||||||
if (SelectObject(drawDC, prevbitmap) != bitmap)
|
if (SelectObject(drawDC, prevbitmap) != bitmap)
|
||||||
xpanic("error selecting previous bitmap into checkbox image's DC", GetLastError());
|
xpanic("error selecting previous bitmap into checkbox image's DC", GetLastError());
|
||||||
if (DeleteDC(drawDC) == 0)
|
if (DeleteDC(drawDC) == 0)
|
||||||
|
|
Loading…
Reference in New Issue