view: Show the filename in the window title

André Hentschel nerv at dawncrow.de
Sun Mar 18 13:31:15 CDT 2012


---
 programs/view/view.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/programs/view/view.c b/programs/view/view.c
index c50a0ff..b218d42 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 );
 }
 
+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;
 
-- 

Best Regards, André Hentschel


More information about the wine-patches mailing list