From c275fd73fd5046f35709ee1f90f1baaff9a0095f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Hentschel?= Date: Sun, 18 Mar 2012 19:31:15 +0100 Subject: [PATCH] view: Show the filename in the window title. --- programs/view/view.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/programs/view/view.c b/programs/view/view.c index c50a0ffed3a..ebd48aae335 100644 --- a/programs/view/view.c +++ b/programs/view/view.c @@ -25,7 +25,8 @@ static HINSTANCE hInst; static HWND hMainWnd; static WCHAR szAppName[5] = {'V','i','e','w',0}; -static WCHAR szTitle[80]; +static WCHAR szTitle[MAX_PATH]; +static WCHAR szFileTitle[MAX_PATH]; static HMETAFILE hmf; static HENHMETAFILE enhmf; @@ -204,6 +205,27 @@ static void DoOpenFile(LPCWSTR filename) InvalidateRect( hMainWnd, NULL, TRUE ); } +static void UpdateWindowCaption(void) +{ + WCHAR szCaption[MAX_PATH]; + WCHAR szView[MAX_PATH]; + static const WCHAR hyphenW[] = { ' ','-',' ',0 }; + + LoadStringW(hInst, IDS_DESCRIPTION, szView, sizeof(szView)/sizeof(WCHAR)); + + if (szFileTitle[0] != '\0') + { + lstrcpyW(szCaption, szFileTitle); + LoadStringW(hInst, IDS_DESCRIPTION, szView, sizeof(szView)/sizeof(WCHAR)); + lstrcatW(szCaption, hyphenW); + lstrcatW(szCaption, szView); + } + else + lstrcpyW(szCaption, szView); + + SetWindowTextW(hMainWnd, szCaption); +} + static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { switch (uMessage) @@ -236,7 +258,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM { WCHAR filename[MAX_PATH]; if (FileOpen(hwnd, filename, sizeof(filename)/sizeof(WCHAR))) + { + szFileTitle[0] = 0; + GetFileTitleW(filename, szFileTitle, sizeof(szFileTitle)); DoOpenFile(filename); + UpdateWindowCaption(); + } } break;