Skip to content

Commit 5311b5c

Browse files
committed
Read copyright from version
1 parent bc50a5e commit 5311b5c

4 files changed

Lines changed: 82 additions & 32 deletions

File tree

src/About.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@ void FormatDlgItemText(HWND dlg, int id, LPCTSTR value) {
2828
}
2929
}
3030

31+
// Set the copyright label (IDC_ABOUT_COPYRIGHT) from the executable's version-information
32+
// "LegalCopyright" string (res\WinNumTip.rc2), so the About dialog and the file's Details
33+
// property page always show the one identical copyright (build year included) rather than a
34+
// second copy formatted into the .rc template. Read the version block straight from the
35+
// running module, resolve the language/code-page from its Translation table to form the
36+
// value's sub-block path, and apply LegalCopyright; on any failure the .rc's design-time text
37+
// is left in place.
38+
void SetCopyrightFromVersionInfo(HWND dlg, HINSTANCE inst) {
39+
TCHAR path[MAX_PATH];
40+
if (!GetModuleFileName(inst, path, ARRAYSIZE(path))) return;
41+
42+
DWORD ignored;
43+
const DWORD size = GetFileVersionInfoSize(path, &ignored);
44+
if (!size) return;
45+
46+
const HANDLE heap = GetProcessHeap();
47+
void* const block = HeapAlloc(heap, 0, size);
48+
if (!block) return;
49+
50+
if (GetFileVersionInfo(path, 0, size, block)) {
51+
// Resolve the first language/code-page pair so the sub-block path matches the
52+
// StringFileInfo block that holds the strings (here "000004B0"); %04X reproduces the
53+
// upper-case block name authored in the version resource exactly.
54+
struct LangAndCodePage { WORD language; WORD codePage; } *trans = nullptr;
55+
UINT transLen = 0;
56+
if (VerQueryValue(block, TEXT("\\VarFileInfo\\Translation"),
57+
reinterpret_cast<void**>(&trans), &transLen) &&
58+
transLen >= sizeof(LangAndCodePage)) {
59+
TCHAR sub[64];
60+
wsprintf(sub, TEXT("\\StringFileInfo\\%04X%04X\\LegalCopyright"),
61+
trans->language, trans->codePage);
62+
63+
LPTSTR copyright = nullptr;
64+
UINT copyrightLen = 0;
65+
if (VerQueryValue(block, sub, reinterpret_cast<void**>(&copyright), &copyrightLen) && copyrightLen)
66+
VERIFY(SetDlgItemText(dlg, IDC_ABOUT_COPYRIGHT, copyright));
67+
}
68+
}
69+
70+
VERIFY(HeapFree(heap, 0, block));
71+
}
72+
3173
BOOL OnInitDialog(HWND dlg, HWND /*focus*/, LPARAM lParam) {
3274
g_dlg = dlg;
3375
const HINSTANCE inst = reinterpret_cast<HINSTANCE>(lParam);
@@ -49,10 +91,10 @@ BOOL OnInitDialog(HWND dlg, HWND /*focus*/, LPARAM lParam) {
4991

5092
SendMessage(dlg, WM_NEXTDLGCTL, reinterpret_cast<WPARAM>(GetDlgItem(dlg, IDC_ABOUT_LINK)), TRUE);
5193

52-
// Fill the app-name and copyright "%s" placeholders (see IDD_ABOUT) with the build's
53-
// version and year.
54-
FormatDlgItemText(dlg, IDC_ABOUT_NAME, TEXT(APP_STRINGIZE(APP_VER_STR)));
55-
FormatDlgItemText(dlg, IDC_ABOUT_COPYRIGHT, TEXT(APP_STRINGIZE(APP_YEAR)));
94+
// Fill the app-name "%s" placeholder (see IDD_ABOUT) with the build's version, and set the
95+
// copyright label from the executable's LegalCopyright version string.
96+
FormatDlgItemText(dlg, IDC_ABOUT_NAME, TEXT(APP_STRINGIZE(APP_VER_STR)));
97+
SetCopyrightFromVersionInfo(dlg, inst);
5698

5799
return FALSE;
58100
}

src/FontPicker.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ constexpr UINT kRefreshSampleMsg = WM_APP + 0x100;
4444
constexpr LPCTSTR kFontTemplate = TEXT("FONTSELECTORDLG");
4545
constexpr LPCTSTR kFontSample = TEXT("0123456789");
4646

47+
// SetWindowSubclass IDs for our two subclasses -- one on the ChooseFont Sample control (stc5),
48+
// one on the dialog itself; each proc removes its own subclass by the id Windows passes back
49+
// (see the WM_NCDESTROY cases).
50+
constexpr UINT_PTR kSampleSubclassId = 1;
51+
constexpr UINT_PTR kDlgSubclassId = 2;
52+
4753
// comdlg32 rewrites the ChooseFont Sample control (stc5) with its own preview string
4854
// ("AaBbYyZz") on every selection change. Subclass it and intercept WM_SETTEXT so the
4955
// sample always shows our badge digits instead.
@@ -79,6 +85,7 @@ void RefreshChooseFontSample(HWND hDlg) {
7985
const int boxW = rc.right - rc.left;
8086
const int boxH = rc.bottom - rc.top;
8187
constexpr int kRefHeight = 100;
88+
constexpr int kFillPercent = 90; // the digits fill this % of the Sample box (a small margin)
8289
lf.lfWidth = 0;
8390
lf.lfHeight = -kRefHeight;
8491
if (const HFONT measure = CreateFontIndirect(&lf)) {
@@ -91,8 +98,8 @@ void RefreshChooseFontSample(HWND hDlg) {
9198
DeleteObject(measure);
9299

93100
int h = kRefHeight;
94-
if (ext.cx > 0 && boxW > 0) { const int hw = MulDiv(kRefHeight, boxW * 9 / 10, ext.cx); if (hw < h) h = hw; }
95-
if (ext.cy > 0 && boxH > 0) { const int hh = MulDiv(kRefHeight, boxH * 9 / 10, ext.cy); if (hh < h) h = hh; }
101+
if (ext.cx > 0 && boxW > 0) { const int hw = MulDiv(kRefHeight, boxW * kFillPercent / 100, ext.cx); if (hw < h) h = hw; }
102+
if (ext.cy > 0 && boxH > 0) { const int hh = MulDiv(kRefHeight, boxH * kFillPercent / 100, ext.cy); if (hh < h) h = hh; }
96103
lf.lfHeight = -(h > 0 ? h : 1);
97104
}
98105

@@ -195,10 +202,10 @@ LRESULT CALLBACK ChooseFontDlgSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARA
195202
BOOL OnChooseFontInitDialog(HWND hwnd, HWND /*focus*/, LPARAM /*cf*/) {
196203
g_chooseFontDlg = hwnd;
197204
if (const HWND sample = GetDlgItem(hwnd, stc5)) {
198-
VERIFY(SetWindowSubclass(sample, FontSampleSubclassProc, 1, 0));
205+
VERIFY(SetWindowSubclass(sample, FontSampleSubclassProc, kSampleSubclassId, 0));
199206
VERIFY(SetWindowText(sample, kFontSample));
200207
}
201-
VERIFY(SetWindowSubclass(hwnd, ChooseFontDlgSubclass, 2, 0));
208+
VERIFY(SetWindowSubclass(hwnd, ChooseFontDlgSubclass, kDlgSubclassId, 0));
202209
VERIFY(PostMessage(hwnd, kRefreshSampleMsg, 0, 0));
203210

204211
// Focus the font-name combo (cmb1) instead of the dialog's first tab stop -- which, because
@@ -245,8 +252,7 @@ void UpdateFontPreview(HWND dlg) {
245252
MoveMemory(&lf, &g_workingFont, sizeof(lf));
246253

247254
// Render at the label's own line height rather than the chosen size.
248-
HFONT dlgFont = reinterpret_cast<HFONT>(SendMessage(dlg, WM_GETFONT, 0, 0));
249-
if (dlgFont) {
255+
if (const HFONT dlgFont = reinterpret_cast<HFONT>(SendMessage(dlg, WM_GETFONT, 0, 0))) {
250256
LOGFONT base;
251257
ZeroMemory(&base, sizeof(base));
252258
if (GetObject(dlgFont, sizeof(base), &base)) {
@@ -255,8 +261,7 @@ void UpdateFontPreview(HWND dlg) {
255261
}
256262
}
257263

258-
const HFONT nf = CreateFontIndirect(&lf);
259-
if (nf) {
264+
if (const HFONT nf = CreateFontIndirect(&lf)) {
260265
SendMessage(name, WM_SETFONT, reinterpret_cast<WPARAM>(nf), TRUE);
261266
if (g_previewFont) DeleteObject(g_previewFont);
262267
g_previewFont = nf;

src/WinNumTip.rc

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define APSTUDIO_HIDDEN_SYMBOLS
1111
#include "winres.h"
1212
#undef APSTUDIO_HIDDEN_SYMBOLS
13+
#include <dlgs.h>
1314

1415
/////////////////////////////////////////////////////////////////////////////
1516
#undef APSTUDIO_READONLY_SYMBOLS
@@ -94,7 +95,7 @@ BEGIN
9495
"SysLink",WS_TABSTOP,36,20,189,18
9596
CONTROL "<a href=""https://github.com/i2van/WinNumTip/blob/main/README.md"">README</a> <a href=""https://github.com/i2van/WinNumTip/"">Project site</a>",IDC_ABOUT_LINK,
9697
"SysLink",WS_TABSTOP,36,43,189,10
97-
LTEXT "Copyright � %s Ivan Ivon",IDC_ABOUT_COPYRIGHT,36,63,189,10
98+
LTEXT "",IDC_ABOUT_COPYRIGHT,36,63,189,10
9899
CONTROL "<a>Preferences</a>",IDC_ABOUT_PREFS,"SysLink",WS_TABSTOP,36,79,60,10
99100
DEFPUSHBUTTON "OK",IDOK,175,76,50,14
100101
END
@@ -115,35 +116,35 @@ BEGIN
115116
LTEXT "&Win key poll:",IDC_POLL_LABEL,7,108,110,10
116117
RTEXT "%d ms",IDC_POLL_VALUE,155,108,70,10
117118
CONTROL "",IDC_POLL_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | WS_TABSTOP,7,121,218,24
118-
CONTROL "&Invert colors",IDC_INVERT,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,151,150,10
119+
CONTROL "In&vert colors",IDC_INVERT,"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,151,150,10
119120
LTEXT "Font:",IDC_FONT_LABEL,7,168,17,10
120121
LTEXT "Default",IDC_FONT_NAME,28,166,142,14,SS_NOPREFIX | SS_CENTERIMAGE | SS_ENDELLIPSIS | WS_BORDER
121-
PUSHBUTTON "&Choose...",IDC_FONT_BUTTON,175,166,50,14
122+
PUSHBUTTON "S&elect...",IDC_FONT_BUTTON,175,166,50,14
122123
CONTROL "<a>Reset to defaults</a>",IDC_RESET,"SysLink",WS_GROUP | WS_TABSTOP,7,191,100,10
123124
DEFPUSHBUTTON "OK",IDOK,121,188,50,14,WS_GROUP
124125
PUSHBUTTON "Cancel",IDCANCEL,175,188,50,14
125126
END
126127

127-
FONTSELECTORDLG DIALOGEX 13, 54, 300, 300
128+
FONTSELECTORDLG DIALOGEX 13, 54, 301, 306
128129
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
129130
CAPTION "Select Font"
130131
FONT 8, "MS Shell Dlg", 0, 0, 0x0
131132
BEGIN
132-
LTEXT "&Font:",1088,7,6,71,9
133-
CONTROL "<A>Reset to default</A>",IDC_FONT_RESET_LINK,"SysLink",LWS_RIGHT | WS_TABSTOP,84,6,83,10
134-
COMBOBOX 1136,7,17,160,264,CBS_SIMPLE | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | CBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
135-
LTEXT "Font st&yle:",1089,175,6,118,9
136-
COMBOBOX 1137,175,17,118,169,CBS_SIMPLE | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_HASSTRINGS | CBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
137-
GROUPBOX "Effects",1072,175,189,118,44,WS_GROUP
138-
CONTROL "Stri&keout",1040,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,203,100,10
139-
CONTROL "&Underline",1041,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,216,100,10
140-
GROUPBOX "Sample",1073,175,238,118,40,WS_GROUP
141-
CTEXT "0123456789",1092,178,245,112,29,SS_NOPREFIX | SS_CENTERIMAGE
142-
DEFPUSHBUTTON "OK",IDOK,179,281,55,14,WS_GROUP
143-
PUSHBUTTON "Cancel",IDCANCEL,238,281,55,14
144-
PUSHBUTTON "&Apply",1026,66,281,55,14
145-
PUSHBUTTON "&Help",1038,121,281,55,14
146-
CONTROL "<A>Show more fonts</A>",1592,"SysLink",WS_TABSTOP,7,284,59,10
133+
LTEXT "&Font:",1088,7,8,71,9
134+
COMBOBOX 1136,7,19,160,264,CBS_SIMPLE | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | CBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
135+
CONTROL "<A>Reset to default</A>",IDC_FONT_RESET_LINK,"SysLink",LWS_RIGHT | WS_TABSTOP,84,8,83,10
136+
LTEXT "Font st&yle:",1089,175,8,118,9
137+
COMBOBOX 1137,175,19,118,169,CBS_SIMPLE | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_HASSTRINGS | CBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
138+
GROUPBOX "Effects",1072,175,191,118,44,WS_GROUP
139+
CONTROL "Stri&keout",1040,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,205,100,10
140+
CONTROL "&Underline",1041,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,218,100,10
141+
GROUPBOX "Sample",1073,175,240,118,40,WS_GROUP
142+
CTEXT "0123456789",1092,178,248,112,28,SS_NOPREFIX | SS_CENTERIMAGE
143+
DEFPUSHBUTTON "OK",IDOK,172,284,59,16,WS_GROUP
144+
PUSHBUTTON "Cancel",IDCANCEL,235,284,59,16
145+
PUSHBUTTON "&Apply",1026,66,283,55,14
146+
PUSHBUTTON "&Help",1038,121,283,55,14
147+
CONTROL "<A>Show more fonts</A>",1592,"SysLink",WS_TABSTOP,7,286,59,10
147148
LTEXT "&Size:",1090,7,306,30,9,NOT WS_VISIBLE
148149
COMBOBOX 1138,40,306,36,60,CBS_SIMPLE | CBS_OWNERDRAWFIXED | CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | CBS_DISABLENOSCROLL | NOT WS_VISIBLE | WS_VSCROLL
149150
LTEXT "&Color:",1091,80,306,30,9,NOT WS_VISIBLE
@@ -172,6 +173,8 @@ BEGIN
172173

173174
"FONTSELECTORDLG", DIALOG
174175
BEGIN
176+
RIGHTMARGIN, 300
177+
BOTTOMMARGIN, 300
175178
END
176179
END
177180
#endif // APSTUDIO_INVOKED

src/WinNumTip.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
8989
<EntryPointSymbol>Entry</EntryPointSymbol>
9090
<GenerateDebugInformation>true</GenerateDebugInformation>
91-
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;ole32.lib;oleaut32.lib;shell32.lib;uxtheme.lib;comctl32.lib;comdlg32.lib</AdditionalDependencies>
91+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;ole32.lib;oleaut32.lib;shell32.lib;uxtheme.lib;comctl32.lib;comdlg32.lib;version.lib</AdditionalDependencies>
9292
</Link>
9393
<Manifest>
9494
<!-- Embeds WinNumTip.manifest (Common-Controls v6 for visual styles +

0 commit comments

Comments
 (0)