-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWindowWithVersionInfo.cpp
62 lines (51 loc) · 3.22 KB
/
WindowWithVersionInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include <cstdint>
#include <string>
#include <Windows.h>
#include <CommCtrl.h>
using namespace std;
HWND window = nullptr;
HWND labelCompany = nullptr;
HWND labelProduct = nullptr;
HWND labelVersion = nullptr;
HWND labelCompanyName = nullptr;
HWND labelProductName = nullptr;
HWND labelProductVersion = nullptr;
WNDPROC defWndProc = nullptr;
LRESULT OnWindowClose(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
PostQuitMessage(0);
return CallWindowProc(defWndProc, hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_CLOSE && hwnd == window) return OnWindowClose(hwnd, message, wParam, lParam);
return CallWindowProc(defWndProc, hwnd, message, wParam, lParam);
}
int main() {
wstring currentModuleName(MAX_PATH, 0);
GetModuleFileName(nullptr, (LPWSTR)currentModuleName.c_str(), static_cast<int32_t>(currentModuleName.length()));
int32_t versionHandle = 0;
int32_t versionSize = GetFileVersionInfoSize(currentModuleName.c_str(), (LPDWORD)&versionHandle);
wstring versionData(versionSize, 0);
GetFileVersionInfo(currentModuleName.c_str(), versionHandle, versionSize, (LPVOID)versionData.c_str());
wchar_t* value;
int32_t valueLength = 0;
VerQueryValue((LPVOID)versionData.c_str(), L"\\StringFileInfo\\000004b0\\CompanyName", (LPVOID*)&value, (PUINT)&valueLength);
wstring valueCompanyName(value);
VerQueryValue((LPVOID)versionData.c_str(), L"\\StringFileInfo\\000004b0\\ProductName", (LPVOID*)&value, (PUINT)&valueLength);
wstring valueProductName(value);
VerQueryValue((LPVOID)versionData.c_str(), L"\\StringFileInfo\\000004b0\\ProductVersion", (LPVOID*)&value, (PUINT)&valueLength);
wstring valueProductVersion(value);
window = CreateWindowEx(0, WC_DIALOG, L"Form with version info", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 316, 140, nullptr, nullptr, nullptr, nullptr);
labelCompany = CreateWindowEx(0, WC_STATIC, L"Company name", WS_CHILD | WS_VISIBLE, 10, 12, 105, 23, window, nullptr, nullptr, nullptr);
labelProduct = CreateWindowEx(0, WC_STATIC, L"Product name", WS_CHILD | WS_VISIBLE, 10, 42, 105, 23, window, nullptr, nullptr, nullptr);
labelVersion = CreateWindowEx(0, WC_STATIC, L"Product version", WS_CHILD | WS_VISIBLE, 10, 72, 105, 23, window, nullptr, nullptr, nullptr);
labelCompanyName = CreateWindowEx(WS_EX_CLIENTEDGE, WC_STATIC, valueCompanyName.c_str(), WS_CHILD | WS_VISIBLE, 120, 10, 170, 23, window, nullptr, nullptr, nullptr);
labelProductName = CreateWindowEx(WS_EX_CLIENTEDGE, WC_STATIC, valueProductName.c_str(), WS_CHILD | WS_VISIBLE, 120, 40, 170, 23, window, nullptr, nullptr, nullptr);
labelProductVersion = CreateWindowEx(WS_EX_CLIENTEDGE, WC_STATIC, valueProductVersion.c_str(), WS_CHILD | WS_VISIBLE, 120, 70, 170, 23, window, nullptr, nullptr, nullptr);
defWndProc = (WNDPROC)SetWindowLongPtr(window, GWLP_WNDPROC, (LONG_PTR)WndProc);
ShowWindow(window, SW_SHOW);
MSG message = { 0 };
while (GetMessage(&message, nullptr, 0, 0))
DispatchMessage(&message);
return (int)message.wParam;
}