Something went wrong. Try again.
A simple, small calculator placed discreetly near the Windows Taskbar or anywhere on the screen taskbar-calculator.marcomaroni.it
Something went wrong. Try again.
taskbar-calculator AboutDialog.cpp
2.2 kB · 75 lines
C++
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576#include "stdafx.h"#include <commctrl.h>#include <vector>
#pragma comment(lib, "version.lib")
// Reads the executable's FILEVERSION from its VERSIONINFO resource,// formatted as "major.minor.build" (empty on failure).static ATL::CString GetAppVersionString(){ ATL::CString result; WCHAR path[MAX_PATH]; if (GetModuleFileNameW(NULL, path, MAX_PATH) == 0) return result;
DWORD handle = 0; DWORD size = GetFileVersionInfoSizeW(path, &handle); if (size == 0) return result;
std::vector<BYTE> buffer(size); if (!GetFileVersionInfoW(path, handle, size, buffer.data())) return result;
VS_FIXEDFILEINFO* ffi = nullptr; UINT len = 0; if (VerQueryValueW(buffer.data(), L"\\", (LPVOID*)&ffi, &len) && ffi != nullptr) { result.Format(_T("%u.%u.%u"), HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS), HIWORD(ffi->dwFileVersionLS)); } return result;}
INT_PTR CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch (uMsg) { case WM_INITDIALOG: { RECT rc; GetWindowRect(hwndDlg, &rc); int w = rc.right - rc.left, h = rc.bottom - rc.top; int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; int y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; SetWindowPos(hwndDlg, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
ATL::CString version = GetAppVersionString(); if (!version.IsEmpty()) { ATL::CString text; text.Format(_T("Taskbar Calculator - %s"), (LPCTSTR)version); SetDlgItemText(hwndDlg, IDC_VERSION, text); } return TRUE; } case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case NM_CLICK: case NM_RETURN: { PNMLINK p = (PNMLINK)lParam; if (p->item.iLink == 0) ShellExecuteW(NULL, L"open", p->item.szUrl, NULL, NULL, SW_SHOW); break; } } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: EndDialog(hwndDlg, TRUE); return TRUE; } break; } return FALSE;}