diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-16 10:47:38 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-16 10:47:38 +0200 |
| commit | 090203fff7a05929816b49b19ea24959e2f518e5 (patch) | |
| tree | 88a7a227fa0f5d59307e972802fd2e4f4f84511e /alf/alfpanel.cpp | |
| parent | 02ffd45d5cb15b7d025b9a72a21ec1fd32de8c6f (diff) | |
panel: show centered text like Delphi
Diffstat (limited to 'alf/alfpanel.cpp')
| -rw-r--r-- | alf/alfpanel.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/alf/alfpanel.cpp b/alf/alfpanel.cpp index b8ef8b3..ce640a2 100644 --- a/alf/alfpanel.cpp +++ b/alf/alfpanel.cpp @@ -4,6 +4,7 @@ TCHAR *_alf_panelClass = NULL; typedef struct { ALFLayout layout; + HFONT font; } ALFPanelPriv; static void @@ -23,6 +24,27 @@ ALF_Panel_Paint(ALFPanelPriv *priv, HWND hwnd, HDC dc, RECT *r) { (void)priv; ALF_Compat_DrawThemeParentBackground(hwnd, dc, r); + + int textlen = GetWindowTextLength(hwnd); + if (textlen < 1) + return; + + TCHAR *textbuf = ALF_New(TCHAR, textlen + 1); + GetWindowText(hwnd, textbuf, textlen+1); + + HFONT oldFont = SelectFont(dc, priv->font); + + SetTextColor(dc, GetSysColor(COLOR_BTNTEXT)); + SetBkMode(dc, TRANSPARENT); + + RECT rc; + GetClientRect(hwnd, &rc); + + DrawText(dc, textbuf, -1, &rc, DT_SINGLELINE | DT_EXPANDTABS | DT_HIDEPREFIX | DT_CENTER | DT_VCENTER); + + ALF_Free(textbuf); + + SelectFont(dc, oldFont); } static LRESULT WINAPI @@ -48,6 +70,22 @@ ALF__PanelWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) return TRUE; } + if (msg == WM_SETFONT) { + priv->font = (HFONT)wparam; + if (LOWORD(lparam) != 0) + InvalidateRect(window, NULL, TRUE); + + return 0; + } + + if (msg == WM_GETFONT) { + return (LRESULT)priv->font; + } + + if (msg == WM_SETTEXT) { + InvalidateRect(window, NULL, TRUE); + } + if (msg == WM_PRINTCLIENT) { RECT r = { 0, 0, 0, 0 }; GetClientRect(window, &r); @@ -129,7 +167,7 @@ ALF_AddPanel(HWND parent, WORD id, UINT x, UINT y) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_SENDAPPLYFONTS; + p.flags = ALF_QUERYSIZE | ALF_SENDAPPLYFONTS | ALF_MESSAGEFONT; ALF_AddWidgetEx(parent, &p); |
