Added a function to the Windows backend to keep track of text length. This will be important for sizing purposes.

This commit is contained in:
Pietro Gagliardi 2014-08-01 19:15:03 -04:00
parent b31ce95b33
commit 785d6ac4fd
2 changed files with 24 additions and 0 deletions

View File

@ -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) if (MoveWindow(hwnd, x, y, width, height, TRUE) == 0)
xpanic("error setting window/control rect", GetLastError()); 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;
}

View File

@ -18,6 +18,8 @@
#include <commctrl.h> #include <commctrl.h>
#include <stdint.h> #include <stdint.h>
#include <uxtheme.h> #include <uxtheme.h>
#include <string.h>
#include <wchar.h>
/* global messages unique to everything */ /* global messages unique to everything */
enum { enum {
@ -68,6 +70,7 @@ extern int baseX;
extern int baseY; extern int baseY;
extern void calculateBaseUnits(HWND); extern void calculateBaseUnits(HWND);
extern void moveWindow(HWND, int, int, int, int); extern void moveWindow(HWND, int, int, int, int);
extern LONG controlTextLength(HWND, LPWSTR);
/* window_windows.c */ /* window_windows.c */
extern DWORD makeWindowWindowClass(char **); extern DWORD makeWindowWindowClass(char **);