From 0f8304ef233435ba8bfc35b1f3f20bfcf433512b Mon Sep 17 00:00:00 2001 From: W0LF Date: Sun, 26 Mar 2023 21:28:59 +0300 Subject: [PATCH 01/15] Update versioning scripts. --- .gitignore | 1 + VersionInfo.h | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 VersionInfo.h diff --git a/.gitignore b/.gitignore index bb50ac6..0e1aa2f 100644 --- a/.gitignore +++ b/.gitignore @@ -437,3 +437,4 @@ lightgbm.Rcheck/ # GraphViz artifacts *.gv *.gv.* +/VersionInfo.h diff --git a/VersionInfo.h b/VersionInfo.h deleted file mode 100644 index 1b74b01..0000000 --- a/VersionInfo.h +++ /dev/null @@ -1,12 +0,0 @@ -// wCenterWindow -// version.h -// -#pragma once - -#define V_MAJOR 2 -#define V_MINOR 3 -#define V_PATCH 4 -#define PRODUCT_NAME "wCenterWindow" -#define PRODUCT_AUTHORS "W0LF aka 'dreamforce'" -#define PRODUCT_YEAR_START 2020 -#define PRODUCT_DESCRIPTION "Centers windows by hotkey" From 6b3a90d68248b748c9d09a77e80646cb5dd8ae2a Mon Sep 17 00:00:00 2001 From: W0LF Date: Sun, 26 Mar 2023 21:29:55 +0300 Subject: [PATCH 02/15] Update versioning scripts. --- Update_version.bat | 71 ++++++++++++++++------------ wCenterWindow.sln | 10 +++- wCenterWindow/VersionInfo.h | 28 +++++++++++ wCenterWindow/VersionInfo.rc | Bin 0 -> 1954 bytes wCenterWindow/framework.h | 2 +- wCenterWindow/resource.h | 6 +++ wCenterWindow/wCenterWindow.rc | Bin 14644 -> 12890 bytes wCenterWindow/wCenterWindow.vcxproj | 23 ++++++--- 8 files changed, 100 insertions(+), 40 deletions(-) create mode 100644 wCenterWindow/VersionInfo.h create mode 100644 wCenterWindow/VersionInfo.rc diff --git a/Update_version.bat b/Update_version.bat index 7f79ddb..3df6465 100644 --- a/Update_version.bat +++ b/Update_version.bat @@ -1,4 +1,5 @@ @ECHO OFF +CHCP 1251 >nul SETLOCAL ENABLEDELAYEDEXPANSION SET CURRENT_TIME=%TIME% @@ -8,8 +9,8 @@ SET BUILDTIME=%CURRENT_TIME:~0,8% SET BUILDDATE=%CURRENT_DATE% SET BUILD_DATETIME=Build time: %BUILDDATE% %BUILDTIME% SET CURRENT_YEAR=%CURRENT_DATE:~6,4% - SET BUILDSECS=0 + SET GIT_COUNT=0 SET GIT_TIME=0 SET GIT_DATE=0 @@ -28,25 +29,28 @@ SET PYS=0 SET PA=0 CD /D %~dp0 -IF NOT EXIST "VersionInfo.h" ( - ECHO Can't find file 'VersionInfo.h' +IF NOT EXIST "Version.h" ( + ECHO Can't find file 'Version.h' TIMEOUT /T 3 EXIT /B 1 ) -COPY /Y "VersionInfo.h" "version.h" >nul +COPY /Y "Version.h" "VersionInfo.h" >nul -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MAJOR" "version.h"') DO (SET "VerMajor=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MINOR" "version.h"') DO (SET "VerMinor=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_PATCH" "version.h"') DO (SET "VerPatch=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_NAME" "version.h"') DO (SET "PN=%%~A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_YEAR_START" "version.h"') DO (SET "PYS=%%A") -FOR /F "tokens=2*" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_AUTHORS" "version.h"') DO (SET "PA=%%~B") +FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MAJOR" "VersionInfo.h"') DO (SET "VerMajor=%%A") +FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MINOR" "VersionInfo.h"') DO (SET "VerMinor=%%A") +FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_PATCH" "VersionInfo.h"') DO (SET "VerPatch=%%A") +FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_NAME" "VersionInfo.h"') DO (SET "PN=%%~A") +FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_YEAR_START" "VersionInfo.h"') DO (SET "PYS=%%A") +FOR /F "tokens=2*" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_AUTHORS" "VersionInfo.h"') DO (SET "PA=%%~B") FOR /F "tokens=1-4 delims=:., " %%A IN ("%BUILDTIME%") DO (SET /A "BUILDSECS=%%A * 3600 + %%B * 60 + %%C") -FOR /F "delims=" %%A IN ('git rev-list --count HEAD') DO (SET /A GIT_COUNT=%%A) -FOR /F "tokens=1,2 delims= " %%A IN ('git log -1 --date=format:%%d.%%m.%%Y ^| find /I "Date:"') DO (SET "GIT_DATE=%%B") -FOR /F "tokens=2-4 delims=, " %%A IN ('git log -1 --date=format:"%%a,%%d-%%h-%%Y,%%T" ^| find /I "Date:"') DO ( - SET "GIT_DATETIME=Git time: %%A, %%B %%C" - SET "GIT_TIME=%%C" + +IF EXIST ".git" ( + FOR /F "delims=" %%A IN ('git rev-list --count HEAD') DO (SET /A GIT_COUNT=%%A) + FOR /F "tokens=1,2 delims= " %%A IN ('git log -1 --date=format:%%d.%%m.%%Y ^| find /I "Date:"') DO (SET "GIT_DATE=%%B") + FOR /F "tokens=2-4 delims=, " %%A IN ('git log -1 --date=format:"%%a,%%d-%%h-%%Y,%%T" ^| find /I "Date:"') DO ( + SET "GIT_DATETIME=Git time: %%A, %%B %%C" + SET "GIT_TIME=%%C" + ) ) SET VSF=%VerMajor%.%VerMinor%.%VerPatch%.%GIT_COUNT% @@ -60,22 +64,27 @@ SET PCF=Copyright (C) %PYS%-%CURRENT_YEAR% by %PA% SET INT_NAME=%PN%C++ SET ORIG_NAME=%PN%.exe -ECHO #define BUILD_DATE "%BUILDDATE%">> version.h -ECHO #define BUILD_TIME "%BUILDTIME%">> version.h -ECHO #define BUILD_DATETIME "%BUILD_DATETIME%">> version.h -ECHO #define GIT_DATE "%GIT_DATE%">> version.h -ECHO #define GIT_TIME "%GIT_TIME%">> version.h -ECHO #define GIT_DATETIME "%GIT_DATETIME%">> version.h -ECHO #define GIT_COUNT %GIT_COUNT% >> version.h -ECHO #define V_SECS %BUILDSECS% >> version.h -ECHO #define INTERNAL_NAME "%INT_NAME%">> version.h -ECHO #define ORIG_FILE_NAME "%ORIG_NAME%">> version.h -ECHO #define PRODUCT_NAME_FULL "%PNF%">> version.h -ECHO #define PRODUCT_COPYRIGHT "%PCF%">> version.h -ECHO #define VERSION_NUM %VN% >> version.h -ECHO #define VERSION_STR "%VS%">> version.h -ECHO #define VERSION_NUM_FULL %VNF% >> version.h -ECHO #define VERSION_STR_FULL "%VSF%">> version.h +ECHO #define BUILD_DATE "%BUILDDATE%">> VersionInfo.h +ECHO #define BUILD_TIME "%BUILDTIME%">> VersionInfo.h +ECHO #define BUILD_DATETIME "%BUILD_DATETIME%">> VersionInfo.h + +IF EXIST ".git" ( + ECHO #define GIT_DATE "%GIT_DATE%">> VersionInfo.h + ECHO #define GIT_TIME "%GIT_TIME%">> VersionInfo.h + ECHO #define GIT_DATETIME "%GIT_DATETIME%">> VersionInfo.h + ECHO #define GIT_COUNT %GIT_COUNT% >> VersionInfo.h +) + +ECHO #define V_SECS %BUILDSECS% >> VersionInfo.h +ECHO #define INTERNAL_NAME "%INT_NAME%">> VersionInfo.h +ECHO #define ORIG_FILE_NAME "%ORIG_NAME%">> VersionInfo.h +ECHO #define PRODUCT_NAME_FULL "%PNF%">> VersionInfo.h +ECHO #define PRODUCT_COPYRIGHT "%PCF%">> VersionInfo.h +ECHO #define VERSION_NUM %VN% >> VersionInfo.h +ECHO #define VERSION_STR "%VS%">> VersionInfo.h +ECHO #define VERSION_NUM_FULL %VNF% >> VersionInfo.h +ECHO #define VERSION_STR_FULL "%VSF%">> VersionInfo.h ENDLOCAL +TIMEOUT /T 1 >nul EXIT diff --git a/wCenterWindow.sln b/wCenterWindow.sln index df62922..fe3ab9e 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -1,10 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31112.23 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWindow\wCenterWindow.vcxproj", "{F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}" + ProjectSection(SolutionItems) = preProject + Update_version.bat = Update_version.bat + Version.h = Version.h + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 diff --git a/wCenterWindow/VersionInfo.h b/wCenterWindow/VersionInfo.h new file mode 100644 index 0000000..e78339e --- /dev/null +++ b/wCenterWindow/VersionInfo.h @@ -0,0 +1,28 @@ +// wCenterWindow +// version.h +// +#pragma once + +#define V_MAJOR 2 +#define V_MINOR 3 +#define V_PATCH 5 +#define PRODUCT_NAME "wCenterWindow" +#define PRODUCT_AUTHORS "W0LF aka 'dreamforce'" +#define PRODUCT_YEAR_START 2020 +#define PRODUCT_DESCRIPTION "Centers windows by hotkey" +#define BUILD_DATE "26.03.2023" +#define BUILD_TIME "21:26:13" +#define BUILD_DATETIME "Build time: 26.03.2023 21:26:13" +#define GIT_DATE "16.03.2022" +#define GIT_TIME "17:42:44" +#define GIT_DATETIME "Git time: Wed, 16-Mar-2022 17:42:44" +#define GIT_COUNT 71 +#define V_SECS 77173 +#define INTERNAL_NAME "wCenterWindowC++" +#define ORIG_FILE_NAME "wCenterWindow.exe" +#define PRODUCT_NAME_FULL "wCenterWindow v2.3.5 (C++)" +#define PRODUCT_COPYRIGHT "Copyright (C) 2020-2023 by W0LF aka 'dreamforce'" +#define VERSION_NUM 2,3,5 +#define VERSION_STR "2.3.5" +#define VERSION_NUM_FULL 2,3,5,71 +#define VERSION_STR_FULL "2.3.5.71" diff --git a/wCenterWindow/VersionInfo.rc b/wCenterWindow/VersionInfo.rc new file mode 100644 index 0000000000000000000000000000000000000000..696dad222a084b5f037087977447402209f342fc GIT binary patch literal 1954 zcmd6n-EP`I5QWcmrM`njZ>xr?d4cd76en2VAoa>Z4Uk9)ARton@=d<+vRSW_Rs!`R zvS97qnR8~&%Yzf z-#6WIW%FH<{;O(jfcYhzvTO^0@{ndYl zwp)~qa}UhUzFDzf!e^|p$B_7(?I|(ZbGr8list&Mj0ocx!ugoUTc}pG^2{y#`eg+j zZvsk!b&A^UQke!3?C2xwm<3h2BeNMEu0LFFI4|>i4=tQlQC&9SKSl~Z|3dUu6Y7|f zrD@P0?v)<2)|42Z=%*=PGxoo78uw9w-!;mdldW}hRRfRh*OER;e{LGW8bRG`qi4sZD({`qz}}Q?2{}w&5P#`q%RDm9wwV7gm46 zHpSdMbxdX%Tr1}Ik&f8al&g2%;kw1>|EmkS#Mz1Te7h6h2NRUryy|$&O%Qin4w}vC Xmg-DvGi3L2vz%P_R-Kj*XLx%7QS$Ne literal 0 HcmV?d00001 diff --git a/wCenterWindow/framework.h b/wCenterWindow/framework.h index f8f264b..80b8a6e 100644 --- a/wCenterWindow/framework.h +++ b/wCenterWindow/framework.h @@ -6,7 +6,6 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files -#include #include #include #include @@ -17,3 +16,4 @@ // Project Specific Header Files #include "Logger.h" +#include "VersionInfo.h" diff --git a/wCenterWindow/resource.h b/wCenterWindow/resource.h index 1f65376..ce35626 100644 --- a/wCenterWindow/resource.h +++ b/wCenterWindow/resource.h @@ -2,6 +2,10 @@ // Microsoft Visual C++ generated include file. // Used by wCenterWindow.rc // +#define V_MAJOR 2 +#define V_MINOR 3 +#define V_PATCH 4 +#define GIT_COUNT 72 #define IDS_CLASSNAME 102 #define IDS_APP_TITLE 103 #define IDD_ABOUTBOX 104 @@ -33,6 +37,8 @@ #define IDC_BUTTON_CLOSE 1007 #define IDC_ABOUTHELP 1008 #define IDC_DONATIONLINK 1009 +#define PRODUCT_YEAR_START 2020 +#define V_SECS 52245 #define IDC_STATIC -1 // Next default values for new objects diff --git a/wCenterWindow/wCenterWindow.rc b/wCenterWindow/wCenterWindow.rc index 303d3900847857558cf74bd21277cdc96c14aa81..cedd24744cd3a1152a42125a02b760a60f22bf97 100644 GIT binary patch delta 336 zcmdl|bSq`Tf{mB<2u?21k&#qjC}S{U&|@$LViN`h1`P&h25lhJoLtBwJ^6%Cl)Vyz z6GJIOCPNNG3Q)cT$jW6%Wv~LWjTj7px(vX2jexWfkfi_=GXcsP1Nl}!mMPerFk!LD zdBRSKN^vn1q;?1XQcQ5DpaeVQ>So5*f0A zSb;$u=$ay+I}(AeNduZ$#E=Z+se^3W{7P7cX>y6M0J8!^&18Lk@y!Ne7kDO1D2d62 z0o4>S6a($fXUJpl1Y(e0J+N-2$!nFQCmSe#+B`{n6VJpV5dx|Ul^0KbW#I(?VkJe3 delta 1605 zcma)6O>a_B5Ir@qA=>%{wjl)igt#!(N-G-^6T@eVr9j|;F)<wFL2+xcjnBQGc)&B(@gfzm~L7Z<1?xm1Y;RUyP?3`C$E}5PP_mbR=@jOOL zla?lT=rOcgnlsd%GdhDCWt1!)Fj^9u*n&BinosgIyj<9paR!K&O+S1`z9GfGVD|2de+D4^G)P7*C>F5h`PuGGsUa50Rxjp`p`6 zN|Qy;lA=yxa-Jvk2%BiyilNoPRnMwaKf}fp75t3VW%Jh2K#dIQOrpwiHAt%oznXIg z)DN#?MfVX#LEN^OJ>kD!9r`Y-kk_X^I~|)vYMf$xVdrO@CSIV0GBNjA;WEFf+`rCK zy|N|x707vu?AT-$Ch_t*-iTw2C>=btxVM;tHGC)FN-^_fB4d)3(Nf>MZsD3d9$O!U z0av~6O2jjXH}2ID+qjM>N_NS#&9zKz_55W_WY}|DMYHimF+#IxnIcln!Vy(l)Ke-~ z!!yP>UeVzNp~`2M)sfF3IcIc+nIVRBfG`~CD_@gJNk!y}k$eZkJi~Qc$ITMA$p+tJ zjk>nH?RB5M9;Khi)uyJ7`QKF%HBZOMA*SA}EZ;ELdGhEzU1YxParQG4a97XHq^)#x lhl-VL-6uE8U_PYB*RjC~2{Q7v{!!r3qWbCnq%LgS`wNg179#)v diff --git a/wCenterWindow/wCenterWindow.vcxproj b/wCenterWindow/wCenterWindow.vcxproj index b1e9ac9..3c2f0d1 100644 --- a/wCenterWindow/wCenterWindow.vcxproj +++ b/wCenterWindow/wCenterWindow.vcxproj @@ -73,16 +73,25 @@ true + false false false + false + false + false + false true false + false + false + false + false @@ -103,7 +112,8 @@ - "$(SolutionDir)Update_version.bat" + start "" /wait "$(SolutionDir)Update_version.bat" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" + @@ -113,8 +123,8 @@ true true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - MultiThreaded + false + MultiThreadedDLL stdcpp17 @@ -128,7 +138,8 @@ %(AdditionalManifestFiles) - "$(SolutionDir)Update_version.bat" + start "" /wait "$(SolutionDir)Update_version.bat" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" + @@ -160,13 +171,13 @@ NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true stdcpp17 - MultiThreaded + MultiThreadedDLL Windows true true - true + false comctl32.lib;%(AdditionalDependencies) From 266afddfe59f7389f11fe3dbf7abc85ed1185ead Mon Sep 17 00:00:00 2001 From: W0LF Date: Sun, 26 Mar 2023 22:50:18 +0300 Subject: [PATCH 03/15] Update About dialog. --- .gitignore | 1 + wCenterWindow/VersionInfo.h | 28 ---------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 wCenterWindow/VersionInfo.h diff --git a/.gitignore b/.gitignore index 0e1aa2f..142eac4 100644 --- a/.gitignore +++ b/.gitignore @@ -438,3 +438,4 @@ lightgbm.Rcheck/ *.gv *.gv.* /VersionInfo.h +/wCenterWindow/VersionInfo.h diff --git a/wCenterWindow/VersionInfo.h b/wCenterWindow/VersionInfo.h deleted file mode 100644 index e78339e..0000000 --- a/wCenterWindow/VersionInfo.h +++ /dev/null @@ -1,28 +0,0 @@ -// wCenterWindow -// version.h -// -#pragma once - -#define V_MAJOR 2 -#define V_MINOR 3 -#define V_PATCH 5 -#define PRODUCT_NAME "wCenterWindow" -#define PRODUCT_AUTHORS "W0LF aka 'dreamforce'" -#define PRODUCT_YEAR_START 2020 -#define PRODUCT_DESCRIPTION "Centers windows by hotkey" -#define BUILD_DATE "26.03.2023" -#define BUILD_TIME "21:26:13" -#define BUILD_DATETIME "Build time: 26.03.2023 21:26:13" -#define GIT_DATE "16.03.2022" -#define GIT_TIME "17:42:44" -#define GIT_DATETIME "Git time: Wed, 16-Mar-2022 17:42:44" -#define GIT_COUNT 71 -#define V_SECS 77173 -#define INTERNAL_NAME "wCenterWindowC++" -#define ORIG_FILE_NAME "wCenterWindow.exe" -#define PRODUCT_NAME_FULL "wCenterWindow v2.3.5 (C++)" -#define PRODUCT_COPYRIGHT "Copyright (C) 2020-2023 by W0LF aka 'dreamforce'" -#define VERSION_NUM 2,3,5 -#define VERSION_STR "2.3.5" -#define VERSION_NUM_FULL 2,3,5,71 -#define VERSION_STR_FULL "2.3.5.71" From 117c4f780fb891988812e0b4931dc0670c0cf9a0 Mon Sep 17 00:00:00 2001 From: W0LF Date: Sun, 26 Mar 2023 22:50:52 +0300 Subject: [PATCH 04/15] Update About dialog. --- wCenterWindow/resource.h | 5 +- wCenterWindow/wCenterWindow.cpp | 357 ++++++++++++++++---------------- wCenterWindow/wCenterWindow.rc | Bin 12890 -> 13062 bytes 3 files changed, 187 insertions(+), 175 deletions(-) diff --git a/wCenterWindow/resource.h b/wCenterWindow/resource.h index ce35626..37a7c26 100644 --- a/wCenterWindow/resource.h +++ b/wCenterWindow/resource.h @@ -37,6 +37,9 @@ #define IDC_BUTTON_CLOSE 1007 #define IDC_ABOUTHELP 1008 #define IDC_DONATIONLINK 1009 +#define IDC_ABOUT_PROGNAME 1010 +#define IDC_ABOUT_COPYRIGHT 1011 +#define IDC_ABOUT_BUILDTIME 1012 #define PRODUCT_YEAR_START 2020 #define V_SECS 52245 #define IDC_STATIC -1 @@ -48,7 +51,7 @@ #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 130 #define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1010 +#define _APS_NEXT_CONTROL_VALUE 1013 #define _APS_NEXT_SYMED_VALUE 122 #endif #endif diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 1100e9d..9803609 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -16,7 +16,7 @@ HINSTANCE hInst; // Instance WCHAR szTitle[MAX_LOADSTRING]; // Window's title WCHAR szClass[MAX_LOADSTRING]; // Window's class -WCHAR szAbout[MAX_LOADSTRING * 12]; // Description text +WCHAR szAboutHelp[MAX_LOADSTRING * 12]; // Description text WCHAR szWinTitle[256]; WCHAR szWinClass[256]; WCHAR szWinCore[] = L"Windows.UI.Core.CoreWindow"; @@ -194,125 +194,125 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { - case WM_CREATE: + case WM_CREATE: + { + diag_log("Recived WM_CREATE message"); + hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU)); + if (!hMenu) { - diag_log("Recived WM_CREATE message"); - hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU)); - if (!hMenu) - { - diag_log("Loading context menu failed!"); - ShowError(IDS_ERR_MENU); - PostMessageW(hWnd, WM_CLOSE, NULL, NULL); - } - diag_log("Context menu successfully loaded"); + diag_log("Loading context menu failed!"); + ShowError(IDS_ERR_MENU); + PostMessageW(hWnd, WM_CLOSE, NULL, NULL); + } + diag_log("Context menu successfully loaded"); - hPopup = GetSubMenu(hMenu, 0); - if (!hPopup) - { - diag_log("Creating popup menu failed!"); - ShowError(IDS_ERR_POPUP); - PostMessageW(hWnd, WM_CLOSE, NULL, NULL); - } - diag_log("Popup menu successfully created"); + hPopup = GetSubMenu(hMenu, 0); + if (!hPopup) + { + diag_log("Creating popup menu failed!"); + ShowError(IDS_ERR_POPUP); + PostMessageW(hWnd, WM_CLOSE, NULL, NULL); + } + diag_log("Popup menu successfully created"); - mii.cbSize = sizeof(MENUITEMINFO); - mii.fMask = MIIM_STATE; - bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; - SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); + mii.cbSize = sizeof(MENUITEMINFO); + mii.fMask = MIIM_STATE; + bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; + SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); - nid.cbSize = sizeof(NOTIFYICONDATAW); - nid.hWnd = hWnd; - nid.uVersion = NOTIFYICON_VERSION; - nid.uCallbackMessage = WM_WCW; - nid.hIcon = hIcon; - nid.uID = IDI_TRAYICON; - nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - nid.dwInfoFlags = NIIF_NONE; - nid.dwState = NIS_HIDDEN; - nid.dwStateMask = NIS_HIDDEN; - StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle); + nid.cbSize = sizeof(NOTIFYICONDATAW); + nid.hWnd = hWnd; + nid.uVersion = NOTIFYICON_VERSION; + nid.uCallbackMessage = WM_WCW; + nid.hIcon = hIcon; + nid.uID = IDI_TRAYICON; + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + nid.dwInfoFlags = NIIF_NONE; + nid.dwState = NIS_HIDDEN; + nid.dwStateMask = NIS_HIDDEN; + StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle); #ifndef _DEBUG - hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL); - if (!hMouseHook) - { - diag_log("Creating mouse hook failed!"); - ShowError(IDS_ERR_HOOK); - PostMessageW(hWnd, WM_CLOSE, NULL, NULL); - } - diag_log("Mouse hook was successfully set"); + hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL); + if (!hMouseHook) + { + diag_log("Creating mouse hook failed!"); + ShowError(IDS_ERR_HOOK); + PostMessageW(hWnd, WM_CLOSE, NULL, NULL); + } + diag_log("Mouse hook was successfully set"); #endif // !_DEBUG - hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); - if (!hKbdHook) + hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); + if (!hKbdHook) + { + diag_log("Creating keyboard hook failed!"); + ShowError(IDS_ERR_HOOK); + PostMessageW(hWnd, WM_CLOSE, NULL, NULL); + } + diag_log("Keyboard hook was successfully set"); + + LoadStringW(hInst, IDS_ABOUT, szAboutHelp, _countof(szAboutHelp)); + break; + } + + case WM_WCW: + { + if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam)) + { + diag_log("Entering menu handler"); + SetForegroundWindow(hWnd); + POINT pt; + GetCursorPos(&pt); + int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL); + if (ID_POPUPMENU_ICON == idMenu) { - diag_log("Creating keyboard hook failed!"); - ShowError(IDS_ERR_HOOK); + diag_log("Pressed 'Hide icon' menuitem"); + bShowIcon = FALSE; + HandlingTrayIcon(); + } + if (ID_POPUPMENU_AREA == idMenu) + { + diag_log("Pressed 'Use workarea' menuitem"); + bWorkArea = !bWorkArea; + bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; + SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); + diag_log("Changed 'Use workarea' option to ", bWorkArea); + } + if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed) + { + diag_log("Pressed 'About' menuitem"); + bKPressed = TRUE; + DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); + bKPressed = FALSE; + } + if (ID_POPUPMENU_EXIT == idMenu) + { + diag_log("Pressed 'Exit' menuitem"); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } - diag_log("Keyboard hook was successfully set"); - - LoadStringW(hInst, IDS_ABOUT, szAbout, _countof(szAbout)); - break; + diag_log("Quiting menu handler"); } + break; + } - case WM_WCW: - { - if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam)) - { - diag_log("Entering menu handler"); - SetForegroundWindow(hWnd); - POINT pt; - GetCursorPos(&pt); - int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL); - if (ID_POPUPMENU_ICON == idMenu) - { - diag_log("Pressed 'Hide icon' menuitem"); - bShowIcon = FALSE; - HandlingTrayIcon(); - } - if (ID_POPUPMENU_AREA == idMenu) - { - diag_log("Pressed 'Use workarea' menuitem"); - bWorkArea = !bWorkArea; - bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; - SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); - diag_log("Changed 'Use workarea' option to ", bWorkArea); - } - if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed) - { - diag_log("Pressed 'About' menuitem"); - bKPressed = TRUE; - DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); - bKPressed = FALSE; - } - if (ID_POPUPMENU_EXIT == idMenu) - { - diag_log("Pressed 'Exit' menuitem"); - PostMessageW(hWnd, WM_CLOSE, NULL, NULL); - } - diag_log("Quiting menu handler"); - } - break; - } + case WM_QUERYENDSESSION: + { + diag_log("Recieved WM_QUERYENDSESSION message, lParam = ", lParam); + CloseLogFile(); + return TRUE; + break; + } - case WM_QUERYENDSESSION: - { - diag_log("Recieved WM_QUERYENDSESSION message, lParam = ", lParam); - CloseLogFile(); - return TRUE; - break; - } + case WM_DESTROY: + { + diag_log("Recived WM_DESTROY message"); + PostQuitMessage(0); + break; + } - case WM_DESTROY: - { - diag_log("Recived WM_DESTROY message"); - PostQuitMessage(0); - break; - } - - default: - return DefWindowProcW(hWnd, message, wParam, lParam); + default: + return DefWindowProcW(hWnd, message, wParam, lParam); } return 0; } @@ -390,52 +390,52 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) int x, y, w, h; switch (dlgmsg) { - case WM_INITDIALOG: + case WM_INITDIALOG: + { + diag_log("Initializing 'Manual editing' dialog"); + SetWindowTextW(hDlg, szTitle); + GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle)); + GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass)); + GetWindowRect(hFgWnd, &rcFW); + x = rcFW.left; + y = rcFW.top; + w = rcFW.right - rcFW.left; + h = rcFW.bottom - rcFW.top; + SetDlgItemInt(hDlg, IDC_EDIT_X, x, TRUE); + SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE); + SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE); + SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE); + SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle); + SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass); + UpdateWindow(hDlg); + break; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) { - diag_log("Initializing 'Manual editing' dialog"); - SetWindowTextW(hDlg, szTitle); - GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle)); - GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass)); - GetWindowRect(hFgWnd, &rcFW); - x = rcFW.left; - y = rcFW.top; - w = rcFW.right - rcFW.left; - h = rcFW.bottom - rcFW.top; - SetDlgItemInt(hDlg, IDC_EDIT_X, x, TRUE); - SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE); - SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE); - SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE); - SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle); - SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass); - UpdateWindow(hDlg); + case IDC_BUTTON_SET: + { + diag_log("Pressed 'Set' button"); + x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE); + y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE); + w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE); + h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE); + SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL); + MoveWindow(hFgWnd, x, y, w, h, TRUE); + SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); + diag_log("Window with handle 0x", hFgWnd, " was moved to x = ", x, ", y = ", y); + return TRUE; break; } - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_BUTTON_SET: - { - diag_log("Pressed 'Set' button"); - x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE); - y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE); - w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE); - h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE); - SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL); - MoveWindow(hFgWnd, x, y, w, h, TRUE); - SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); - diag_log("Window with handle 0x", hFgWnd, " was moved to x = ", x, ", y = ", y); - return TRUE; - break; - } - case IDCANCEL: - case IDC_BUTTON_CLOSE: - { - diag_log("Closing 'Manual editing' dialog"); - EndDialog(hDlg, LOWORD(wParam)); - break; - } - } + case IDCANCEL: + case IDC_BUTTON_CLOSE: + { + diag_log("Closing 'Manual editing' dialog"); + EndDialog(hDlg, LOWORD(wParam)); + break; + } + } } return FALSE; } @@ -507,38 +507,47 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: + { + diag_log("Initializing 'About' dialog"); + WCHAR szAboutProgName[MAX_LOADSTRING]; + WCHAR szAboutCopyright[MAX_LOADSTRING]; + WCHAR szAboutBuildTime[MAX_LOADSTRING]; + MultiByteToWideChar(1251, 0, PRODUCT_NAME_FULL, _countof(PRODUCT_NAME_FULL), szAboutProgName, MAX_LOADSTRING); + MultiByteToWideChar(1251, 0, PRODUCT_COPYRIGHT, _countof(PRODUCT_COPYRIGHT), szAboutCopyright, MAX_LOADSTRING); + MultiByteToWideChar(1251, 0, BUILD_DATETIME, _countof(BUILD_DATETIME), szAboutBuildTime, MAX_LOADSTRING); + SetDlgItemTextW(hDlg, IDC_ABOUT_PROGNAME, szAboutProgName); + SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright); + SetDlgItemTextW(hDlg, IDC_ABOUT_BUILDTIME, szAboutBuildTime); + SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAboutHelp); + return (INT_PTR)TRUE; + break; + } + + case WM_NOTIFY: + { + LPNMHDR pNMHdr = (LPNMHDR)lParam; + if ((NM_CLICK == pNMHdr->code || NM_RETURN == pNMHdr->code) && IDC_DONATIONLINK == pNMHdr->idFrom) { - diag_log("Initializing 'About' dialog"); - SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAbout); + PNMLINK pNMLink = (PNMLINK)pNMHdr; + LITEM item = pNMLink->item; + ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); + diag_log("Pressed donation link"); return (INT_PTR)TRUE; - break; } + break; + } - case WM_NOTIFY: + case WM_COMMAND: + { + if (IDOK == LOWORD(wParam) || IDCANCEL == LOWORD(wParam)) { - LPNMHDR pNMHdr = (LPNMHDR)lParam; - if ((NM_CLICK == pNMHdr->code || NM_RETURN == pNMHdr->code) && IDC_DONATIONLINK == pNMHdr->idFrom) - { - PNMLINK pNMLink = (PNMLINK)pNMHdr; - LITEM item = pNMLink->item; - ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); - diag_log("Pressed donation link"); - return (INT_PTR)TRUE; - } - break; - } - - case WM_COMMAND: - { - if (IDOK == LOWORD(wParam) || IDCANCEL == LOWORD(wParam)) - { - EndDialog(hDlg, LOWORD(wParam)); - diag_log("Closing 'About' dialog"); - return (INT_PTR)TRUE; - } - break; + EndDialog(hDlg, LOWORD(wParam)); + diag_log("Closing 'About' dialog"); + return (INT_PTR)TRUE; } + break; + } } return (INT_PTR)FALSE; } diff --git a/wCenterWindow/wCenterWindow.rc b/wCenterWindow/wCenterWindow.rc index cedd24744cd3a1152a42125a02b760a60f22bf97..5b3c0d3257cc64efdc77544acb5a872e626edafb 100644 GIT binary patch delta 317 zcmcbW(w4U2hycGEgC|1-gDZmzLoh=mL-1rr_SDTXf*g#Z&Okvwh7ceb1XSY7;K<<4 z;5vCOm%h3ZgAP!{g~6F29w_R>;Li{WR2R<>095G@ROJU0^#!VZ&t)qb3^X<#DB=&6 zb!7lsH@TNblGB922xyKWgUMuD5y{D`xRf+;nd<~J-;==yXk!T2C18`Kv6{@Fz)-`W rFxgW~dGahCp2-QqB9pyDc<`F;40c;2*q81M9t+Bld|+GQVct78gn$&xF+3 zP)2yH(59xSn%$YQ8>#2Bu8uFY&6a8d-+UC^LV+pG=W$}bos#)-ot+j>+;B%Cre)T0rse)4az>XP9S&9ZXmPA7I`)cQn|mI3ArO}oyNb#<)uHT4mT+P From a1db2f16e93c3109518d6595228bed4873b82c5b Mon Sep 17 00:00:00 2001 From: W0LF Date: Sun, 26 Mar 2023 23:05:36 +0300 Subject: [PATCH 05/15] Update versioning script. --- Update_version.bat | 2 +- wCenterWindow/VersionInfo.rc | Bin 1954 -> 1838 bytes wCenterWindow/resource.h | 6 ------ wCenterWindow/wCenterWindow.rc | Bin 13062 -> 12982 bytes 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Update_version.bat b/Update_version.bat index 3df6465..f4ad142 100644 --- a/Update_version.bat +++ b/Update_version.bat @@ -58,7 +58,7 @@ SET VS=%VerMajor%.%VerMinor%.%VerPatch% SET VNF=%VerMajor%,%VerMinor%,%VerPatch%,%GIT_COUNT% SET VN=%VerMajor%,%VerMinor%,%VerPatch% -SET PNF=%PN% v%VS% (C++) +SET PNF=%PN% v%VSF% (C++) SET PCF=Copyright (C) %PYS%-%CURRENT_YEAR% by %PA% SET INT_NAME=%PN%C++ diff --git a/wCenterWindow/VersionInfo.rc b/wCenterWindow/VersionInfo.rc index 696dad222a084b5f037087977447402209f342fc..8e7e879f09d5847859e37fc1f6af47bb8d4a0127 100644 GIT binary patch delta 59 zcmZ3)zm8A)|37^OeFg=Fat3FHRE9i;5+GT`5YCVZWT!CX1I2k6xPU5vY9`*6WG-Sz J-njcY8vwSo4zBqCi{p;OfC`@5j9~jV$gwNa|SaY+k!!7@ Date: Sun, 26 Mar 2023 23:16:05 +0300 Subject: [PATCH 06/15] Move global szAboutHelp variable to local. --- wCenterWindow/wCenterWindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 9803609..679329f 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -16,7 +16,6 @@ HINSTANCE hInst; // Instance WCHAR szTitle[MAX_LOADSTRING]; // Window's title WCHAR szClass[MAX_LOADSTRING]; // Window's class -WCHAR szAboutHelp[MAX_LOADSTRING * 12]; // Description text WCHAR szWinTitle[256]; WCHAR szWinClass[256]; WCHAR szWinCore[] = L"Windows.UI.Core.CoreWindow"; @@ -251,8 +250,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } diag_log("Keyboard hook was successfully set"); - - LoadStringW(hInst, IDS_ABOUT, szAboutHelp, _countof(szAboutHelp)); break; } @@ -510,12 +507,15 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: { diag_log("Initializing 'About' dialog"); + WCHAR szAboutProgName[MAX_LOADSTRING]; WCHAR szAboutCopyright[MAX_LOADSTRING]; WCHAR szAboutBuildTime[MAX_LOADSTRING]; + WCHAR szAboutHelp[MAX_LOADSTRING * 12]; MultiByteToWideChar(1251, 0, PRODUCT_NAME_FULL, _countof(PRODUCT_NAME_FULL), szAboutProgName, MAX_LOADSTRING); MultiByteToWideChar(1251, 0, PRODUCT_COPYRIGHT, _countof(PRODUCT_COPYRIGHT), szAboutCopyright, MAX_LOADSTRING); MultiByteToWideChar(1251, 0, BUILD_DATETIME, _countof(BUILD_DATETIME), szAboutBuildTime, MAX_LOADSTRING); + LoadStringW(hInst, IDS_ABOUT, szAboutHelp, _countof(szAboutHelp)); SetDlgItemTextW(hDlg, IDC_ABOUT_PROGNAME, szAboutProgName); SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright); SetDlgItemTextW(hDlg, IDC_ABOUT_BUILDTIME, szAboutBuildTime); From 9b3b505ec652f885efe70d3143715e1b10893245 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Sun, 2 Apr 2023 16:50:15 +0300 Subject: [PATCH 07/15] Update pre-build scripts. --- Update_Version.ps1 | 85 ++++++++++++++++++++++++++ Update_version.bat | 90 ---------------------------- pre-build.cmd | 22 +++++++ wCenterWindow.sln | 3 +- wCenterWindow/VersionInfo.rc | Bin 1838 -> 1914 bytes wCenterWindow/wCenterWindow.cpp | 2 +- wCenterWindow/wCenterWindow.vcxproj | 10 ++-- 7 files changed, 113 insertions(+), 99 deletions(-) create mode 100644 Update_Version.ps1 delete mode 100644 Update_version.bat create mode 100644 pre-build.cmd diff --git a/Update_Version.ps1 b/Update_Version.ps1 new file mode 100644 index 0000000..81a998d --- /dev/null +++ b/Update_Version.ps1 @@ -0,0 +1,85 @@ +# Update_Version.ps1 + +$date = Get-Date + +function ParseString ([string]$searchString) { + [string]$result = (Select-String -Path '.\VersionInfo.h' -Pattern $searchString -SimpleMatch).Line + if ([string]::IsNullOrEmpty($result)) { return -1 } + return ($result -split "\s+", 3).Trim('"')[2] +} + +$currentYear = $date.Year +$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))" +$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays) +$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds) + +if (-not (Test-Path .\Version.h)) { + Write-Host "Can't find file 'Version.h'" + Start-Sleep -Seconds 3 + exit +} +Copy-Item .\Version.h .\VersionInfo.h + +$verMajor = ParseString("V_MAJOR") +$verMinor = ParseString("V_MINOR") +$verPatch = ParseString("V_PATCH") +$pn = ParseString("PRODUCT_NAME") +$pa = ParseString("PRODUCT_AUTHORS") +$pys = ParseString("PRODUCT_YEAR_START") +$aboutBuild = "" +$pnf = "" + +if ($pys -eq $currentYear) { + $pcf = "Copyright (C) $pys by $pa" +} else { + $pcf = "Copyright (C) $pys-$currentYear by $pa" +} + +if (Test-Path .\.git) { + $gitCommitCount = Invoke-Expression -Command "git rev-list --count HEAD" + $gitRevBranch = Invoke-Expression -Command "git symbolic-ref --short HEAD" + $gitRevDate = Invoke-Expression -Command "git log -1 --date=rfc --pretty=format:%ad%n" + $gitVerStr = Invoke-Expression -Command "git describe --long" + + if ($LastExitCode -eq 0) { + $gitVerStr = $gitVerStr.Replace('-g', '-') + $gitRevCount = $gitVerStr.Split('-')[-2] + } else { + $gitVerStr = "" + $gitRevCount = $gitCommitCount + } + + $vs = [string]::Join(".", $verMajor, $verMinor, $verPatch, $gitRevCount) + $vn = [string]::Join(",", $verMajor, $verMinor, $verPatch, $gitRevCount) + + if ($gitVerStr -eq "") { + $pnf = "$pn v$vs" + } else { + $pnf = "$pn $gitVerStr".Trim() + } + + "#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_REV_BRANCH `"$gitRevBranch`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + $aboutBuild = "Git date: $gitRevDate" +} else { + $vs = [string]::Join(".", $verMajor, $verMinor, $verPatch) + $vn = [string]::Join(",", $verMajor, $verMinor, $verPatch) + $pnf = "$pn v$vs" + $aboutBuild = $buildDateTime +} + +$intName = "$pn`C++" +$origName = "$pn.exe" + +"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_NAME_FULL `"$pnf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define INTERNAL_NAME `"$intName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define ORIG_FILE_NAME `"$origName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_COPYRIGHT `"$pcf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define VERSION_STR `"$vs`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define VERSION_NUM $vn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append diff --git a/Update_version.bat b/Update_version.bat deleted file mode 100644 index f4ad142..0000000 --- a/Update_version.bat +++ /dev/null @@ -1,90 +0,0 @@ -@ECHO OFF -CHCP 1251 >nul -SETLOCAL ENABLEDELAYEDEXPANSION - -SET CURRENT_TIME=%TIME% -SET CURRENT_DATE=%DATE% - -SET BUILDTIME=%CURRENT_TIME:~0,8% -SET BUILDDATE=%CURRENT_DATE% -SET BUILD_DATETIME=Build time: %BUILDDATE% %BUILDTIME% -SET CURRENT_YEAR=%CURRENT_DATE:~6,4% -SET BUILDSECS=0 - -SET GIT_COUNT=0 -SET GIT_TIME=0 -SET GIT_DATE=0 -SET GIT_DATETIME=0 - -SET VerMajor=0 -SET VerMinor=0 -SET VerPatch=0 - -SET INT_NAME=0 -SET PN=0 -SET VS=0 -SET VSF=0 -SET PCF=0 -SET PYS=0 -SET PA=0 - -CD /D %~dp0 -IF NOT EXIST "Version.h" ( - ECHO Can't find file 'Version.h' - TIMEOUT /T 3 - EXIT /B 1 -) -COPY /Y "Version.h" "VersionInfo.h" >nul - -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MAJOR" "VersionInfo.h"') DO (SET "VerMajor=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_MINOR" "VersionInfo.h"') DO (SET "VerMinor=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define V_PATCH" "VersionInfo.h"') DO (SET "VerPatch=%%A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_NAME" "VersionInfo.h"') DO (SET "PN=%%~A") -FOR /F "tokens=3" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_YEAR_START" "VersionInfo.h"') DO (SET "PYS=%%A") -FOR /F "tokens=2*" %%A IN ('FINDSTR /I /L /C:"define PRODUCT_AUTHORS" "VersionInfo.h"') DO (SET "PA=%%~B") -FOR /F "tokens=1-4 delims=:., " %%A IN ("%BUILDTIME%") DO (SET /A "BUILDSECS=%%A * 3600 + %%B * 60 + %%C") - -IF EXIST ".git" ( - FOR /F "delims=" %%A IN ('git rev-list --count HEAD') DO (SET /A GIT_COUNT=%%A) - FOR /F "tokens=1,2 delims= " %%A IN ('git log -1 --date=format:%%d.%%m.%%Y ^| find /I "Date:"') DO (SET "GIT_DATE=%%B") - FOR /F "tokens=2-4 delims=, " %%A IN ('git log -1 --date=format:"%%a,%%d-%%h-%%Y,%%T" ^| find /I "Date:"') DO ( - SET "GIT_DATETIME=Git time: %%A, %%B %%C" - SET "GIT_TIME=%%C" - ) -) - -SET VSF=%VerMajor%.%VerMinor%.%VerPatch%.%GIT_COUNT% -SET VS=%VerMajor%.%VerMinor%.%VerPatch% -SET VNF=%VerMajor%,%VerMinor%,%VerPatch%,%GIT_COUNT% -SET VN=%VerMajor%,%VerMinor%,%VerPatch% - -SET PNF=%PN% v%VSF% (C++) -SET PCF=Copyright (C) %PYS%-%CURRENT_YEAR% by %PA% - -SET INT_NAME=%PN%C++ -SET ORIG_NAME=%PN%.exe - -ECHO #define BUILD_DATE "%BUILDDATE%">> VersionInfo.h -ECHO #define BUILD_TIME "%BUILDTIME%">> VersionInfo.h -ECHO #define BUILD_DATETIME "%BUILD_DATETIME%">> VersionInfo.h - -IF EXIST ".git" ( - ECHO #define GIT_DATE "%GIT_DATE%">> VersionInfo.h - ECHO #define GIT_TIME "%GIT_TIME%">> VersionInfo.h - ECHO #define GIT_DATETIME "%GIT_DATETIME%">> VersionInfo.h - ECHO #define GIT_COUNT %GIT_COUNT% >> VersionInfo.h -) - -ECHO #define V_SECS %BUILDSECS% >> VersionInfo.h -ECHO #define INTERNAL_NAME "%INT_NAME%">> VersionInfo.h -ECHO #define ORIG_FILE_NAME "%ORIG_NAME%">> VersionInfo.h -ECHO #define PRODUCT_NAME_FULL "%PNF%">> VersionInfo.h -ECHO #define PRODUCT_COPYRIGHT "%PCF%">> VersionInfo.h -ECHO #define VERSION_NUM %VN% >> VersionInfo.h -ECHO #define VERSION_STR "%VS%">> VersionInfo.h -ECHO #define VERSION_NUM_FULL %VNF% >> VersionInfo.h -ECHO #define VERSION_STR_FULL "%VSF%">> VersionInfo.h - -ENDLOCAL -TIMEOUT /T 1 >nul -EXIT diff --git a/pre-build.cmd b/pre-build.cmd new file mode 100644 index 0000000..a5d6210 --- /dev/null +++ b/pre-build.cmd @@ -0,0 +1,22 @@ +@ECHO OFF + +REM In VisualStudio add to Pre-Build events: +REM "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" +REM Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives' + +IF "%~1" == "" GOTO :no_args +IF "%~2" == "" GOTO :no_args +SET solutionDir=%1 +SET projectDir=%2 + +ECHO solutionDir: %solutionDir% +ECHO projectDir: %projectDir% + +CD /D %solutionDir% +powershell -ExecutionPolicy RemoteSigned -File Update_Version.ps1 +MOVE /Y %solutionDir%VersionInfo.h %projectDir%VersionInfo.h +EXIT + +:no_args +ECHO Not enough arguments! +EXIT 1 diff --git a/wCenterWindow.sln b/wCenterWindow.sln index fe3ab9e..8f2ed13 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -7,8 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}" ProjectSection(SolutionItems) = preProject - Update_version.bat = Update_version.bat - Version.h = Version.h + Update_Version.ps1 = Update_Version.ps1 EndProjectSection EndProject Global diff --git a/wCenterWindow/VersionInfo.rc b/wCenterWindow/VersionInfo.rc index 8e7e879f09d5847859e37fc1f6af47bb8d4a0127..bf98286edc1e5cbbb3c4df268bd23de666c072c6 100644 GIT binary patch delta 204 zcmZ3-_lvLo|37_(0fZ`eE$3z60?AKQl$_|XZW5!_ - start "" /wait "$(SolutionDir)Update_version.bat" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" - + "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" @@ -138,8 +137,7 @@ %(AdditionalManifestFiles) - start "" /wait "$(SolutionDir)Update_version.bat" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" - + powershell -ExecutionPolicy RemoteSigned -File "$(SolutionDir)Update_Version.ps1" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" @@ -159,7 +157,7 @@ %(AdditionalManifestFiles) - "$(SolutionDir)Update_version.bat" + powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" @@ -184,7 +182,7 @@ %(AdditionalManifestFiles) - "$(SolutionDir)Update_version.bat" + powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)" From 8cd54374abb4f3bf35a1f66dfcee6c06c95c93c3 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Sat, 8 Apr 2023 11:00:40 +0300 Subject: [PATCH 08/15] Update versioning script. --- Update_Version.ps1 | 194 ++++++++++++++++++++++++++++++++------------- Version.ini | Bin 0 -> 998 bytes wCenterWindow.sln | 2 +- 3 files changed, 138 insertions(+), 58 deletions(-) create mode 100644 Version.ini diff --git a/Update_Version.ps1 b/Update_Version.ps1 index 81a998d..7e91af4 100644 --- a/Update_Version.ps1 +++ b/Update_Version.ps1 @@ -1,85 +1,165 @@ -# Update_Version.ps1 +# Update Version v2.0 +# Required module: PSIni +# Installation: Install-Module -Name PsIni $date = Get-Date -function ParseString ([string]$searchString) { - [string]$result = (Select-String -Path '.\VersionInfo.h' -Pattern $searchString -SimpleMatch).Line - if ([string]::IsNullOrEmpty($result)) { return -1 } - return ($result -split "\s+", 3).Trim('"')[2] +function addLeadingZero([int]$nvar) { + [string]$svar = $null + if ($nvar -lt 10) { $svar = '0' + $nvar.ToString() } + else { $svar = $nvar.ToString() } + return $svar } -$currentYear = $date.Year -$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))" -$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays) -$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds) - -if (-not (Test-Path .\Version.h)) { - Write-Host "Can't find file 'Version.h'" - Start-Sleep -Seconds 3 - exit +function getValue([string]$var) { + switch -CaseSensitive ($var) { + "%y" { $var = $currentYear; break } + "%m" { $var = $currentMonth; break } + "%d" { $var = $currentDay; break } + "%t" { $var = -join ((addLeadingZero($currentHour)), (addLeadingZero($currentMinute)), (addLeadingZero($currentSecond))); break } + "%D" { $var = $spanDays; break } + "%S" { $var = $spanSecs; break } + "%C" { $var = $gitCommitCount; break } + "%c" { $var = $gitRevCount; break } + } + return $var } -Copy-Item .\Version.h .\VersionInfo.h -$verMajor = ParseString("V_MAJOR") -$verMinor = ParseString("V_MINOR") -$verPatch = ParseString("V_PATCH") -$pn = ParseString("PRODUCT_NAME") -$pa = ParseString("PRODUCT_AUTHORS") -$pys = ParseString("PRODUCT_YEAR_START") -$aboutBuild = "" -$pnf = "" +function makeVersionString([string]$vmaj, [string]$vmin, [string]$vbld, [string]$vrev) { + [string]$vstr = $null + if ($vmin -eq "") { $vmin = $vbld = $vrev = 0; $vstr = ($vmaj) -join '.' } + else { + if ($vbld -eq "") { $vbld = $vrev = 0; $vstr = ($vmaj, $vmin) -join '.' } + else { + if ($vrev -eq "") { $vrev = 0; $vstr = ($vmaj, $vmin, $vbld) -join '.' } + else { $vstr = ($vmaj, $vmin, $vbld, $vrev) -join '.' } + } + } + [string]$nstr = ($vmaj, $vmin, $vbld, $vrev) -join ',' + $res = @($vstr, $nstr) + return $res +} -if ($pys -eq $currentYear) { - $pcf = "Copyright (C) $pys by $pa" -} else { - $pcf = "Copyright (C) $pys-$currentYear by $pa" -} +#region Initializing variables +[string]$verMajor = [string]$verMinor = [string]$verBuild = [string]$verRevision = $null +[string]$pn = [string]$pa = [string]$aboutBuild = [string]$pnf = [string]$pcf = $null +[string]$buildDateTime = [string]$vs = [string]$vn = [string]$intName = [string]$origName = $null +[int]$pys = [int]$spanDays = [int]$spanSecs = $null +[int]$currentYear = [int]$currentMonth = [int]$currentDay = [int]$currentHour = [int]$currentMinute = [int]$currentSecond = $null +[string]$iniFile = ".\Version.ini" +#endregion -if (Test-Path .\.git) { - $gitCommitCount = Invoke-Expression -Command "git rev-list --count HEAD" - $gitRevBranch = Invoke-Expression -Command "git symbolic-ref --short HEAD" - $gitRevDate = Invoke-Expression -Command "git log -1 --date=rfc --pretty=format:%ad%n" - $gitVerStr = Invoke-Expression -Command "git describe --long" +if (-not (Test-Path $iniFile)) { + Write-Error "Can't find file '$iniFile'" + # Start-Sleep -Seconds 3 + exit 1 +} +[bool]$isGit = $false +if (Test-Path ".\.git") { + $isGit = $true + [int]$gitCommitCount = [int]$gitRevCount = $null + [string]$gitRevDate = [string]$gitVerStr = $null + $gitCommitCount = $(git rev-list --count HEAD) + $gitRevDate = $(git log -1 HEAD --date=rfc --pretty=format:%ad%n) + $gitVerStr = $(git describe HEAD --long) if ($LastExitCode -eq 0) { $gitVerStr = $gitVerStr.Replace('-g', '-') $gitRevCount = $gitVerStr.Split('-')[-2] - } else { + } + else { $gitVerStr = "" $gitRevCount = $gitCommitCount } - $vs = [string]::Join(".", $verMajor, $verMinor, $verPatch, $gitRevCount) - $vn = [string]::Join(",", $verMajor, $verMinor, $verPatch, $gitRevCount) +} - if ($gitVerStr -eq "") { - $pnf = "$pn v$vs" - } else { - $pnf = "$pn $gitVerStr".Trim() - } +#region Reading values from INI file +$config = $null +$config = (Get-IniContent -FilePath $iniFile)["Config"] +$verMajor = $config.Major +$verMinor = $config.Minor +$verBuild = $config.Build +$verRevision = $config.Revision +$pys = $config.ProductYearStart +$pn = $config.ProductName +$pa = $config.ProductAutors +$pd = $config.ProductDescription +#endregion - "#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - "#define GIT_REV_BRANCH `"$gitRevBranch`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - $aboutBuild = "Git date: $gitRevDate" -} else { - $vs = [string]::Join(".", $verMajor, $verMinor, $verPatch) - $vn = [string]::Join(",", $verMajor, $verMinor, $verPatch) - $pnf = "$pn v$vs" - $aboutBuild = $buildDateTime -} +if ($verMajor -eq "") { + Write-Error "Major version cannot be empty!" + # Start-Sleep -Seconds 3 + exit 2 +} -$intName = "$pn`C++" +#region Variables preparation +$currentYear = $date.Year +$currentMonth = $date.Month +$currentDay = $date.Day +$currentHour = $date.Hour +$currentMinute = $date.Minute +$currentSecond = $date.Second +$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))" +$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays) +$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds) +if ($pys -eq $currentYear) { $pcf = "Copyright (C) $pys by $pa" } else { $pcf = "Copyright (C) $pys-$currentYear by $pa" } +$intName = "$pn-C++" $origName = "$pn.exe" +$verMajor = getValue $verMajor +$verMinor = getValue $verMinor +$verBuild = getValue $verBuild +$verRevision = getValue $verRevision +#endregion -"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +$vs = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[0] +$vn = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[1] + +if ([string]::IsNullOrEmpty($gitVerStr)) { $pnf = "$pn v$vs" } else { $pnf = "$pn $gitVerStr" } +if ($isGit) { $aboutBuild = "Git date: $gitRevDate" } else { $aboutBuild = $buildDateTime } + +#region Save all variables to file +"// $pn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode +"// VersionInfo.h" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#pragma once" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_NAME `"$pn`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define PRODUCT_NAME_FULL `"$pnf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_AUTHORS `"$pa`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define PRODUCT_DESCRIPTION `"$pd`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +"#define ABOUT_BUILD `"$aboutBuild`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define INTERNAL_NAME `"$intName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define ORIG_FILE_NAME `"$origName`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define PRODUCT_COPYRIGHT `"$pcf`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define VERSION_STR `"$vs`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append "#define VERSION_NUM $vn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append -"#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append -"#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# "#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# "#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +if ($isGit) { + "#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + # "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + # "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append + # "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +} +#endregion + +#region Print out all variables +# echo " verMajor: [$verMajor]" +# echo " verMinor: [$verMinor]" +# echo " verBuild: [$verBuild]" +# echo " verRevision: [$verRevision]" +# echo "" +# echo " aboutBuild: [$aboutBuild]" +# echo " productNameFull: [$pnf]" +# echo "productCopyrightFull: [$pcf]" +# echo " internalName: [$intName]" +# echo " originalName: [$origName]" +# echo " versionStr: [$vs]" +# echo " versionNum: [$vn]" +# echo " spanDays: [$spanDays]" +# echo " spanSecs: [$spanSecs]" +# echo "" +# echo " gitCommitCount: [$gitCommitCount]" +# echo " gitRevCount: [$gitRevCount]" +# echo " gitRevDate: [$gitRevDate]" +# echo " gitVerStr: [$gitVerStr]" +#endregion diff --git a/Version.ini b/Version.ini new file mode 100644 index 0000000000000000000000000000000000000000..204fc66586c2b6ae0b5849a8473db05a4ac7cc0a GIT binary patch literal 998 zcmaizPfx-?5XI+g;&-SA!byYZ&3I6V@gT;?ff(ZfT7(J((iTj=y!v~)#a4xwN&n33 z%zJNUcRxR#tz%1D*sH}hu@^hE1G})m8dmT=<_T?WDK;i6$1nIB;#Zl;p3KA{=Qge7 zMtgE2FpFBAn0B$}=uA)$@Llk}#d=sD3+Q5rvZRL7Epaki!JrDyl)3Dbe5r5QshyPX zHeXrQpOB@c!pKk%y6z&P;@u)8=!)RcG^fm~Lg|z!IdwT&=J>)`mvfy^qplT8FnL+6 zJ}m41uc_;q!<0E(aZbMRdU$UzrJ!!;CM7Gz*MvgW7MOGfHgeM*qiBU+*pb7i*I$y= zE~DBNkE-aIi(b=XOuyQDMbBOI5!?;&idSn5&ZB1b;3gVT8N&KRuFhPae|@FPv$kON zd-b#8o;-g}l=lv*Kfmg90P6xZOX7dIuHe)jX(FCw0K=W#;0n>R0rtuXIbbor*{Ry$lcm0t2xned857n D0U)4b literal 0 HcmV?d00001 diff --git a/wCenterWindow.sln b/wCenterWindow.sln index 8f2ed13..2e42ca0 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -7,7 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}" ProjectSection(SolutionItems) = preProject - Update_Version.ps1 = Update_Version.ps1 + Version.h = Version.h EndProjectSection EndProject Global From 28ea9794921206d3ea5fd78410dc8720c8c98193 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Sat, 8 Apr 2023 11:55:56 +0300 Subject: [PATCH 09/15] Hid the donation link. --- wCenterWindow.sln | 2 +- wCenterWindow/wCenterWindow.cpp | 5 +++++ wCenterWindow/wCenterWindow.rc | Bin 12982 -> 12954 bytes 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wCenterWindow.sln b/wCenterWindow.sln index 2e42ca0..f277e52 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -7,7 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}" ProjectSection(SolutionItems) = preProject - Version.h = Version.h + Version.ini = Version.ini EndProjectSection EndProject Global diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index aa34978..0b2209b 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -4,6 +4,7 @@ #include "framework.h" #include "wCenterWindow.h" +#define NO_DONATION #define KEY_I 0x49 #define KEY_C 0x43 #define KEY_V 0x56 @@ -520,6 +521,10 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright); SetDlgItemTextW(hDlg, IDC_ABOUT_BUILDTIME, szAboutBuildTime); SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAboutHelp); +#ifdef NO_DONATION + HWND hLink = GetDlgItem(hDlg, IDC_DONATIONLINK); + if (hLink) DestroyWindow(hLink); +#endif // !NO_DONATION return (INT_PTR)TRUE; break; } diff --git a/wCenterWindow/wCenterWindow.rc b/wCenterWindow/wCenterWindow.rc index 246ebd325bea870a4a2012bb4776085615948d6d..e752b58cfb0ed11e73c3b6cdd52ea5d43a081639 100644 GIT binary patch delta 12 Ucmdm%IxBU<8nMkM#NJ5*04fXyCjbBd delta 36 scmbQ0x-E6X8ZluP22X}y21f=b1|J4j1{VeehMLKL`NTKx5_=#G0K@hQrvLx| From b6a6ec685de8eb1fbe5515d7ec0ff712cb426cdb Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Sat, 8 Apr 2023 14:29:33 +0300 Subject: [PATCH 10/15] Simplified the "IsWindowApprooved()" function. --- wCenterWindow/wCenterWindow.cpp | 45 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 0b2209b..4d143fa 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -19,15 +19,15 @@ WCHAR szTitle[MAX_LOADSTRING]; // Window's title WCHAR szClass[MAX_LOADSTRING]; // Window's class WCHAR szWinTitle[256]; WCHAR szWinClass[256]; -WCHAR szWinCore[] = L"Windows.UI.Core.CoreWindow"; -WCHAR szWorkerW[] = L"WorkerW"; +//WCHAR szWinCore[] = L"Windows.UI.Core.CoreWindow"; +//WCHAR szWorkerW[] = L"WorkerW"; HANDLE hHeap = NULL; HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles HICON hIcon = NULL; HMENU hMenu = NULL, hPopup = NULL; -HWND hWnd = NULL, hFgWnd = NULL, hTaskBar = NULL, hDesktop = NULL, hProgman = NULL; -bool bKPressed = FALSE, bMPressed = FALSE, bShowIcon = TRUE, bWorkArea = TRUE; -bool bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE; +HWND hWnd = NULL, hFgWnd = NULL; //, hTaskBar = NULL, hDesktop = NULL, hProgman = NULL; +BOOL bKPressed = FALSE, bMPressed = FALSE, bShowIcon = TRUE, bWorkArea = TRUE; +BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE; RECT rcFW = { 0 }; NOTIFYICONDATAW nid = { 0 }; @@ -42,7 +42,7 @@ static const GUID guid = { 0x2d7b7f30, 0x4b5f, 0x4380, { 0x98, 0x7, 0x57, 0xd7, // Forward declarations of functions included in this code module: VOID HandlingTrayIcon(); VOID ShowError(UINT); -bool IsWindowApprooved(HWND); +BOOL IsWindowApprooved(HWND); BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK KeyboardHookProc(int, WPARAM, LPARAM); @@ -157,9 +157,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd hHeap = GetProcessHeap(); szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, BUF_LEN); - hTaskBar = FindWindowW(L"Shell_TrayWnd", NULL); - hProgman = FindWindowW(L"Progman", NULL); - hDesktop = GetDesktopWindow(); + //hTaskBar = FindWindowW(L"Shell_TrayWnd", NULL); + //hProgman = FindWindowW(L"Progman", NULL); + //hDesktop = GetDesktopWindow(); MSG msg; BOOL bRet; @@ -331,8 +331,8 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { + OutputDebugStringA("Hook Fired!"); pkhs = (KBDLLHOOKSTRUCT*)lParam; - if (WM_KEYUP == wParam) { if (VK_LCONTROL == pkhs->vkCode) bLCTRL = FALSE; @@ -438,19 +438,18 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) return FALSE; } -bool IsWindowApprooved(HWND hFW) +BOOL IsWindowApprooved(HWND hFW) { diag_log("Entering IsWindowApprooved(), handle = 0x", hFW); bool bApprooved = FALSE; if (hFW) { - GetClassNameW(hFW, szWinClass, _countof(szWinClass)); + //GetClassNameW(hFW, szWinClass, _countof(szWinClass)); if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR))) diag_log("Title: '", ConvertWideToUtf8((LPWSTR)szBuffer), "'"); if (IsIconic(hFW)) diag_log("Window is iconic"); if (IsZoomed(hFW)) diag_log("Window is maximized"); - if ((wcscmp(szWinClass, szWinCore) != 0) && - (wcscmp(szWinClass, szWorkerW) != 0) && - (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman)) + LONG_PTR wlp = GetWindowLongPtr(hFW, GWL_STYLE); + if (wlp & WS_CAPTION) { if (!IsIconic(hFW) && !IsZoomed(hFW)) { @@ -459,7 +458,21 @@ bool IsWindowApprooved(HWND hFW) } else ShowError(IDS_ERR_MAXMIN); } - else diag_log("The window belongs to the Windows environment"); + else diag_log("The window has no caption"); + + //if ((wcscmp(szWinClass, szWinCore) != 0) && + // (wcscmp(szWinClass, szWorkerW) != 0) && + // (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman)) + //{ + // if (!IsIconic(hFW) && !IsZoomed(hFW)) + // { + // diag_log("Window is approved"); + // bApprooved = TRUE; + // } + // else ShowError(IDS_ERR_MAXMIN); + //} + //else diag_log("The window belongs to the Windows environment"); + } if (!bApprooved) diag_log("Window is not approved!"); diag_log("Quiting IsWindowApprooved()"); From 710d9d9d3e7c8e1b3e94619e0dc1692001dfe5b0 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Tue, 11 Apr 2023 11:56:46 +0300 Subject: [PATCH 11/15] Added LoadIconMetric() function to drawing better quality icon on HiDPI displays. --- Update_Version.ps1 | 36 ++++++++++++++++++++------------- pre-build.cmd | 3 --- wCenterWindow/wCenterWindow.cpp | 28 +++---------------------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/Update_Version.ps1 b/Update_Version.ps1 index 7e91af4..b8c72d9 100644 --- a/Update_Version.ps1 +++ b/Update_Version.ps1 @@ -1,4 +1,4 @@ -# Update Version v2.0 +# Update Version v2.1 # Required module: PSIni # Installation: Install-Module -Name PsIni @@ -36,8 +36,7 @@ function makeVersionString([string]$vmaj, [string]$vmin, [string]$vbld, [string] } } [string]$nstr = ($vmaj, $vmin, $vbld, $vrev) -join ',' - $res = @($vstr, $nstr) - return $res + return @($vstr, $nstr) } #region Initializing variables @@ -59,19 +58,20 @@ if (-not (Test-Path $iniFile)) { if (Test-Path ".\.git") { $isGit = $true [int]$gitCommitCount = [int]$gitRevCount = $null - [string]$gitRevDate = [string]$gitVerStr = $null + [string]$gitRevDate = [string]$gitVerStr = [string]$gitAHash = $null $gitCommitCount = $(git rev-list --count HEAD) $gitRevDate = $(git log -1 HEAD --date=rfc --pretty=format:%ad%n) $gitVerStr = $(git describe HEAD --long) if ($LastExitCode -eq 0) { $gitVerStr = $gitVerStr.Replace('-g', '-') $gitRevCount = $gitVerStr.Split('-')[-2] + $gitAHash = $gitVerStr.Split('-')[-1] } else { $gitVerStr = "" - $gitRevCount = $gitCommitCount + $gitRevCount = 0 + $gitAHash = $(git describe HEAD --always) } - } #region Reading values from INI file @@ -115,8 +115,15 @@ $verRevision = getValue $verRevision $vs = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[0] $vn = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[1] -if ([string]::IsNullOrEmpty($gitVerStr)) { $pnf = "$pn v$vs" } else { $pnf = "$pn $gitVerStr" } -if ($isGit) { $aboutBuild = "Git date: $gitRevDate" } else { $aboutBuild = $buildDateTime } +# if ([string]::IsNullOrEmpty($gitVerStr)) { $pnf = "$pn v$vs" } else { $pnf = "$pn $gitVerStr" } +if ($isGit) { + $aboutBuild = "Git date: $gitRevDate" + $pnf = "$pn v$vs ($gitAHash)" +} +else { + $aboutBuild = $buildDateTime + $pnf = "$pn v$vs" +} #region Save all variables to file "// $pn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode @@ -134,12 +141,13 @@ if ($isGit) { $aboutBuild = "Git date: $gitRevDate" } else { $aboutBuild = $buil "#define VERSION_NUM $vn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append # "#define SPAN_DAYS $spanDays" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append # "#define SPAN_SECS $spanSecs" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append -if ($isGit) { - "#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - # "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - # "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append - # "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append -} + +# if ($isGit) { +# # "#define GIT_VERSION_STR `"$gitVerStr`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# # "#define GIT_REV_DATE `"Git date: $gitRevDate`"" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# # "#define GIT_REV_COUNT $gitRevCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# # "#define GIT_COMMIT_COUNT $gitCommitCount" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append +# } #endregion #region Print out all variables diff --git a/pre-build.cmd b/pre-build.cmd index a5d6210..f063674 100644 --- a/pre-build.cmd +++ b/pre-build.cmd @@ -9,9 +9,6 @@ IF "%~2" == "" GOTO :no_args SET solutionDir=%1 SET projectDir=%2 -ECHO solutionDir: %solutionDir% -ECHO projectDir: %projectDir% - CD /D %solutionDir% powershell -ExecutionPolicy RemoteSigned -File Update_Version.ps1 MOVE /Y %solutionDir%VersionInfo.h %projectDir%VersionInfo.h diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 4d143fa..3d94e28 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -19,8 +19,6 @@ WCHAR szTitle[MAX_LOADSTRING]; // Window's title WCHAR szClass[MAX_LOADSTRING]; // Window's class WCHAR szWinTitle[256]; WCHAR szWinClass[256]; -//WCHAR szWinCore[] = L"Windows.UI.Core.CoreWindow"; -//WCHAR szWorkerW[] = L"WorkerW"; HANDLE hHeap = NULL; HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles HICON hIcon = NULL; @@ -122,6 +120,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd wcex.lpfnWndProc = WndProc; wcex.hInstance = hInstance; wcex.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_TRAYICON)); + LoadIconMetric(hInst, MAKEINTRESOURCE(IDI_TRAYICON), LIM_LARGE, &(wcex.hIcon)); wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW); wcex.lpszClassName = szClass; wcex.hIconSm = wcex.hIcon; @@ -157,10 +156,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd hHeap = GetProcessHeap(); szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, BUF_LEN); - //hTaskBar = FindWindowW(L"Shell_TrayWnd", NULL); - //hProgman = FindWindowW(L"Progman", NULL); - //hDesktop = GetDesktopWindow(); - MSG msg; BOOL bRet; @@ -227,9 +222,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) nid.hIcon = hIcon; nid.uID = IDI_TRAYICON; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - nid.dwInfoFlags = NIIF_NONE; - nid.dwState = NIS_HIDDEN; - nid.dwStateMask = NIS_HIDDEN; StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle); #ifndef _DEBUG @@ -331,7 +323,6 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { - OutputDebugStringA("Hook Fired!"); pkhs = (KBDLLHOOKSTRUCT*)lParam; if (WM_KEYUP == wParam) { @@ -444,7 +435,6 @@ BOOL IsWindowApprooved(HWND hFW) bool bApprooved = FALSE; if (hFW) { - //GetClassNameW(hFW, szWinClass, _countof(szWinClass)); if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR))) diag_log("Title: '", ConvertWideToUtf8((LPWSTR)szBuffer), "'"); if (IsIconic(hFW)) diag_log("Window is iconic"); if (IsZoomed(hFW)) diag_log("Window is maximized"); @@ -459,20 +449,6 @@ BOOL IsWindowApprooved(HWND hFW) else ShowError(IDS_ERR_MAXMIN); } else diag_log("The window has no caption"); - - //if ((wcscmp(szWinClass, szWinCore) != 0) && - // (wcscmp(szWinClass, szWorkerW) != 0) && - // (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman)) - //{ - // if (!IsIconic(hFW) && !IsZoomed(hFW)) - // { - // diag_log("Window is approved"); - // bApprooved = TRUE; - // } - // else ShowError(IDS_ERR_MAXMIN); - //} - //else diag_log("The window belongs to the Windows environment"); - } if (!bApprooved) diag_log("Window is not approved!"); diag_log("Quiting IsWindowApprooved()"); @@ -488,10 +464,12 @@ VOID HandlingTrayIcon() diag_log("Shell_NotifyIconW(NIM_ADD): ", bResult1); bool bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid); diag_log("Shell_NotifyIconW(NIM_SETVERSION): ", bResult2); + Shell_NotifyIconW(NIM_MODIFY, &nid); if (!bResult1 || !bResult2) { diag_log("Error creating trayicon!"); ShowError(IDS_ERR_ICON); + Shell_NotifyIconW(NIM_DELETE, &nid); bShowIcon = FALSE; } } From 582cce5b2067f7fd444789d2cd1b2c273c96560e Mon Sep 17 00:00:00 2001 From: W0LF Date: Tue, 11 Apr 2023 19:02:53 +0300 Subject: [PATCH 12/15] Changed Logger. --- wCenterWindow/Logger.cpp | 70 -------- wCenterWindow/Logger.h | 106 ++++++------ wCenterWindow/framework.h | 6 +- wCenterWindow/wCenterWindow.cpp | 173 +++++++++++--------- wCenterWindow/wCenterWindow.vcxproj | 3 +- wCenterWindow/wCenterWindow.vcxproj.filters | 5 +- 6 files changed, 166 insertions(+), 197 deletions(-) delete mode 100644 wCenterWindow/Logger.cpp diff --git a/wCenterWindow/Logger.cpp b/wCenterWindow/Logger.cpp deleted file mode 100644 index bbcabeb..0000000 --- a/wCenterWindow/Logger.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// wCenterWindow -// Logger.cpp -// -#include "framework.h" - -#define TS_LEN 30 - -std::ofstream logfile; -extern WCHAR szTitle[]; -extern LPVOID szBuffer; - -std::string GetTimeStamp() -{ - SYSTEMTIME lt; - GetLocalTime(<); - CHAR ts[TS_LEN]; - StringCchPrintfA(ts, TS_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d - ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds); - return ts; -} - -void OpenLogFile() -{ - WCHAR lpszPath[MAX_PATH + 1] = { 0 }; - DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, MAX_PATH); - DWORD dwError = GetLastError(); - if (ERROR_INSUFFICIENT_BUFFER == dwError) - { - MessageBoxW(NULL, L"Path to logfile is too long! Working without logging", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING); - return; - } - if (NULL == dwPathLength) - { - MessageBoxW(NULL, L"Can't get module filename! Working without logging", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING); - return; - } - - std::filesystem::path log_path = lpszPath; - log_path.replace_extension(L".log"); - std::filesystem::path bak_path = log_path; - bak_path.replace_extension(L".bak"); - - if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path); - -#ifdef _DEBUG - log_path = L"d:\\test.log"; -#endif - - logfile.open(log_path); - if (logfile.is_open()) - { - logfile << std::boolalpha; - diag_log("Start logging"); - diag_log("Logfile: ", log_path); - diag_log("Logfile was successfully opened"); - } - else - { - MessageBoxW(NULL, L"Can't open logfile! Working without logging", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING); - } - return; -} - -void CloseLogFile() -{ - if (logfile) - { - diag_log("End logging"); - logfile.close(); - } -} diff --git a/wCenterWindow/Logger.h b/wCenterWindow/Logger.h index 8d15d2f..f427fba 100644 --- a/wCenterWindow/Logger.h +++ b/wCenterWindow/Logger.h @@ -1,59 +1,71 @@ -// wCenterWindow -// Logger.h -// +// wLogger v3.0 (Edited version from RBTray project [https://github.com/benbuck/rbtray]) +// logger.h +// Usage: LOG_TO_FILE(L"%s(%d): Log message", TEXT(__FUNCTION__), __LINE__); #pragma once #include "framework.h" -extern std::ofstream logfile; -std::string GetTimeStamp(); +#define DBUFLEN 256 +#define LOG_TO_FILE(fmt, ...) do { StringCchPrintfW(debugBuffer, DBUFLEN, fmt, ##__VA_ARGS__); logfile << GetTimeStamp() << debugBuffer << std::endl; } while (0) -template -void diag_log(T1 arg1) +SYSTEMTIME lt; +wchar_t debugTimeBuffer[32]; +wchar_t debugBuffer[DBUFLEN]; +std::wofstream logfile; + +extern wchar_t szTitle[]; + +wchar_t* GetTimeStamp() { - logfile << GetTimeStamp() << arg1 << std::endl; + GetLocalTime(<); + StringCchPrintfW(debugTimeBuffer, 32, L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds); + return debugTimeBuffer; } -template -void diag_log(T1 arg1, T2 arg2) +void OpenLogFile() { - logfile << GetTimeStamp() << arg1 << arg2 << std::endl; + WCHAR lpszPath[MAX_PATH + 1] = { 0 }; + DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, MAX_PATH); + DWORD dwError = GetLastError(); + if (ERROR_INSUFFICIENT_BUFFER == dwError) + { + MessageBoxW(NULL, L"Path to logfile is too long! Working without logging", szTitle, MB_OK | MB_ICONWARNING); + return; + } + if (NULL == dwPathLength) + { + MessageBoxW(NULL, L"Can't get module filename! Working without logging", szTitle, MB_OK | MB_ICONWARNING); + return; + } + + std::filesystem::path log_path = lpszPath; + log_path.replace_extension(L".log"); + std::filesystem::path bak_path = log_path; + bak_path.replace_extension(L".bak"); + + if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path); +#ifdef _DEBUG + log_path = L"D:\\test.log"; +#endif + logfile.open(log_path, std::ios::trunc); + if (logfile.is_open()) + { + logfile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM + logfile.imbue(std::locale("en-US.utf8")); + logfile << GetTimeStamp() << "[ " << szTitle << " ] Start log." << std::endl; + logfile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl; + } + else + { + MessageBoxW(NULL, L"Can't open logfile! Working without logging", szTitle, MB_OK | MB_ICONWARNING); + } + return; } -template -void diag_log(T1 arg1, T2 arg2, T3 arg3) +void CloseLogFile() { - logfile << GetTimeStamp() << arg1 << arg2 << arg3 << std::endl; + if (logfile) + { + logfile << GetTimeStamp() << "[ " << szTitle << " ] Stop log." << std::endl; + logfile.close(); + } } - -template -void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4) -{ - logfile << GetTimeStamp() << arg1 << arg2 << arg3 << arg4 << std::endl; -} - -template -void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) -{ - logfile << GetTimeStamp() << arg1 << arg2 << arg3 << arg4 << arg5 << std::endl; -} - -template -void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) -{ - logfile << GetTimeStamp() << arg1 << arg2 << arg3 << arg4 << arg5 << arg6 << std::endl; -} - -template -void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) -{ - logfile << GetTimeStamp() << arg1 << arg2 << arg3 << arg4 << arg5 << arg6 << arg7 << std::endl; -} - -template -void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) -{ - logfile << GetTimeStamp() << arg1 << arg2 << arg3 << arg4 << arg5 << arg6 << arg7 << arg8 << std::endl; -} - -void OpenLogFile(); -void CloseLogFile(); diff --git a/wCenterWindow/framework.h b/wCenterWindow/framework.h index 80b8a6e..9da34e8 100644 --- a/wCenterWindow/framework.h +++ b/wCenterWindow/framework.h @@ -15,5 +15,9 @@ #include // Project Specific Header Files -#include "Logger.h" +#include "logger.h" #include "VersionInfo.h" + +// Extern variables +#define MAX_LOADSTRING 50 +WCHAR szTitle[MAX_LOADSTRING]; // wCenterWindow's title diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 3d94e28..333934f 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -2,6 +2,7 @@ // wCenterWindow.cpp // #include "framework.h" +#include "logger.h" #include "wCenterWindow.h" #define NO_DONATION @@ -10,12 +11,11 @@ #define KEY_V 0x56 #define BUF_LEN 1024 -#define MAX_LOADSTRING 50 #define WM_WCW 0x8F00 // Global variables: HINSTANCE hInst; // Instance -WCHAR szTitle[MAX_LOADSTRING]; // Window's title +extern WCHAR szTitle[]; WCHAR szClass[MAX_LOADSTRING]; // Window's class WCHAR szWinTitle[256]; WCHAR szWinClass[256]; @@ -23,7 +23,7 @@ HANDLE hHeap = NULL; HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles HICON hIcon = NULL; HMENU hMenu = NULL, hPopup = NULL; -HWND hWnd = NULL, hFgWnd = NULL; //, hTaskBar = NULL, hDesktop = NULL, hProgman = NULL; +HWND hWnd = NULL, hFgWnd = NULL; BOOL bKPressed = FALSE, bMPressed = FALSE, bShowIcon = TRUE, bWorkArea = TRUE; BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE; @@ -46,20 +46,17 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK KeyboardHookProc(int, WPARAM, LPARAM); LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); -std::string ConvertWideToUtf8(const std::wstring&); - - VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) { - diag_log("Entering MoveWindowToMonitorCenter(), handle = 0x", hwnd); + LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__)); RECT fgwrc = { 0 }; GetWindowRect(hwnd, &fgwrc); LONG nWidth = fgwrc.right - fgwrc.left; LONG nHeight = fgwrc.bottom - fgwrc.top; - diag_log("Moving window from x = ", fgwrc.left, ", y = ", fgwrc.top); + LOG_TO_FILE(L"%s(%d): Moving the window from %d, %d", TEXT(__FUNCTION__), __LINE__, fgwrc.left, fgwrc.top); MONITORINFO mi = { 0 }; mi.cbSize = sizeof(MONITORINFO); @@ -93,12 +90,10 @@ VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) MoveWindow(hwnd, x, y, nWidth, nHeight, TRUE); SendMessageW(hwnd, WM_EXITSIZEMOVE, NULL, NULL); - diag_log("Moving window to x = ", x, ", y = ", y); - diag_log("Quiting MoveWindowToMonitorCenter()"); + LOG_TO_FILE(L"%s(%d): Moving the window to %d, %d", TEXT(__FUNCTION__), __LINE__, x, y); + LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); } - - int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { hInst = hInstance; @@ -113,7 +108,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd } OpenLogFile(); - diag_log("Entering WinMain()"); + LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__)); WNDCLASSEX wcex = { 0 }; wcex.cbSize = sizeof(WNDCLASSEX); @@ -140,13 +135,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd int nArgs = 0; LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); - std::string arg; - - diag_log("Arguments: ", nArgs - 1); + LOG_TO_FILE(L"Arguments count: %d", nArgs - 1); for (int i = 1; i < nArgs; i++) { - arg = ConvertWideToUtf8(szArglist[i]); - diag_log("Argument #", i, ": ", arg); + LOG_TO_FILE(L"Argument %d: %s", i, szArglist[i]); } (nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], L"/hide")) ? bShowIcon = FALSE : bShowIcon = TRUE; @@ -178,7 +170,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd if (hMenu) DestroyMenu(hMenu); Shell_NotifyIconW(NIM_DELETE, &nid); - diag_log("Quiting WinMain(), msg.wParam = ", (int)msg.wParam); + LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam); CloseLogFile(); HeapFree(hHeap, NULL, szBuffer); @@ -191,24 +183,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { case WM_CREATE: { - diag_log("Recived WM_CREATE message"); + LOG_TO_FILE(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__); + hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU)); if (!hMenu) { - diag_log("Loading context menu failed!"); + LOG_TO_FILE(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__); ShowError(IDS_ERR_MENU); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } - diag_log("Context menu successfully loaded"); + LOG_TO_FILE(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__); hPopup = GetSubMenu(hMenu, 0); if (!hPopup) { - diag_log("Creating popup menu failed!"); + LOG_TO_FILE(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__); ShowError(IDS_ERR_POPUP); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } - diag_log("Popup menu successfully created"); + LOG_TO_FILE(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STATE; @@ -228,67 +221,69 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL); if (!hMouseHook) { - diag_log("Creating mouse hook failed!"); + LOG_TO_FILE(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__); ShowError(IDS_ERR_HOOK); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } - diag_log("Mouse hook was successfully set"); + LOG_TO_FILE(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__); #endif // !_DEBUG hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); if (!hKbdHook) { - diag_log("Creating keyboard hook failed!"); + LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__); ShowError(IDS_ERR_HOOK); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } - diag_log("Keyboard hook was successfully set"); + LOG_TO_FILE(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__); break; } - case WM_WCW: + case WM_WCW: // Popup menu handler { if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam)) { - diag_log("Entering menu handler"); + LOG_TO_FILE(L"%s(%d): Entering the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__); + SetForegroundWindow(hWnd); POINT pt; GetCursorPos(&pt); int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL); if (ID_POPUPMENU_ICON == idMenu) { - diag_log("Pressed 'Hide icon' menuitem"); + LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__); bShowIcon = FALSE; HandlingTrayIcon(); } if (ID_POPUPMENU_AREA == idMenu) { - diag_log("Pressed 'Use workarea' menuitem"); + LOG_TO_FILE(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__); bWorkArea = !bWorkArea; bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); - diag_log("Changed 'Use workarea' option to ", bWorkArea); + LOG_TO_FILE(L"%s(%d): Changed 'Use workarea' option to %s", TEXT(__FUNCTION__), __LINE__, bWorkArea ? L"True" : L"False"); } if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed) { - diag_log("Pressed 'About' menuitem"); + LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__); bKPressed = TRUE; DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); bKPressed = FALSE; } if (ID_POPUPMENU_EXIT == idMenu) { - diag_log("Pressed 'Exit' menuitem"); + LOG_TO_FILE(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } - diag_log("Quiting menu handler"); + + LOG_TO_FILE(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__); } break; } case WM_QUERYENDSESSION: { - diag_log("Recieved WM_QUERYENDSESSION message, lParam = ", lParam); + LOG_TO_FILE(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)lParam); CloseLogFile(); return TRUE; break; @@ -296,7 +291,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: { - diag_log("Recived WM_DESTROY message"); + LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__); PostQuitMessage(0); break; } @@ -312,7 +307,7 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (WM_MBUTTONUP == wParam) bMPressed = FALSE; if (WM_MBUTTONDOWN == wParam && bLCTRL && bLWIN && !bMPressed) { - diag_log("Pressed LCTRL + LWIN + MMB"); + LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__); bMPressed = TRUE; hFgWnd = GetForegroundWindow(); if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); @@ -338,7 +333,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key { - diag_log("Pressed LCTRL + LWIN + I"); + LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__); bKPressed = TRUE; bShowIcon = !bShowIcon; HandlingTrayIcon(); @@ -347,7 +342,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key { - diag_log("Pressed LCTRL + LWIN + C"); + LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__); bKPressed = TRUE; hFgWnd = GetForegroundWindow(); if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); @@ -357,12 +352,12 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key { - diag_log("Pressed LCTRL + LWIN + V"); + LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__); bKPressed = TRUE; bKEYV = TRUE; hFgWnd = GetForegroundWindow(); if (IsWindowApprooved(hFgWnd)) { - diag_log("Opening 'Manual editing' dialog"); + LOG_TO_FILE(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc); SetForegroundWindow(hFgWnd); } @@ -381,7 +376,8 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) { case WM_INITDIALOG: { - diag_log("Initializing 'Manual editing' dialog"); + LOG_TO_FILE(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); + SetWindowTextW(hDlg, szTitle); GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle)); GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass)); @@ -405,7 +401,8 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) { case IDC_BUTTON_SET: { - diag_log("Pressed 'Set' button"); + LOG_TO_FILE(L"%s(%d): Pressed the 'Set' button", TEXT(__FUNCTION__), __LINE__); + x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE); y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE); w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE); @@ -413,14 +410,16 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL); MoveWindow(hFgWnd, x, y, w, h, TRUE); SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); - diag_log("Window with handle 0x", hFgWnd, " was moved to x = ", x, ", y = ", y); + + LOG_TO_FILE(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y); return TRUE; break; } case IDCANCEL: case IDC_BUTTON_CLOSE: { - diag_log("Closing 'Manual editing' dialog"); + LOG_TO_FILE(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); + EndDialog(hDlg, LOWORD(wParam)); break; } @@ -431,53 +430,82 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) BOOL IsWindowApprooved(HWND hFW) { - diag_log("Entering IsWindowApprooved(), handle = 0x", hFW); + LOG_TO_FILE(L"Entering the %s() function, handle = 0x%08X", TEXT(__FUNCTION__), hFW); + bool bApprooved = FALSE; if (hFW) { - if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR))) diag_log("Title: '", ConvertWideToUtf8((LPWSTR)szBuffer), "'"); - if (IsIconic(hFW)) diag_log("Window is iconic"); - if (IsZoomed(hFW)) diag_log("Window is maximized"); - LONG_PTR wlp = GetWindowLongPtr(hFW, GWL_STYLE); + if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR))) + { + LOG_TO_FILE(L"%s(%d): Window title: '%s'", TEXT(__FUNCTION__), __LINE__, (LPWSTR)szBuffer); + } + + if (IsIconic(hFW)) + { + LOG_TO_FILE(L"%s(%d): The window is iconified", TEXT(__FUNCTION__), __LINE__); + } + + if (IsZoomed(hFW)) + { + LOG_TO_FILE(L"%s(%d): The window is maximized", TEXT(__FUNCTION__), __LINE__); + } + + LONG_PTR wlp = GetWindowLongPtrW(hFW, GWL_STYLE); if (wlp & WS_CAPTION) { if (!IsIconic(hFW) && !IsZoomed(hFW)) { - diag_log("Window is approved"); + LOG_TO_FILE(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__); bApprooved = TRUE; } else ShowError(IDS_ERR_MAXMIN); } - else diag_log("The window has no caption"); + else + { + LOG_TO_FILE(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__); + } } - if (!bApprooved) diag_log("Window is not approved!"); - diag_log("Quiting IsWindowApprooved()"); + + if (!bApprooved) + { + LOG_TO_FILE(L"%s(%d): The window is not approved!", TEXT(__FUNCTION__), __LINE__); + } + + LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); return bApprooved; } VOID HandlingTrayIcon() { - diag_log("Entering HandlingTrayIcon(), bShowIcon = ", bShowIcon); + LOG_TO_FILE(L"Entering the %s() function, bShowIcon = %s", TEXT(__FUNCTION__), bShowIcon ? L"True" : L"False"); + if (bShowIcon) { bool bResult1 = Shell_NotifyIconW(NIM_ADD, &nid); - diag_log("Shell_NotifyIconW(NIM_ADD): ", bResult1); + LOG_TO_FILE(L"%s(%d): Shell_NotifyIconW(NIM_ADD): %s", TEXT(__FUNCTION__), __LINE__, bResult1 ? L"True" : L"False"); + bool bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid); - diag_log("Shell_NotifyIconW(NIM_SETVERSION): ", bResult2); - Shell_NotifyIconW(NIM_MODIFY, &nid); + LOG_TO_FILE(L"%s(%d): Shell_NotifyIconW(NIM_SETVERSION): %s", TEXT(__FUNCTION__), __LINE__, bResult2 ? L"True" : L"False"); + if (!bResult1 || !bResult2) { - diag_log("Error creating trayicon!"); + LOG_TO_FILE(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__); + ShowError(IDS_ERR_ICON); Shell_NotifyIconW(NIM_DELETE, &nid); bShowIcon = FALSE; } + else + { + Shell_NotifyIconW(NIM_MODIFY, &nid); + } } else { Shell_NotifyIconW(NIM_DELETE, &nid); } - diag_log("Quiting HandlingTrayIcon()"); + + LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); } VOID ShowError(UINT uID) @@ -498,7 +526,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { case WM_INITDIALOG: { - diag_log("Initializing 'About' dialog"); + LOG_TO_FILE(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__); WCHAR szAboutProgName[MAX_LOADSTRING]; WCHAR szAboutCopyright[MAX_LOADSTRING]; @@ -516,6 +544,9 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) HWND hLink = GetDlgItem(hDlg, IDC_DONATIONLINK); if (hLink) DestroyWindow(hLink); #endif // !NO_DONATION + + LOG_TO_FILE(L"%s(%d): End of initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__); + return (INT_PTR)TRUE; break; } @@ -528,7 +559,9 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) PNMLINK pNMLink = (PNMLINK)pNMHdr; LITEM item = pNMLink->item; ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); - diag_log("Pressed donation link"); + + LOG_TO_FILE(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__); + return (INT_PTR)TRUE; } break; @@ -539,7 +572,9 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) if (IDOK == LOWORD(wParam) || IDCANCEL == LOWORD(wParam)) { EndDialog(hDlg, LOWORD(wParam)); - diag_log("Closing 'About' dialog"); + + LOG_TO_FILE(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__); + return (INT_PTR)TRUE; } break; @@ -547,11 +582,3 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } return (INT_PTR)FALSE; } - -std::string ConvertWideToUtf8(const std::wstring& wstr) -{ - int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL); - std::string str(count, 0); - WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL); - return str; -} diff --git a/wCenterWindow/wCenterWindow.vcxproj b/wCenterWindow/wCenterWindow.vcxproj index 55588b8..266f294 100644 --- a/wCenterWindow/wCenterWindow.vcxproj +++ b/wCenterWindow/wCenterWindow.vcxproj @@ -187,13 +187,12 @@ - + - diff --git a/wCenterWindow/wCenterWindow.vcxproj.filters b/wCenterWindow/wCenterWindow.vcxproj.filters index 8b73153..47aa13c 100644 --- a/wCenterWindow/wCenterWindow.vcxproj.filters +++ b/wCenterWindow/wCenterWindow.vcxproj.filters @@ -27,7 +27,7 @@ Header Files - + Header Files @@ -35,9 +35,6 @@ Source Files - - Source Files - From bf609d3c08f672743b1092dfe125e1e7b77dadb5 Mon Sep 17 00:00:00 2001 From: W0LF Date: Wed, 12 Apr 2023 07:35:29 +0300 Subject: [PATCH 13/15] Added DestroyIcon() function. --- wCenterWindow/wCenterWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 333934f..7f3e872 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -169,6 +169,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd if (hKbdHook) UnhookWindowsHookEx(hKbdHook); if (hMenu) DestroyMenu(hMenu); Shell_NotifyIconW(NIM_DELETE, &nid); + DestroyIcon(hIcon); LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam); CloseLogFile(); From 90b281d3a539698712973128e8f9ce84532b6961 Mon Sep 17 00:00:00 2001 From: W0LF Date: Wed, 12 Apr 2023 08:54:30 +0300 Subject: [PATCH 14/15] Changed control for help text from static to EditText. --- wCenterWindow/Logger.h | 2 +- wCenterWindow/resource.h | 3 ++- wCenterWindow/wCenterWindow.cpp | 22 +++++++++++++++++++++- wCenterWindow/wCenterWindow.rc | Bin 12954 -> 13152 bytes 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/wCenterWindow/Logger.h b/wCenterWindow/Logger.h index f427fba..d51aa14 100644 --- a/wCenterWindow/Logger.h +++ b/wCenterWindow/Logger.h @@ -1,4 +1,4 @@ -// wLogger v3.0 (Edited version from RBTray project [https://github.com/benbuck/rbtray]) +// wLogger v3.1 (Edited version from RBTray project [https://github.com/benbuck/rbtray]) // logger.h // Usage: LOG_TO_FILE(L"%s(%d): Log message", TEXT(__FUNCTION__), __LINE__); #pragma once diff --git a/wCenterWindow/resource.h b/wCenterWindow/resource.h index 7b7b5c1..541fa76 100644 --- a/wCenterWindow/resource.h +++ b/wCenterWindow/resource.h @@ -36,6 +36,7 @@ #define IDC_ABOUT_PROGNAME 1010 #define IDC_ABOUT_COPYRIGHT 1011 #define IDC_ABOUT_BUILDTIME 1012 +#define IDC_ABOUTEDIT 1013 #define IDC_STATIC -1 // Next default values for new objects @@ -45,7 +46,7 @@ #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 130 #define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1013 +#define _APS_NEXT_CONTROL_VALUE 1014 #define _APS_NEXT_SYMED_VALUE 122 #endif #endif diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index 7f3e872..b2a0ce1 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -108,6 +108,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd } OpenLogFile(); + LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__)); WNDCLASSEX wcex = { 0 }; @@ -135,7 +136,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd int nArgs = 0; LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); + LOG_TO_FILE(L"Arguments count: %d", nArgs - 1); + for (int i = 1; i < nArgs; i++) { LOG_TO_FILE(L"Argument %d: %s", i, szArglist[i]); @@ -172,6 +175,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd DestroyIcon(hIcon); LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam); + CloseLogFile(); HeapFree(hHeap, NULL, szBuffer); @@ -223,6 +227,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (!hMouseHook) { LOG_TO_FILE(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__); + ShowError(IDS_ERR_HOOK); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } @@ -233,6 +238,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (!hKbdHook) { LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__); + ShowError(IDS_ERR_HOOK); PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } @@ -253,12 +259,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (ID_POPUPMENU_ICON == idMenu) { LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__); + bShowIcon = FALSE; HandlingTrayIcon(); } if (ID_POPUPMENU_AREA == idMenu) { LOG_TO_FILE(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__); + bWorkArea = !bWorkArea; bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); @@ -267,6 +275,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed) { LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__); + bKPressed = TRUE; DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); bKPressed = FALSE; @@ -274,6 +283,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (ID_POPUPMENU_EXIT == idMenu) { LOG_TO_FILE(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__); + PostMessageW(hWnd, WM_CLOSE, NULL, NULL); } @@ -285,6 +295,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_QUERYENDSESSION: { LOG_TO_FILE(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)lParam); + CloseLogFile(); return TRUE; break; @@ -293,6 +304,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: { LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__); + PostQuitMessage(0); break; } @@ -309,6 +321,7 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (WM_MBUTTONDOWN == wParam && bLCTRL && bLWIN && !bMPressed) { LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__); + bMPressed = TRUE; hFgWnd = GetForegroundWindow(); if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); @@ -335,6 +348,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key { LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__); + bKPressed = TRUE; bShowIcon = !bShowIcon; HandlingTrayIcon(); @@ -344,6 +358,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key { LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__); + bKPressed = TRUE; hFgWnd = GetForegroundWindow(); if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); @@ -354,11 +369,13 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key { LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__); + bKPressed = TRUE; bKEYV = TRUE; hFgWnd = GetForegroundWindow(); if (IsWindowApprooved(hFgWnd)) { LOG_TO_FILE(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); + DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc); SetForegroundWindow(hFgWnd); } @@ -413,6 +430,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); LOG_TO_FILE(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y); + return TRUE; break; } @@ -457,6 +475,7 @@ BOOL IsWindowApprooved(HWND hFW) if (!IsIconic(hFW) && !IsZoomed(hFW)) { LOG_TO_FILE(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__); + bApprooved = TRUE; } else ShowError(IDS_ERR_MAXMIN); @@ -473,6 +492,7 @@ BOOL IsWindowApprooved(HWND hFW) } LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); + return bApprooved; } @@ -540,7 +560,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetDlgItemTextW(hDlg, IDC_ABOUT_PROGNAME, szAboutProgName); SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright); SetDlgItemTextW(hDlg, IDC_ABOUT_BUILDTIME, szAboutBuildTime); - SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAboutHelp); + SetDlgItemTextW(hDlg, IDC_ABOUTEDIT, szAboutHelp); #ifdef NO_DONATION HWND hLink = GetDlgItem(hDlg, IDC_DONATIONLINK); if (hLink) DestroyWindow(hLink); diff --git a/wCenterWindow/wCenterWindow.rc b/wCenterWindow/wCenterWindow.rc index e752b58cfb0ed11e73c3b6cdd52ea5d43a081639..d2ebf4328d104740cbcc7fbe72f08f363f779f10 100644 GIT binary patch delta 269 zcmbQ0`XFsXlF(!e;X9M(2+f&%OZdj*M`9V1WwLlDqB zA0SjuQd6J vh|}h6;?wv!ix^@U@_@K#vakA7B;I57MkHRU#!Lin^M4ItMkKDVRyzj(RysbM delta 155 zcmaEmHY;^QlF;ONVoH<$2un=16P`0UN$AdG5s`V5yZDtR3rRR_RuMbHIC+yu#$+9! zqAy$mrk)Hg49*Pk42}#=4E_wE3?U3246Y153;_%}42BFwK+=@K1V|b)7yuzi%z(jS wv%kb_e%3sO7>2yb6V(+bOK21@0$Cc3U{Z9lfo2P1-sZiU!i+%brdB%#0I`fJRR910 From 1dd9883f42c38fc0d24a6895ee73857d4c564521 Mon Sep 17 00:00:00 2001 From: W0LF Date: Wed, 12 Apr 2023 09:13:46 +0300 Subject: [PATCH 15/15] Release v2.3.5 --- Version.ini | Bin 998 -> 998 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Version.ini b/Version.ini index 204fc66586c2b6ae0b5849a8473db05a4ac7cc0a..5fdfc1ad143b5b8ebdb921afe1a199d7a329584b 100644 GIT binary patch delta 14 VcmaFH{)~M?855)F=5nTdMgS_U1l0fl delta 14 VcmaFH{)~M?855()=5nTdMgS_O1k?Zk