diff options
Diffstat (limited to 'redo/sizing_windows.c')
| -rw-r--r-- | redo/sizing_windows.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/redo/sizing_windows.c b/redo/sizing_windows.c index 133cbcc..e6f27a6 100644 --- a/redo/sizing_windows.c +++ b/redo/sizing_windows.c @@ -38,3 +38,24 @@ void moveWindow(HWND hwnd, int x, int y, int width, int height) if (MoveWindow(hwnd, x, y, width, height, TRUE) == 0) xpanic("error setting window/control rect", GetLastError()); } + +LONG controlTextLength(HWND hwnd, LPWSTR text) +{ + HDC dc; + HFONT prev; + SIZE size; + + dc = GetDC(hwnd); + if (dc == NULL) + xpanic("error getting DC of control for text length", GetLastError()); + prev = SelectObject(dc, controlFont); + if (prev == NULL) + xpanic("error setting control font to DC for text length", GetLastError()); + if (GetTextExtentPoint32W(dc, text, wcslen(text), &size) == 0) + xpanic("error actually getting text length", GetLastError()); + if (SelectObject(dc, prev) != controlFont) + xpanic("error restoring previous control font to DC for text length", GetLastError()); + if (ReleaseDC(hwnd, dc) == 0) + xpanic("error releasing DC of control for text length", GetLastError()); + return size.cx; +} |
