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,29 +126,38 @@ 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) { GetClientRect(button, &r);
case CDDS_PREPAINT: part = 3;
GetClientRect(button, &r); //TODO if ((tbb.fsStyle & BTNS_DROPDOWN) != 0)
part = 3; //TODO part = 4;
//TODO if ((tbb.fsStyle & BTNS_DROPDOWN) != 0) state = 1;
//TODO part = 4; // TODO this doesn't work; both keyboard and mouse are listed as HOT
state = 1; if ((nm->uItemState & CDIS_FOCUS) != 0)
// TODO this doesn't work; both keyboard and mouse are listed as HOT state = 4;
if ((nm->uItemState & CDIS_FOCUS) != 0) if ((nm->uItemState & CDIS_HOT) != 0)
state = 4; state = 2;
if ((nm->uItemState & CDIS_HOT) != 0) if ((nm->uItemState & CDIS_SELECTED) != 0)
state = 2; state = 3;
if ((nm->uItemState & CDIS_SELECTED) != 0) DrawThemeParentBackground(button, nm->hdc, &(nm->rc));
state = 3; DrawThemeBackground(theme, nm->hdc,
DrawThemeParentBackground(button, nm->hdc, &(nm->rc)); part, state,
DrawThemeBackground(theme, nm->hdc, &r, &(nm->rc));
part, state, n = SendMessageW(button, WM_GETTEXTLENGTH, 0, 0);
&r, &(nm->rc)); buf = new WCHAR[n + 1];
return CDRF_NEWFONT; GetWindowTextW(button, buf, n + 1);
} SetBkMode(nm->hdc, TRANSPARENT);
return CDRF_DODEFAULT; 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;
} }