From 52907f0989f298d823cc9ab2514c8088d297a416 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20Steinh=C3=B6fer?= Date: Thu, 7 Apr 2022 12:08:44 +0200 Subject: [PATCH] Dynamically show version number in AboutDlg --- WinMute/AboutDlg.cpp | 46 ++++++++++++++++++++++++++++++++++++++++- WinMute/WinMute.rc | 4 ++-- WinMute/WinMute.vcxproj | 4 ++-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/WinMute/AboutDlg.cpp b/WinMute/AboutDlg.cpp index 1c84c29..e5bef64 100644 --- a/WinMute/AboutDlg.cpp +++ b/WinMute/AboutDlg.cpp @@ -173,6 +173,41 @@ static INT_PTR CALLBACK About_LicenseDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM return FALSE; } +static bool GetWinMuteVersion(tstring& versNumber) +{ + bool success = false; + DWORD dummy; + TCHAR szFileName[MAX_PATH]; + GetModuleFileName(NULL, szFileName, sizeof(szFileName)/sizeof(szFileName[0])); + DWORD versSize = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL, szFileName, &dummy); + LPVOID versData = malloc(versSize); + if (versData != nullptr) { + if (GetFileVersionInfoEx( + FILE_VER_GET_NEUTRAL, + szFileName, + NULL, + versSize, + versData)) { + VS_FIXEDFILEINFO *pvi; + UINT pviLen = sizeof(*pvi); + if (VerQueryValue( + versData, + _T("\\"), + reinterpret_cast(&pvi), + &pviLen)) { + versNumber = std::format(_T("{}.{}.{}.{}"), + pvi->dwProductVersionMS >> 16, + pvi->dwFileVersionMS & 0xFFFF, + pvi->dwFileVersionLS >> 16, + pvi->dwFileVersionLS & 0xFFFF); + success = true; + } + } + free(versData); + } + return success; +} + INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { AboutDlgData* dlgData = @@ -207,6 +242,14 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) SwitchTab(dlgData, dlgData->hTabs[ABOUT_TAB_GENERAL]); + HWND hTitle = GetDlgItem(hDlg, IDC_ABOUT_TITLE); + tstring progName = _T("WinMute"); + tstring progVers = _T("WinMute"); + if (GetWinMuteVersion(progVers)) { + progName = std::format(_T("WinMute {}"), progVers); + Static_SetText(hTitle, progName.c_str()); + } + // Set title font LOGFONT font; font.lfHeight = 32; @@ -227,10 +270,11 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) dlgData->hTitleFont = CreateFontIndirect(&font); SendMessage( - GetDlgItem(hDlg, IDC_ABOUT_TITLE), + hTitle, WM_SETFONT, reinterpret_cast(dlgData->hTitleFont), TRUE); + return TRUE; } case WM_NOTIFY: { diff --git a/WinMute/WinMute.rc b/WinMute/WinMute.rc index eab465f..0f540aa 100644 --- a/WinMute/WinMute.rc +++ b/WinMute/WinMute.rc @@ -57,8 +57,8 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN CONTROL "",IDC_ABOUT_TAB,"SysTabControl32",0x0,7,34,299,202 PUSHBUTTON "OK",IDOK,242,246,64,16 - LTEXT "WinMute 2.0",IDC_ABOUT_TITLE,41,7,193,23 - ICON IDI_APP,IDC_STATIC,13,7,21,20,SS_CENTERIMAGE + LTEXT "WinMute ",IDC_ABOUT_TITLE,41,7,193,23 + ICON IDI_APP,IDC_STATIC,13,7,20,20,SS_CENTERIMAGE END IDD_SETTINGS DIALOGEX 0, 0, 269, 253 diff --git a/WinMute/WinMute.vcxproj b/WinMute/WinMute.vcxproj index 81f4ad2..5f8d097 100644 --- a/WinMute/WinMute.vcxproj +++ b/WinMute/WinMute.vcxproj @@ -110,7 +110,7 @@ Windows true - strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;UxTheme.lib;comsuppwd.lib;%(AdditionalDependencies) + strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;UxTheme.lib;comsuppwd.lib;Version.lib;%(AdditionalDependencies) PerMonitorHighDPIAware @@ -157,7 +157,7 @@ Windows true - strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;UxTheme.lib;comsuppwd.lib;%(AdditionalDependencies) + strsafe.lib;comctl32.lib;WtsApi32.lib;Winmm.lib;UxTheme.lib;comsuppwd.lib;Version.lib;%(AdditionalDependencies) PerMonitorHighDPIAware -- 2.43.0