Skip to content

Commit

Permalink
Add app version lookup to windows client about message box
Browse files Browse the repository at this point in the history
  • Loading branch information
bplaat committed May 14, 2022
1 parent 3c7bea1 commit 8becce4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
1 change: 0 additions & 1 deletion windows-client/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
build/
app.min.manifest
7 changes: 4 additions & 3 deletions windows-client/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# with MinGW (MSYS2 & pacman -S mingw-w64-x86_64-toolchain)
# and a minify-xml tool (npm install -g minify-xml)
# to build release use ./build.sh release

rm -rf build
mkdir build
if minify-xml res/app.manifest > res/app.min.manifest && windres res/resource.rc -o build/resource.o; then
if minify-xml res/app.manifest > build/app.min.manifest && windres res/resource.rc -o build/resource.o; then
if gcc -c $([ "$1" == "release" ] && echo "-Os") -IWebView2/include src/strepen.c -o build/strepen.o; then
if ld -s $([ "$1" == "release" ] && echo "--subsystem windows") build/strepen.o build/resource.o -e _start \
-L"C:\\Windows\\System32" -lkernel32 -luser32 -lgdi32 -lshell32 -o build/strepen.exe
-L"C:\\Windows\\System32" -lkernel32 -luser32 -lgdi32 -lshell32 -lversion -o build/strepen.exe
then
rm build/resource.o build/strepen.o
rm build/app.min.manifest build/resource.o build/strepen.o
cp WebView2/x64/WebView2Loader.dll build
if [ "$1" != "release" ]; then
./build/strepen
Expand Down
2 changes: 1 addition & 1 deletion windows-client/res/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
#define ID_STRING_WEBVIEW_URL 2
#define ID_STRING_ABOUT_MENU 3
#define ID_STRING_ABOUT_TITLE 4
#define ID_STRING_ABOUT_TEXT 5
#define ID_STRING_ABOUT_TEXT_FORMAT 5

#endif
10 changes: 7 additions & 3 deletions windows-client/res/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "resource.h"

// Manifest
ID_MANIFEST MANIFEST "app.min.manifest"
ID_MANIFEST MANIFEST "../build/app.min.manifest"

// Icon
ID_ICON_APP ICON "icon.ico"
Expand All @@ -15,7 +15,9 @@ STRINGTABLE LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
ID_STRING_WEBVIEW_URL "https://stam.diekantankys.nl/\x00"
ID_STRING_ABOUT_MENU "About\x00"
ID_STRING_ABOUT_TITLE "About Strepen Windows App\x00"
ID_STRING_ABOUT_TEXT "Made by Bastiaan van der Plaat\nCopyright \xA9 2021 - 2022 PlaatSoft\x00"
ID_STRING_ABOUT_TEXT_FORMAT "Strepen Windows App v%d.%d.%d.%d\n"
"Made by Bastiaan van der Plaat\n"
"Copyright \xA9 2021 - 2022 PlaatSoft\x00"
}

// Dutch Strings
Expand All @@ -25,7 +27,9 @@ STRINGTABLE LANGUAGE LANG_DUTCH, SUBLANG_DUTCH
ID_STRING_WEBVIEW_URL "https://stam.diekantankys.nl/\x00"
ID_STRING_ABOUT_MENU "Over\x00"
ID_STRING_ABOUT_TITLE "Over Strepen Windows App\x00"
ID_STRING_ABOUT_TEXT "Gemaakt door Bastiaan van der Plaat\nCopyright \xA9 2021 - 2022 PlaatSoft\x00"
ID_STRING_ABOUT_TEXT_FORMAT "Strepen Windows App v%d.%d.%d.%d\n"
"Gemaakt door Bastiaan van der Plaat\n"
"Copyright \xA9 2021 - 2022 PlaatSoft\x00"
}

// Version Information
Expand Down
48 changes: 38 additions & 10 deletions windows-client/src/strepen.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "WebView2.h"
#include "../res/resource.h"

#define ID_MENU_ABOUT 1001
#define ID_MENU_ABOUT 1

#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720
Expand All @@ -15,7 +15,7 @@

HWND hwnd;
HINSTANCE instance;
int window_dpi;
UINT window_dpi;
ICoreWebView2 *webview2 = NULL;
ICoreWebView2Controller *controller = NULL;

Expand All @@ -24,6 +24,10 @@ void *malloc(size_t size) {
return HeapAlloc(GetProcessHeap(), 0, size);
}

void free(void *ptr) {
HeapFree(GetProcessHeap(), 0, ptr);
}

wchar_t *wcscpy(wchar_t *dest, const wchar_t *src) {
wchar_t *start = dest;
while ((*dest++ = *src++) != '\0');
Expand All @@ -44,9 +48,9 @@ typedef HRESULT (STDMETHODCALLTYPE *_DwmSetWindowAttribute)(HWND hwnd, DWORD dwA

typedef HRESULT (STDMETHODCALLTYPE *_CreateCoreWebView2EnvironmentWithOptions)(PCWSTR browserExecutableFolder, PCWSTR userDataFolder, ICoreWebView2EnvironmentOptions *environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler *environmentCreatedHandler);

int GetPrimaryDesktopDpi(void) {
UINT GetPrimaryDesktopDpi(void) {
HDC hdc = GetDC(HWND_DESKTOP);
int dpi = GetDeviceCaps(hdc, LOGPIXELSY);
UINT dpi = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(HWND_DESKTOP, hdc);
return dpi;
}
Expand Down Expand Up @@ -96,14 +100,34 @@ void FatalError(wchar_t *message) {
ExitProcess(1);
}

void GetAppVersion(UINT *version) {
wchar_t file_name[MAX_PATH];
GetModuleFileName(NULL, file_name, sizeof(file_name) / sizeof(wchar_t));
DWORD version_info_size = GetFileVersionInfoSize(file_name, NULL);
BYTE *version_info = malloc(version_info_size);
GetFileVersionInfo(file_name, 0, version_info_size, version_info);

VS_FIXEDFILEINFO *file_info;
UINT file_info_size;
VerQueryValue(version_info, L"\\", (LPVOID *)&file_info, &file_info_size);

version[0] = HIWORD(file_info->dwProductVersionMS);
version[1] = LOWORD(file_info->dwProductVersionMS);
version[2] = HIWORD(file_info->dwProductVersionLS);
version[3] = LOWORD(file_info->dwProductVersionLS);

free(version_info);
}

// Browser functionality
void ResizeBrowser(HWND hwnd) {
if (!controller) return;
RECT window_rect;
GetClientRect(hwnd, &window_rect);
ICoreWebView2Controller_put_Bounds(controller, window_rect);
}

BOOL HandleKeyDown(int key) {
BOOL HandleKeyDown(UINT key) {
if (key == VK_ESCAPE) {
if (!(GetWindowLong(hwnd, GWL_STYLE) & WS_OVERLAPPEDWINDOW)) {
SetWindowFullscreen(hwnd, FALSE);
Expand Down Expand Up @@ -157,7 +181,7 @@ ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerVtbl EnvironmentComple
HRESULT STDMETHODCALLTYPE AcceleratorKeyPressedHandler_Invoke(ICoreWebView2AcceleratorKeyPressedEventHandler *This, ICoreWebView2Controller *sender, ICoreWebView2AcceleratorKeyPressedEventArgs *args) {
COREWEBVIEW2_KEY_EVENT_KIND state;
ICoreWebView2AcceleratorKeyPressedEventArgs_get_KeyEventKind(args, &state);
int key;
UINT key;
ICoreWebView2AcceleratorKeyPressedEventArgs_get_VirtualKey(args, &key);
if (state == COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN && HandleKeyDown(key)) {
ICoreWebView2AcceleratorKeyPressedEventArgs_put_Handled(args, TRUE);
Expand Down Expand Up @@ -237,9 +261,13 @@ LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

// Menu commands
if (msg == WM_SYSCOMMAND) {
int id = LOWORD(wParam);
UINT id = LOWORD(wParam);
if (id == ID_MENU_ABOUT) {
MessageBox(hwnd, GetString(ID_STRING_ABOUT_TEXT), GetString(ID_STRING_ABOUT_TITLE), MB_OK | MB_ICONINFORMATION);
UINT app_version[4];
GetAppVersion(app_version);
wchar_t about_text[512];
wsprintf(about_text, GetString(ID_STRING_ABOUT_TEXT_FORMAT), app_version[0], app_version[1], app_version[2], app_version[3]);
MessageBox(hwnd, about_text, GetString(ID_STRING_ABOUT_TITLE), MB_OK | MB_ICONINFORMATION);
return 0;
}
}
Expand Down Expand Up @@ -302,8 +330,8 @@ void _start(void) {

// Create centered window
window_dpi = GetPrimaryDesktopDpi();
int window_width = MulDiv(WINDOW_WIDTH, window_dpi, 96);
int window_height = MulDiv(WINDOW_HEIGHT, window_dpi, 96);
UINT window_width = MulDiv(WINDOW_WIDTH, window_dpi, 96);
UINT window_height = MulDiv(WINDOW_HEIGHT, window_dpi, 96);
RECT window_rect;
window_rect.left = (GetSystemMetrics(SM_CXSCREEN) - window_width) / 2;
window_rect.top = (GetSystemMetrics(SM_CYSCREEN) - window_height) / 2;
Expand Down

0 comments on commit 8becce4

Please # to comment.