More experimentation. DirectUI is doing something with the sizing that I'm not...

This commit is contained in:
Pietro Gagliardi 2018-10-16 23:19:23 -04:00
parent 83ba0b1a41
commit 7e34fac79d
1 changed files with 38 additions and 27 deletions

View File

@ -126,10 +126,12 @@ LRESULT drawExplorerButton(NMCUSTOMDRAW *nm)
HWND button; HWND button;
RECT r; RECT r;
int part, state; int part, state;
LRESULT n;
WCHAR *buf;
if (nm->dwDrawStage != CDDS_PREPAINT)
return CDRF_DODEFAULT;
button = nm->hdr.hwndFrom; button = nm->hdr.hwndFrom;
switch (nm->dwDrawStage) {
case CDDS_PREPAINT:
GetClientRect(button, &r); GetClientRect(button, &r);
part = 3; part = 3;
//TODO if ((tbb.fsStyle & BTNS_DROPDOWN) != 0) //TODO if ((tbb.fsStyle & BTNS_DROPDOWN) != 0)
@ -146,9 +148,16 @@ LRESULT drawExplorerButton(NMCUSTOMDRAW *nm)
DrawThemeBackground(theme, nm->hdc, DrawThemeBackground(theme, nm->hdc,
part, state, part, state,
&r, &(nm->rc)); &r, &(nm->rc));
return CDRF_NEWFONT; n = SendMessageW(button, WM_GETTEXTLENGTH, 0, 0);
} buf = new WCHAR[n + 1];
return CDRF_DODEFAULT; GetWindowTextW(button, buf, n + 1);
SetBkMode(nm->hdc, TRANSPARENT);
DrawThemeText(textstyleTheme, nm->hdc,
4, 0,
buf, n, DT_CENTER | DT_VCENTER | DT_SINGLELINE,
0, &r);
delete[] buf;
return CDRF_SKIPDEFAULT;
} }
void onWM_CREATE(HWND hwnd) void onWM_CREATE(HWND hwnd)
@ -264,11 +273,14 @@ SIZE buttonSize(HWND button)
WCHAR *buf; WCHAR *buf;
RECT textRect; RECT textRect;
RECT contentRect; RECT contentRect;
RECT extentRect; MARGINS margins;
SIZE ret; SIZE ret;
dc = GetDC(button); dc = GetDC(button);
printf("%08I32X ", GetThemePartSize(theme, dc, 3, 1, NULL, TS_TRUE, &ret));
printf("%d %d\n", ret.cx, ret.cy);
n = SendMessageW(button, WM_GETTEXTLENGTH, 0, 0); n = SendMessageW(button, WM_GETTEXTLENGTH, 0, 0);
buf = new WCHAR[n + 1]; buf = new WCHAR[n + 1];
GetWindowTextW(button, buf, n + 1); GetWindowTextW(button, buf, n + 1);
@ -280,6 +292,8 @@ SIZE buttonSize(HWND button)
contentRect.top = 0; contentRect.top = 0;
contentRect.right = textRect.right - textRect.left; contentRect.right = textRect.right - textRect.left;
contentRect.bottom = textRect.bottom - textRect.top; contentRect.bottom = textRect.bottom - textRect.top;
delete[] buf;
printf("%d %d\n", contentRect.right, contentRect.bottom);
if (button == leftButtons[0] || button == leftButtons[1] || button == leftButtons[2]) { if (button == leftButtons[0] || button == leftButtons[1] || button == leftButtons[2]) {
SIZE arrowSize; SIZE arrowSize;
@ -298,13 +312,10 @@ SIZE buttonSize(HWND button)
// TODO these should be DIPs // TODO these should be DIPs
contentRect.right += 13 * 2; contentRect.right += 13 * 2;
contentRect.bottom += 5 * 2; contentRect.bottom += 5 * 2;
GetThemeBackgroundExtent(theme, dc,
3, 1,
&contentRect, &extentRect);
ReleaseDC(button, dc); ReleaseDC(button, dc);
ret.cx = extentRect.right - extentRect.left; ret.cx = contentRect.right - contentRect.left;
ret.cy = extentRect.bottom - extentRect.top; ret.cy = contentRect.bottom - contentRect.top;
return ret; return ret;
} }