8 Commits

Author SHA1 Message Date
ba18587c31 Increased revision. 2022-02-21 17:02:41 +03:00
c6d9f908e5 Fixed donation link. 2022-02-21 16:47:48 +03:00
8fbd6f1bde Cleanup code.
Changed main "ghost" window to a message-only window.
2022-02-21 16:44:06 +03:00
7c73a52f0a Fixed mistake not getting focus when calling manual edit window 2022-02-21 16:10:11 +03:00
05c4ad977b Revert "Fixed warnings"
This reverts commit 7cd58a9a15.
2022-02-21 16:02:40 +03:00
c968b47baf Revert "Added SetForegroundWindow() into WM_INITDIALOG"
This reverts commit 6f6ce164ee.
2022-02-21 16:02:28 +03:00
6f6ce164ee Added SetForegroundWindow() into WM_INITDIALOG 2022-02-19 23:59:24 +03:00
7cd58a9a15 Fixed warnings 2022-02-19 23:12:26 +03:00
26 changed files with 690 additions and 2339 deletions

5
.gitignore vendored
View File

@@ -6,7 +6,6 @@
*.user *.user
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
[Vv]ersion.h
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs
@@ -437,7 +436,3 @@ lightgbm.Rcheck/
# GraphViz artifacts # GraphViz artifacts
*.gv *.gv
*.gv.* *.gv.*
/wCenterWindow/VersionInfo.h
[Pp]atches/
*.patch

21
LICENSE
View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2020-2024 Vladislav Salikov aka W0LF
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,34 +1,12 @@
## wCenterWindow # wCenterWindow
This program centers the current active window by a ```LCTRL + LWIN + C``` hotkey,
or pressing ```LCTRL + LWIN + MMB``` (Middle Mouse Button).
Copyright (c) 2020-2024 Vladislav Salikov aka W0LF.<br> ```LCTRL + LWIN + V``` - manual editing of size and position of the window.
Program icon made by Kirill Topov.
--- You can use ```LCTRL + LWIN + I``` hotkey for hide/show trayicon.
You can also use commandline option ```/hide``` for hide trayicon at startup.
This program centers the current active window by a `LCTRL + LWIN + C` hotkey, or pressing `LCTRL + LWIN + MMB` (Middle Mouse Button). ```Use workarea``` option means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used.
`LCTRL + LWIN + V` - manual editing of size and position of the window. If some windows does not centers you should run wCenterWindow with administrative rights.
`LCTRL + LWIN + I` hotkey is used to hide/show trayicon.
You can also use commandline option `/hide` to hide trayicon at startup.
The `/noupdate` commandline option is used to disable check for updates. By default, the program checks for updates upon startup and once a day.
The `Use workarea` option (at popup menu) means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used.
If some windows does not centers, you should run wCenterWindow with administrative rights.
## Automatic startup
Usually, to start the application when Windows starts, it is enough to put the application's shortcut in the "Startup" folder -
"C:\Users\\<*Your user name*>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup".
(The easiest way to get there - press 'WIN + R' and type `shell:startup`).<br>
However, in this case wCenterWindow will not be able to work with windows that are open with elevated privileges.
And if you enable the "Run as administrator" option in the shortcut, then wCenterWindow will not start. This is related to the security of Windows (maybe only in 10/11, I did not check).
This behavior can be bypassed by creating a task in the Task Scheduler with the "Run with highest privileges" option.<br>
**Note:** If you run wCenterWindow via the Task Scheduler, I highly recommend enabling the "Delay task for" option for 15-30 seconds, otherwise you may get an error message "Can't create tray icon".
## License
This software is licensed under a [MIT License](https://mit-license.org).<br>
This software uses the [PicoJSON](https://github.com/kazuho/picojson) - a C++ JSON parser / serializer by Kazuho Oku.

View File

@@ -1,177 +0,0 @@
# Update Version v2.1
# Required module: PSIni
# Installation: Install-Module -Name PsIni
$date = Get-Date
function addLeadingZero([int]$nvar) {
[string]$svar = $null
if ($nvar -lt 10) { $svar = '0' + $nvar.ToString() }
else { $svar = $nvar.ToString() }
return $svar
}
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
}
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 ','
return @($vstr, $nstr)
}
#region Initializing variables
[string]$verMajor = [string]$verMinor = [string]$verBuild = [string]$verPatch = $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]$platformArch = $args[0]
[string]$iniFile = ".\Version.ini"
#endregion
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 = [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 = 0
$gitAHash = $(git describe HEAD --always)
}
}
#region Reading values from INI file
$config = $null
$config = (Get-IniContent -FilePath $iniFile)["Config"]
$verMajor = $config.Major
$verMinor = $config.Minor
$verBuild = $config.Build
$verPatch = $config.Patch
$pys = $config.ProductYearStart
$pn = $config.ProductName
$pa = $config.ProductAutors
$pd = $config.ProductDescription
#endregion
if ($verMajor -eq "") {
Write-Error "Major version cannot be empty!"
# Start-Sleep -Seconds 3
exit 2
}
#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 $pa" } else { $pcf = "Copyright (c) $pys-$currentYear $pa" }
$intName = "$pn-$platformArch-C++"
$origName = "$pn.exe"
$verMajor = getValue $verMajor
$verMinor = getValue $verMinor
$verBuild = getValue $verBuild
$verPatch = getValue $verPatch
#endregion
$vs = (makeVersionString $verMajor $verMinor $verBuild $verPatch)[0]
$vn = (makeVersionString $verMajor $verMinor $verBuild $verPatch)[1]
# 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"
}
$pnf = "$pn v$vs ($platformArch)"
#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
# 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 " verPatch: [$verPatch]"
# echo ""
# echo " aboutBuild: [$aboutBuild]"
# echo " platformArch: [$platformArch]"
# 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

Binary file not shown.

View File

@@ -1,25 +0,0 @@
@ECHO OFF
:: In VisualStudio add to Pre-Build events:
:: "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"
:: Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives'
REM In VisualStudio add to Pre-Build events:
REM "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"
REM Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives'
IF "%~1" == "" GOTO :no_args
IF "%~2" == "" GOTO :no_args
IF "%~3" == "" GOTO :no_args
SET solutionDir=%1
SET projectDir=%2
SET platformArch=%3
CD /D %solutionDir%
powershell -ExecutionPolicy RemoteSigned -File Update_Version.ps1 %platformArch%
MOVE /Y %solutionDir%VersionInfo.h %projectDir%VersionInfo.h
EXIT
:no_args
ECHO Not enough arguments!
EXIT 1

View File

@@ -1,15 +1,10 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 16
VisualStudioVersion = 17.5.33516.290 VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWindow\wCenterWindow.vcxproj", "{F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWindow\wCenterWindow.vcxproj", "{F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B4FD1E-DC1B-46A4-842C-5130F09EFCB5}"
ProjectSection(SolutionItems) = preProject
Version.ini = Version.ini
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64

View File

@@ -1,74 +0,0 @@
// wCenterWindow
// CLogger.cpp
#include "CLogger.h"
#include <string>
#include <filesystem>
#include <strsafe.h>
inline wchar_t* CLogger::GetTimeStamp() {
GetLocalTime(&lt);
StringCchPrintfW(logTimeBuffer, _countof(logTimeBuffer), L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
return logTimeBuffer;
}
void CLogger::Out(const wchar_t* fmt, ...) {
if (fsLogFile.is_open()) {
va_list args;
va_start(args, fmt);
EnterCriticalSection(&cs);
StringCchVPrintfW(logBuffer, _countof(logBuffer), fmt, args);
va_end(args);
fsLogFile << GetTimeStamp() << logBuffer << std::endl;
LeaveCriticalSection(&cs);
}
}
void CLogger::Init() {
wchar_t szPath[MAX_PATH] = { 0 };
DWORD dwPathLength = GetModuleFileNameW(NULL, szPath, MAX_PATH);
DWORD dwError = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == dwError) {
MessageBoxW(NULL, L"Warning!\nPath to log file is too long! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
return;
}
if (NULL == dwPathLength) {
MessageBoxW(NULL, L"Warning!\nCan't get application's filename! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
return;
}
std::filesystem::path log_path = szPath;
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
fsLogFile.open(log_path, std::ios::trunc);
if (fsLogFile.is_open()) {
InitializeCriticalSection(&cs);
fsLogFile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
fsLogFile.imbue(std::locale("en-US.utf8"));
fsLogFile << GetTimeStamp() << "[ " << szAppTitleVer.c_str() << " ] Start log." << std::endl;
fsLogFile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
}
else {
MessageBoxW(NULL, L"Warning!\nCan't create log file! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
}
}
CLogger::CLogger(const wchar_t* _appTitle) {
szAppTitle = _appTitle;
szAppTitleVer = _appTitle;
Init();
}
CLogger::~CLogger() {
if (fsLogFile) {
fsLogFile << GetTimeStamp() << "Stop log." << std::endl;
fsLogFile.close();
DeleteCriticalSection(&cs);
}
}

View File

@@ -1,29 +0,0 @@
// wCenterWindow
// CLogger.h
#pragma once
#include <Windows.h>
#include <fstream>
#define MAX_LOGBUFFER_LENGTH 512
class CLogger {
public:
void Out(const wchar_t*, ...);
CLogger(const wchar_t*);
~CLogger();
private:
SYSTEMTIME lt;
CRITICAL_SECTION cs;
wchar_t logTimeBuffer[28]{ 0 };
wchar_t logBuffer[MAX_LOGBUFFER_LENGTH]{ 0 };
std::wofstream fsLogFile;
std::wstring szAppTitle{ 0 };
std::wstring szAppVersion{ 0 };
std::wstring szAppPlatform{ 0 };
std::wstring szAppTitleVer{ 0 };
inline wchar_t* GetTimeStamp();
void Init();
};

76
wCenterWindow/Logger.cpp Normal file
View File

@@ -0,0 +1,76 @@
// wCenterWindow, v2.3.3
// Logger.cpp
//
#include "framework.h"
#define TS_LEN 30
#define PATH_LEN 1024
std::wofstream logfile;
extern WCHAR szTitle[];
extern LPVOID szBuffer;
namespace fs = std::filesystem;
std::wstring PrintTitle()
{
wchar_t szWinTitle[2048];
StringCchPrintf(szWinTitle, 2048, L"%s", szBuffer);
return szWinTitle;
}
std::wstring GetTimeStamp()
{
SYSTEMTIME lt;
GetLocalTime(&lt);
wchar_t ts[TS_LEN];
StringCchPrintfW(ts, TS_LEN, L"%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_t lpszPath[PATH_LEN]{};
DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, PATH_LEN);
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;
}
fs::path log_path = lpszPath;
log_path.replace_extension(L".log");
fs::path bak_path = log_path;
bak_path.replace_extension(L".bak");
if (fs::exists(log_path)) fs::rename(log_path, bak_path);
#ifdef _DEBUG
log_path = L"d:\\test.log";
#endif
logfile.open(log_path);
if (logfile.is_open())
{
diag_log(L"Start logging.");
diag_log(L"Logfile:", log_path);
diag_log(log_path, L"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(L"End logging.");
logfile.close();
}
}

60
wCenterWindow/Logger.h Normal file
View File

@@ -0,0 +1,60 @@
// wCenterWindow, v2.3.3
// Logger.h
//
#pragma once
#include "framework.h"
extern std::wofstream logfile;
std::wstring GetTimeStamp();
std::wstring PrintTitle();
template <typename T1>
void diag_log(T1 arg1)
{
logfile << GetTimeStamp() << arg1 << std::endl;
}
template <typename T1, typename T2>
void diag_log(T1 arg1, T2 arg2)
{
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << std::endl;
}
template <typename T1, typename T2, typename T3>
void diag_log(T1 arg1, T2 arg2, T3 arg3)
{
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << std::endl;
}
template <typename T1, typename T2, typename T3, typename T4>
void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << std::endl;
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
{
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << std::endl;
}
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
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 <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
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 <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
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();

Binary file not shown.

View File

@@ -1,6 +1,26 @@
// wCenterWindow // header.h : include file for standard system include files,
// framework.h // or project specific include files
//
#pragma once #pragma once
#include "targetver.h" #include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
#include <strsafe.h>
#include <windows.h>
#include <shellapi.h>
#include <CommCtrl.h>
// C RunTime Header Files
//#include <stdlib.h>
//#include <malloc.h>
//#include <memory.h>
// Project Specific Header Files
#include "Logger.h"

File diff suppressed because it is too large Load Diff

View File

@@ -2,38 +2,36 @@
// Microsoft Visual C++ generated include file. // Microsoft Visual C++ generated include file.
// Used by wCenterWindow.rc // Used by wCenterWindow.rc
// //
#define IDS_CLASSNAME 100 #define IDS_CLASSNAME 102
#define IDS_APP_TITLE 101 #define IDS_APP_TITLE 103
#define IDI_TRAYICON 102 #define IDD_ABOUTBOX 104
#define IDR_MENU 103 #define IDI_TRAYICON 105
#define ID_POPUPMENU_ICON 104 #define IDR_MENU 106
#define ID_POPUPMENU_AREA 105 #define ID_POPUPMENU_ICON 107
#define ID_POPUPMENU_HELP 106 #define ID_POPUPMENU_AREA 108
#define ID_POPUPMENU_ABOUT 107 #define ID_POPUPMENU_ABOUT 110
#define ID_POPUPMENU_EXIT 108 #define ID_POPUPMENU_EXIT 111
#define IDS_HELP 109 #define IDS_ABOUT 112
#define IDS_ERR_MAIN 110 #define IDS_ERR_MAIN 113
#define IDS_ERR_CLASS 111 #define IDS_ERR_WND 114
#define IDS_ERR_WND 112 #define IDS_ERR_ICON 115
#define IDS_ERR_ICON 113 #define IDS_ERR_MENU 116
#define IDS_ERR_MENU 114 #define IDS_ERR_POPUP 117
#define IDS_ERR_POPUP 115 #define IDS_ERR_HOOK 118
#define IDS_ERR_HOOK 116
#define IDS_ERR_TIMER 117
#define IDS_ERR_HEAP 118
#define IDS_ERR_MAXMIN 119 #define IDS_ERR_MAXMIN 119
#define IDS_RUNNING 120 #define IDS_RUNNING 121
#define IDT_TIMER 121 #define IDR_MAINFRAME 128
#define IDD_MANUAL_EDITING 1000 #define IDD_MANUAL_EDITING 129
#define IDC_EDIT_X 1001 #define IDC_EDIT_X 1000
#define IDC_EDIT_Y 1002 #define IDC_EDIT_Y 1001
#define IDC_EDIT_WIDTH 1003 #define IDC_EDIT_WIDTH 1002
#define IDC_EDIT_HEIGHT 1004 #define IDC_EDIT_HEIGHT 1003
#define IDC_EDIT_TITLE 1005 #define IDC_EDIT_TITLE 1004
#define IDC_EDIT_CLASS 1006 #define IDC_EDIT_CLASS 1005
#define IDC_BUTTON_SET 1007 #define IDC_BUTTON_SET 1006
#define IDC_BUTTON_CENTER 1008 #define IDC_BUTTON_CLOSE 1007
#define IDC_BUTTON_CLOSE 1009 #define IDC_ABOUTHELP 1008
#define IDC_DONATIONLINK 1009
#define IDC_STATIC -1 #define IDC_STATIC -1
// Next default values for new objects // Next default values for new objects
@@ -41,7 +39,7 @@
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1 #define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 200 #define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1010 #define _APS_NEXT_CONTROL_VALUE 1010
#define _APS_NEXT_SYMED_VALUE 122 #define _APS_NEXT_SYMED_VALUE 122

View File

@@ -1,12 +1,6 @@
// wCenterWindow
// targetver.h
#pragma once #pragma once
// // Including SDKDDKVer.h defines the highest available Windows platform. // // Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <winsdkver.h>
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
#define _WIN32_IE 0x0601
#include <SDKDDKVer.h> #include <SDKDDKVer.h>

View File

@@ -1,201 +0,0 @@
// wCenterWindow
// updater.h
#include "wCenterWindow.h"
#include "updater.h"
#include "picojson.h"
#include <cwctype>
#define GITHUB_URL TEXT("api.github.com")
#define GITHUB_URI TEXT("/repos/dreamforceinc/wCenterWindow/releases/latest")
picojson::value json;
struct Version {
UINT Major = 0;
UINT Minor = 0;
UINT Build = 0;
UINT Patch = 0;
} verApp, verGh;
bool GetLatestRelease(const std::wstring& urn);
void FillVersionStructure(Version& ver, const std::wstring& str);
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim);
std::wstring ConvertUtf8ToWide(const std::string& str);
UINT WINAPI Updater(void*) {
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
logger.Out(L"[UPDT] Sleeping %d seconds", T0);
Sleep(T0 * 1000); // 10 seconds
if (!GetLatestRelease(GITHUB_URI)) {
logger.Out(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
MessageBoxW(NULL, L"Failed getting releases!", szTitle, MB_OK | MB_ICONERROR);
return 101;
_endthreadex(101);
}
std::wstring j_tag_name, j_file_name, j_file_ext, j_file_url, j_page_url;
int64_t j_file_size = 0;
picojson::object obj, obj2;
picojson::object::iterator it, it2;
if (json.is<picojson::object>()) {
logger.Out(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
obj = json.get<picojson::object>();
it = obj.find("message"), it2;
if (it != obj.end()) {
std::string u = (*it).second.get<std::string>();
logger.Out(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u);
return 102;
_endthreadex(102);
}
for (it = obj.begin(); it != obj.end(); it++) {
if ((*it).first == "tag_name") j_tag_name = ConvertUtf8ToWide((*it).second.to_str());
if ((*it).first == "html_url") j_page_url = ConvertUtf8ToWide((*it).second.to_str());
if ((*it).first == "assets" && (*it).second.is<picojson::array>()) {
picojson::array a = (*it).second.get<picojson::array>();
obj2 = a[0].get<picojson::object>();
for (it2 = obj2.begin(); it2 != obj2.end(); it2++) {
if ((*it2).first == "name") j_file_name = ConvertUtf8ToWide((*it2).second.to_str());
if ((*it2).first == "browser_download_url") j_file_url = ConvertUtf8ToWide((*it2).second.to_str());
if ((*it2).first == "size") j_file_size = static_cast<int64_t>((*it2).second.get<double>());
}
}
}
}
else {
logger.Out(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
return 103;
_endthreadex(103);
}
size_t pos = 0;
while (std::iswdigit(j_tag_name.at(pos)) == 0) pos++;
std::wstring gh_version = j_tag_name.substr(pos);
logger.Out(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR));
logger.Out(L"[UPDT] %s(%d): GitVersion : %s", TEXT(__FUNCTION__), __LINE__, gh_version.c_str());
//logger.Out(L"[UPDT] %s(%d): FileName : %s", TEXT(__FUNCTION__), __LINE__, j_file_name.c_str());
//logger.Out(L"[UPDT] %s(%d): FileSize : %d", TEXT(__FUNCTION__), __LINE__, j_file_size);
//logger.Out(L"[UPDT] %s(%d): File Url : %s", TEXT(__FUNCTION__), __LINE__, j_file_url.c_str());
//logger.Out(L"[UPDT] %s(%d): Page Url : %s", TEXT(__FUNCTION__), __LINE__, j_page_url.c_str());
FillVersionStructure(verApp, TEXT(VERSION_STR));
FillVersionStructure(verGh, gh_version);
if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Patch > verApp.Patch)) {
logger.Out(L"[UPDT] %s(%d): An update is available!", TEXT(__FUNCTION__), __LINE__);
if (IDYES == MessageBoxW(NULL, L"An update is available!\nDo you want to open the download page?", szTitle, MB_YESNO | MB_ICONINFORMATION)) {
logger.Out(L"[UPDT] %s(%d): Opening download page by default browser", TEXT(__FUNCTION__), __LINE__);
ShellExecuteW(NULL, L"open", j_page_url.c_str(), NULL, NULL, SW_SHOW);
}
else {
logger.Out(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
}
}
else {
logger.Out(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
}
logger.Out(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
return 0;
_endthreadex(0);
}
bool GetLatestRelease(const std::wstring& urn) {
std::wstring user_agent = L"User-Agent: ";
user_agent.append(szTitle);
const std::wstring url = GITHUB_URL;
bool ret = true;
DWORD err = 0;
logger.Out(L"[UPDT] %s(%d): %s", TEXT(__FUNCTION__), __LINE__, user_agent.c_str());
HINTERNET hInternet = InternetOpenW(user_agent.c_str(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hInternet != NULL) {
HINTERNET hConnect = InternetConnectW(hInternet, url.c_str(), INTERNET_DEFAULT_HTTPS_PORT, L"", L"", INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
if (hConnect != NULL) {
HINTERNET hRequest = HttpOpenRequestW(hConnect, L"GET", urn.c_str(), NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_UI, 0);
if (hRequest != NULL) {
BOOL isSend = HttpSendRequestW(hRequest, NULL, 0, 0, 0);
if (isSend) {
char szData[1024]{ 0 };
DWORD dwBytesRead = 0;
std::string buffer;
do {
InternetReadFile(hRequest, szData, sizeof(szData), &dwBytesRead);
buffer.append(szData, dwBytesRead);
}
while (dwBytesRead != 0);
picojson::parse(json, buffer);
std::string jerr = picojson::get_last_error();
if (!jerr.empty()) {
logger.Out(L"[UPDT] %s(%d): Error while parsing JSON object: %s", TEXT(__FUNCTION__), __LINE__, ConvertUtf8ToWide(jerr));
MessageBoxW(NULL, L"Error while parsing JSON object!", szTitle, MB_OK | MB_ICONERROR);
ret = false;
}
}
else {
err = GetLastError();
logger.Out(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false;
}
}
else {
err = GetLastError();
logger.Out(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false;
}
InternetCloseHandle(hRequest);
}
else {
err = GetLastError();
logger.Out(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false;
}
InternetCloseHandle(hConnect);
}
else {
err = GetLastError();
logger.Out(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false;
}
InternetCloseHandle(hInternet);
return ret;
}
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim) {
std::vector<std::wstring> result;
std::wstringstream ss(s);
std::wstring item;
while (getline(ss, item, delim)) result.push_back(item);
return result;
}
void FillVersionStructure(Version& ver, const std::wstring& str) {
std::vector<std::wstring> v;
v = Split(str, '.');
if (v.size() < 4) v.push_back(L"0");
ver.Major = std::stoul(v[0]);
ver.Minor = std::stoul(v[1]);
ver.Build = std::stoul(v[2]);
ver.Patch = std::stoul(v[3]);
}
std::wstring ConvertUtf8ToWide(const std::string& str) {
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
std::wstring wstr(count, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], count);
return wstr;
}

View File

@@ -1,5 +0,0 @@
// wCenterWindow
// updater.h
#pragma once
UINT WINAPI Updater(void*);

View File

@@ -1,482 +1,366 @@
// wCenterWindow // wCenterWindow, v2.3.3
// wCenterWindow.cpp //
// TODO: More verbose logs - partially done.
// TODO: Split main cpp-file to separate files. // TODO: More verbose error messages
// TODO: Make the automatic updater (download, unzip and replace executable). // TODO: Window's title in logs (Impossible?)
// TODO: Change keyboard low-level hook to RegisterHotKey function. (Is it really needed?)
#include "framework.h" #include "framework.h"
#include "wCenterWindow.h" #include "wCenterWindow.h"
#include "updater.h"
//#define NO_DONATION
#define KEY_I 0x49 #define KEY_I 0x49
#define KEY_C 0x43 #define KEY_C 0x43
#define KEY_V 0x56 #define KEY_V 0x56
#define MAX_WINTITLE_BUFFER_LENGTH 1024 #define BUF_LEN 4096
#define WM_WCW (WM_APP + 0x0F00) #define MAX_LOADSTRING 50
#define WM_WCW 0x8F00
// Global variables: // Global variables:
WCHAR szTitle[MAX_LOADSTRING]{ 0 }; // wCenterWindow's title HINSTANCE hInst; // Instance
HICON hIconSmall = NULL, hIconLarge = NULL; WCHAR szTitle[MAX_LOADSTRING]; // Window's title
HMENU hPopup = NULL; WCHAR szClass[MAX_LOADSTRING]; // Window's class
HWND hFgWnd = NULL; WCHAR szAbout[MAX_LOADSTRING * 12]; // Description text
BOOL bKPressed = FALSE, bMPressed = FALSE, fShowIcon = TRUE, fCheckUpdates = TRUE, bWorkArea = TRUE; WCHAR szWinTitle[256];
WCHAR szWinClass[256];
WCHAR szWinCore[] = TEXT("Windows.UI.Core.CoreWindow");
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; BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE;
UINT uMsgRestore = 0;
CLogger logger(TEXT(PRODUCT_NAME_FULL));
RECT rcFW = { 0 };
NOTIFYICONDATAW nid = { 0 }; NOTIFYICONDATAW nid = { 0 };
MENUITEMINFOW mii = { 0 }; LPKBDLLHOOKSTRUCT pkhs = { 0 };
MENUITEMINFO mii = { 0 };
LPVOID szWinTitleBuffer = nullptr; LPVOID szBuffer;
LPVOID szWinClassBuffer = nullptr;
// {2D7B7F30-4B5F-4380-9807-57D7A2E37F6C}
static const GUID guid = { 0x2d7b7f30, 0x4b5f, 0x4380, { 0x98, 0x7, 0x57, 0xd7, 0xa2, 0xe3, 0x7f, 0x6c } };
// Forward declarations of functions included in this code module: // Forward declarations of functions included in this code module:
VOID HandlingTrayIcon(); VOID HandlingTrayIcon();
VOID ShowError(UINT, LPCWSTR); VOID ShowError(UINT);
VOID ShowPopupMenu(HWND, POINT); BOOL CheckWindow(HWND);
BOOL IsWindowApprooved(HWND); BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK KeyboardHookProc(int, WPARAM, LPARAM); LRESULT CALLBACK KeyboardHookProc(int, WPARAM, LPARAM);
LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM); LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM);
INT_PTR CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
HRESULT CALLBACK AboutCallback(HWND, UINT, WPARAM, LPARAM, LONG_PTR);
static VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) {
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
{
//diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd, L"Title:", (LPWSTR)szBuffer);
diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd);
RECT fgwrc = { 0 }; RECT fgwrc = { 0 };
GetWindowRect(hwnd, &fgwrc); GetWindowRect(hwnd, &fgwrc);
LONG nWidth = fgwrc.right - fgwrc.left; LONG nWidth = fgwrc.right - fgwrc.left;
LONG nHeight = fgwrc.bottom - fgwrc.top; LONG nHeight = fgwrc.bottom - fgwrc.top;
logger.Out(L"%s(%d): Moving the window from %d, %d", TEXT(__FUNCTION__), __LINE__, fgwrc.left, fgwrc.top); diag_log(L"Moving window from x =", fgwrc.left, L"y =", fgwrc.top);
MONITORINFO mi = { 0 }; MONITORINFO mi = { 0 };
mi.cbSize = sizeof(MONITORINFO); mi.cbSize = sizeof(MONITORINFO);
GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi); GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi);
RECT area = { 0 }; RECT area = { 0 };
if (bWorkArea) { if (bWorkArea)
{
area.bottom = mi.rcWork.bottom; area.bottom = mi.rcWork.bottom;
area.left = mi.rcWork.left; area.left = mi.rcWork.left;
area.right = mi.rcWork.right; area.right = mi.rcWork.right;
area.top = mi.rcWork.top; area.top = mi.rcWork.top;
} }
else { else
{
area.bottom = mi.rcMonitor.bottom; area.bottom = mi.rcMonitor.bottom;
area.left = mi.rcMonitor.left; area.left = mi.rcMonitor.left;
area.right = mi.rcMonitor.right; area.right = mi.rcMonitor.right;
area.top = mi.rcMonitor.top; area.top = mi.rcMonitor.top;
} }
LONG aw = area.right - area.left; int aw = area.right - area.left;
LONG ah = area.bottom - area.top; int ah = area.bottom - area.top;
if ((nWidth > aw) && bResize) nWidth = aw; if (nWidth > aw && bResize) nWidth = aw;
if ((nHeight > ah) && bResize) nHeight = ah; if (nHeight > ah && bResize) nHeight = ah;
if (area.left < 0) { if (area.left < 0) aw = -aw;
aw = -aw; if (area.top < 0) ah = -ah;
area.left = 0; int x = (aw - nWidth) / 2;
} int y = (ah - nHeight) / 2;
if (area.top < 0) {
ah = -ah;
area.top = 0;
}
int x = area.left + (aw - nWidth) / 2;
int y = area.top + (ah - nHeight) / 2;
logger.Out(L"%s(%d): Moving the window to %d, %d", TEXT(__FUNCTION__), __LINE__, x, y);
SendMessageW(hwnd, WM_ENTERSIZEMOVE, NULL, NULL); SendMessageW(hwnd, WM_ENTERSIZEMOVE, NULL, NULL);
MoveWindow(hwnd, x, y, nWidth, nHeight, TRUE); MoveWindow(hwnd, x, y, nWidth, nHeight, TRUE);
SendMessageW(hwnd, WM_EXITSIZEMOVE, NULL, NULL); SendMessageW(hwnd, WM_EXITSIZEMOVE, NULL, NULL);
logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__)); diag_log(L"Moving window to x =", x, L"y =", y);
diag_log(L"Quiting MoveWindowToMonitorCenter()");
} }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
WCHAR szClass[MAX_LOADSTRING]{ 0 }; // Window's class ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = WndProc;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_TRAYICON));
wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
wcex.lpszClassName = szClass;
wcex.hIconSm = wcex.hIcon;
hIcon = wcex.hIcon;
return RegisterClassExW(&wcex);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
OpenLogFile();
diag_log(L"Entering WinMain()");
hInst = hInstance;
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, _countof(szTitle)); LoadStringW(hInstance, IDS_APP_TITLE, szTitle, _countof(szTitle));
LoadStringW(hInstance, IDS_CLASSNAME, szClass, _countof(szClass)); LoadStringW(hInstance, IDS_CLASSNAME, szClass, _countof(szClass));
if (FindWindowW(szClass, NULL)) { if (FindWindowW(szClass, NULL))
ShowError(IDS_RUNNING, szTitle); {
return -10; ShowError(IDS_RUNNING);
return FALSE;
} }
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__)); MyRegisterClass(hInstance);
hWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
if (!hWnd)
{
ShowError(IDS_ERR_WND);
return FALSE;
}
int nArgs = 0; int nArgs = 0;
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
logger.Out(L"Arguments count: %d", nArgs - 1); diag_log(L"Arguments:", nArgs - 1);
for (int i = 1; i < nArgs; i++)
if (nArgs > 1) { {
for (int i = 1; i < nArgs; i++) { diag_log(L"Argument", i, L":", szArglist[i]);
logger.Out(L"Argument %d: %s", i, szArglist[i]);
if (0 == lstrcmpiW(szArglist[i], L"/hide")) fShowIcon = FALSE;
if (0 == lstrcmpiW(szArglist[i], L"/noupdate")) fCheckUpdates = FALSE;
} }
} (nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], L"/hide")) ? bShowIcon = FALSE : bShowIcon = TRUE;
LocalFree(szArglist); LocalFree(szArglist);
LoadIconMetric(hInstance, MAKEINTRESOURCEW(IDI_TRAYICON), LIM_LARGE, &hIconLarge);
LoadIconMetric(hInstance, MAKEINTRESOURCEW(IDI_TRAYICON), LIM_SMALL, &hIconSmall);
WNDCLASSEXW wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEXW);
wcex.lpfnWndProc = WndProc;
wcex.hInstance = hInstance;
wcex.hIcon = hIconLarge;
wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
wcex.lpszClassName = szClass;
wcex.hIconSm = hIconSmall;
if (!RegisterClassExW(&wcex)) {
ShowError(IDS_ERR_CLASS, szTitle);
return -9;
}
HWND hMainWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
if (!hMainWnd) {
ShowError(IDS_ERR_WND, szTitle);
return -8;
}
#ifndef _DEBUG
HHOOK hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, GetModuleHandleW(NULL), NULL);
if (!hMouseHook) {
logger.Out(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_HOOK, szTitle);
return -7;
}
logger.Out(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
#endif // !_DEBUG
HHOOK hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandleW(NULL), NULL);
if (!hKbdHook) {
logger.Out(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_HOOK, szTitle);
return -6;
}
logger.Out(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
HMENU hMenu = LoadMenuW(hInstance, MAKEINTRESOURCE(IDR_MENU));
if (!hMenu) {
logger.Out(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_MENU, szTitle);
return -5;
}
logger.Out(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
hPopup = GetSubMenu(hMenu, 0);
if (!hPopup) {
logger.Out(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_POPUP, szTitle);
return -4;
}
logger.Out(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
mii.cbSize = sizeof(MENUITEMINFOW);
mii.fMask = MIIM_STATE;
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
HandlingTrayIcon(); HandlingTrayIcon();
HANDLE hHeap = GetProcessHeap(); hHeap = GetProcessHeap();
szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, BUF_LEN);
szWinTitleBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, MAX_WINTITLE_BUFFER_LENGTH); hTaskBar = FindWindowW(L"Shell_TrayWnd", NULL);
if (nullptr == szWinTitleBuffer) { hProgman = FindWindowW(L"Progman", NULL);
ShowError(IDS_ERR_HEAP, szTitle); hDesktop = GetDesktopWindow();
return -3;
}
szWinClassBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, MAX_WINTITLE_BUFFER_LENGTH);
if (nullptr == szWinClassBuffer) {
ShowError(IDS_ERR_HEAP, szTitle);
return -2;
}
MSG msg; MSG msg;
BOOL bRet; BOOL bRet;
while ((bRet = GetMessageW(&msg, NULL, 0, 0)) != 0) { while ((bRet = GetMessageW(&msg, NULL, 0, 0)) != 0)
if (bRet == -1) { {
ShowError(IDS_ERR_MAIN, szTitle); if (bRet == -1)
{
ShowError(IDS_ERR_MAIN);
return -1; return -1;
} }
else { else
{
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageW(&msg); DispatchMessageW(&msg);
} }
} }
#ifndef _DEBUG
if (hMouseHook) UnhookWindowsHookEx(hMouseHook); if (hMouseHook) UnhookWindowsHookEx(hMouseHook);
#endif // !_DEBUG
if (hKbdHook) UnhookWindowsHookEx(hKbdHook); if (hKbdHook) UnhookWindowsHookEx(hKbdHook);
if (hMenu) DestroyMenu(hMenu); if (hMenu) DestroyMenu(hMenu);
Shell_NotifyIconW(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
KillTimer(hMainWnd, IDT_TIMER);
DestroyIcon(hIconSmall);
DestroyIcon(hIconLarge);
HeapFree(hHeap, NULL, szWinClassBuffer);
HeapFree(hHeap, NULL, szWinTitleBuffer);
logger.Out(L"Exit from the %s() function, msg.wParam = 0x%0*tX", TEXT(__FUNCTION__), (sizeof(UINT_PTR) * 2), static_cast<UINT_PTR>(msg.wParam)); diag_log(L"Quiting WinMain(), msg.wParam =", (int)msg.wParam);
CloseLogFile();
HeapFree(hHeap, NULL, szBuffer);
return static_cast<UINT_PTR>(msg.wParam); return (int)msg.wParam;
} }
LRESULT CALLBACK WndProc(HWND hMainWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message) { {
switch (message)
{
case WM_CREATE: case WM_CREATE:
{ {
logger.Out(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__); hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
if (!hMenu)
{
diag_log(L"Loading context menu failed!");
ShowError(IDS_ERR_MENU);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
diag_log(L"Context menu successfully loaded");
hPopup = GetSubMenu(hMenu, 0);
if (!hPopup)
{
diag_log(L"Creating popup menu failed!");
ShowError(IDS_ERR_POPUP);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
diag_log(L"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);
nid.cbSize = sizeof(NOTIFYICONDATAW); nid.cbSize = sizeof(NOTIFYICONDATAW);
nid.hWnd = hMainWnd; nid.hWnd = hWnd;
nid.uVersion = NOTIFYICON_VERSION_4; nid.uVersion = NOTIFYICON_VERSION;
nid.uCallbackMessage = WM_WCW; nid.uCallbackMessage = WM_WCW;
nid.hIcon = hIconSmall; nid.hIcon = hIcon;
nid.uID = IDI_TRAYICON; nid.uID = IDI_TRAYICON;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP; 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); StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle);
uMsgRestore = RegisterWindowMessageW(L"TaskbarCreated"); hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
if (!uMsgRestore) { if (!hMouseHook)
logger.Out(L"%s(%d): Registering 'TaskbarCreated' message failed!", TEXT(__FUNCTION__), __LINE__);
}
logger.Out(L"%s(%d): The 'TaskbarCreated' message successfully registered", TEXT(__FUNCTION__), __LINE__);
if (fCheckUpdates) {
if (!SetTimer(hMainWnd, IDT_TIMER, (T1 * 1000 - T0 * 1000), NULL)) // 50 seconds
{ {
logger.Out(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__); diag_log(L"Creating mouse hook failed!");
ShowError(IDS_ERR_TIMER, szTitle); ShowError(IDS_ERR_HOOK);
fCheckUpdates = FALSE; SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
logger.Out(L"%s(%d): Timer successfully created (%d sec)", TEXT(__FUNCTION__), __LINE__, (T1 - T0)); diag_log(L"Mouse hook was successfully set");
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
if (!hKbdHook)
{
diag_log(L"Creating keyboard hook failed!");
ShowError(IDS_ERR_HOOK);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
diag_log(L"Keyboard hook was successfully set");
LoadStringW(hInst, IDS_ABOUT, szAbout, _countof(szAbout));
break; break;
} }
case WM_TIMER:
{
if (fCheckUpdates) {
logger.Out(L"%s(%d): Checking for updates is enabled", TEXT(__FUNCTION__), __LINE__);
HANDLE hUpdater = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &Updater, NULL, 0, NULL));
if (NULL == hUpdater) {
DWORD dwLastError = GetLastError();
logger.Out(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError);
}
else {
if (!SetTimer(hMainWnd, IDT_TIMER, (T2 * 1000), NULL)) // 1 day
{
logger.Out(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_TIMER, szTitle);
fCheckUpdates = FALSE;
}
logger.Out(L"%s(%d): Timer successfully created (%d sec)", TEXT(__FUNCTION__), __LINE__, T2);
CloseHandle(hUpdater);
}
}
else {
logger.Out(L"%s(%d): Checking for updates is disabled", TEXT(__FUNCTION__), __LINE__);
}
break;
}
// Popup menu handler
case WM_WCW: case WM_WCW:
{ {
if (WM_CONTEXTMENU == LOWORD(lParam)) { if ((lParam == WM_RBUTTONDOWN || lParam == WM_LBUTTONDOWN) && wParam == IDI_TRAYICON)
logger.Out(L"%s(%d): Recived WM_CONTEXTMENU message", TEXT(__FUNCTION__), __LINE__);
POINT pt{ GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam) };
ShowPopupMenu(hMainWnd, pt);
}
break;
}
case WM_COMMAND:
{ {
int wmId = LOWORD(wParam); SetForegroundWindow(hWnd);
POINT pt;
// Parse the menu selections: GetCursorPos(&pt);
switch (wmId) { int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
case ID_POPUPMENU_ICON: if (idMenu == ID_POPUPMENU_ICON)
{ {
logger.Out(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__); bShowIcon = FALSE;
fShowIcon = FALSE;
HandlingTrayIcon(); HandlingTrayIcon();
break;
} }
case ID_POPUPMENU_AREA: if (idMenu == ID_POPUPMENU_AREA)
{ {
logger.Out(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__);
bWorkArea = !bWorkArea; bWorkArea = !bWorkArea;
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
logger.Out(L"%s(%d): Changed 'Use workarea' option to %s", TEXT(__FUNCTION__), __LINE__, bWorkArea ? L"True" : L"False"); diag_log(L"Changed 'Use workarea' option to", bWorkArea);
break;
} }
case ID_POPUPMENU_HELP: if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed)
{ {
if (!bKPressed) {
logger.Out(L"%s(%d): Pressed the 'Help' menuitem", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE; bKPressed = TRUE;
WCHAR szHelp[MAX_LOADSTRING * 15]; diag_log(L"Opening 'About' dialog");
LoadStringW(GetModuleHandleW(NULL), IDS_HELP, szHelp, _countof(szHelp)); DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
MessageBoxW(hMainWnd, szHelp, szTitle, MB_OK | MB_ICONINFORMATION);
bKPressed = FALSE; bKPressed = FALSE;
} }
break; if (idMenu == ID_POPUPMENU_EXIT) SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
case ID_POPUPMENU_ABOUT:
{
if (!bKPressed) {
logger.Out(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE;
WCHAR szContent[MAX_LOADSTRING * 6] = { 0 };
StringCchPrintfW(szContent, ARRAYSIZE(szContent),
L"%s\n%s\n\n%s\n%s\n%s",
TEXT(PRODUCT_COPYRIGHT),
L"Program icon made by Kirill Topov.",
L"This software is licensed under a <A HREF=\"https://mit-license.org\">MIT License</A>.",
L"This software uses the <A HREF=\"https://github.com/kazuho/picojson\">PicoJSON</A> - a C++ JSON parser/serializer by Kazuho Oku.",
#ifndef NO_DONATION
L"\n<A HREF=\"https://www.paypal.com/paypalme/VladislavSalikov\">Donate via PayPal</A>"
#else
L""
#endif // !NO_DONATION
);
TASKDIALOGCONFIG tdc = { 0 };
tdc.cbSize = sizeof(tdc);
tdc.hInstance = GetModuleHandleW(NULL);
tdc.dwFlags = TDF_ENABLE_HYPERLINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_USE_HICON_MAIN | TDF_SIZE_TO_CONTENT;
tdc.dwCommonButtons = TDCBF_OK_BUTTON;
tdc.pszWindowTitle = L"About";
tdc.hMainIcon = hIconLarge;
tdc.pszMainInstruction = TEXT(PRODUCT_NAME_FULL);
tdc.pszContent = szContent;
tdc.pfCallback = AboutCallback;
TaskDialogIndirect(&tdc, NULL, NULL, NULL);
bKPressed = FALSE;
}
break;
}
case ID_POPUPMENU_EXIT:
{
logger.Out(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__);
DestroyWindow(hMainWnd);
break;
}
}
break;
}
case WM_QUERYENDSESSION:
{
logger.Out(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%p", TEXT(__FUNCTION__), __LINE__, lParam);
PostQuitMessage(0);
return TRUE;
break; break;
} }
case WM_DESTROY: case WM_DESTROY:
{ {
logger.Out(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
PostQuitMessage(0); PostQuitMessage(0);
break; break;
} }
default: default:
{ return DefWindowProcW(hWnd, message, wParam, lParam);
if (message == uMsgRestore) {
logger.Out(L"%s(%d): Recieved the 'TaskbarCreated' message", TEXT(__FUNCTION__), __LINE__);
HandlingTrayIcon();
break;
}
return DefWindowProcW(hMainWnd, message, wParam, lParam);
}
} }
return 0; return 0;
} }
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
if (WM_MBUTTONUP == wParam) bMPressed = FALSE; {
if (WM_MBUTTONDOWN == wParam && bLCTRL && bLWIN && !bMPressed) { if (wParam == WM_MBUTTONUP) bMPressed = FALSE;
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__); if (wParam == WM_MBUTTONDOWN && bLCTRL && bLWIN && !bMPressed)
{
diag_log(L"Pressed LCTRL + LWIN + MMB");
bMPressed = TRUE; bMPressed = TRUE;
hFgWnd = GetForegroundWindow(); hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); BOOL bApproved = CheckWindow(hFgWnd);
if (bApproved) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
else hFgWnd = NULL; else hFgWnd = NULL;
} }
return CallNextHookEx(NULL, nCode, wParam, lParam); return CallNextHookEx(NULL, nCode, wParam, lParam);
} }
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
LPKBDLLHOOKSTRUCT pkhs = { 0 }; {
pkhs = reinterpret_cast<LPKBDLLHOOKSTRUCT>(lParam); pkhs = (KBDLLHOOKSTRUCT*)lParam;
if (WM_KEYUP == wParam) {
if (VK_LCONTROL == pkhs->vkCode) bLCTRL = FALSE; if (wParam == WM_KEYUP)
if (VK_LWIN == pkhs->vkCode) bLWIN = FALSE; {
if (pkhs->vkCode == VK_LCONTROL) bLCTRL = FALSE;
if (pkhs->vkCode == VK_LWIN) bLWIN = FALSE;
bKPressed = FALSE; bKPressed = FALSE;
} }
if (WM_KEYDOWN == wParam) { if (wParam == WM_KEYDOWN)
if (VK_LCONTROL == pkhs->vkCode) bLCTRL = TRUE; {
if (VK_LWIN == pkhs->vkCode) bLWIN = TRUE; if (pkhs->vkCode == VK_LCONTROL) bLCTRL = TRUE;
if (pkhs->vkCode == VK_LWIN) bLWIN = TRUE;
// 'I' key
if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) {
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__);
if (bLCTRL && bLWIN && pkhs->vkCode == KEY_I && !bKPressed) // 'I' key
{
diag_log(L"Pressed LCTRL + LWIN + I");
bKPressed = TRUE; bKPressed = TRUE;
fShowIcon = !fShowIcon; bShowIcon = !bShowIcon;
HandlingTrayIcon(); HandlingTrayIcon();
return TRUE; return TRUE;
} }
// 'C' key if (bLCTRL && bLWIN && pkhs->vkCode == KEY_C && !bKPressed && !bKEYV) // 'C' key
if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) { {
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__); diag_log(L"Pressed LCTRL + LWIN + C");
bKPressed = TRUE; bKPressed = TRUE;
hFgWnd = GetForegroundWindow(); hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); BOOL bApproved = CheckWindow(hFgWnd);
if (bApproved) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
else hFgWnd = NULL; else hFgWnd = NULL;
return TRUE; return TRUE;
} }
// 'V' key if (bLCTRL && bLWIN && pkhs->vkCode == KEY_V && !bKPressed && !bKEYV) // 'V' key
if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) { {
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__); diag_log(L"Pressed LCTRL + LWIN + V");
bKPressed = TRUE; bKEYV = TRUE; bKPressed = TRUE; bKEYV = TRUE;
hFgWnd = GetForegroundWindow(); hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd)) { BOOL bApproved = CheckWindow(hFgWnd);
logger.Out(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); if (bApproved)
{
DialogBoxParamW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDD_MANUAL_EDITING), hFgWnd, static_cast<DLGPROC>(DlgProc), 0L); diag_log(L"Opening 'Manual editing' dialog");
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc);
SetForegroundWindow(hFgWnd); SetForegroundWindow(hFgWnd);
} }
else hFgWnd = NULL; else hFgWnd = NULL;
@@ -487,16 +371,16 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
return CallNextHookEx(NULL, nCode, wParam, lParam); return CallNextHookEx(NULL, nCode, wParam, lParam);
} }
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
RECT rcFW = { 0 }; {
int x, y, w, h; int x, y, w, h;
switch (dlgmsg) { switch (dlgmsg)
{
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
logger.Out(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
SetWindowTextW(hDlg, szTitle); SetWindowTextW(hDlg, szTitle);
GetClassNameW(hFgWnd, static_cast<LPWSTR>(szWinClassBuffer), MAX_WINTITLE_BUFFER_LENGTH); GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass));
GetWindowRect(hFgWnd, &rcFW); GetWindowRect(hFgWnd, &rcFW);
x = rcFW.left; x = rcFW.left;
y = rcFW.top; y = rcFW.top;
@@ -506,19 +390,16 @@ INT_PTR CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) {
SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE); SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE);
SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE); SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE); SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE);
SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, static_cast<LPCWSTR>(szWinTitleBuffer)); SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle);
SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, static_cast<LPCWSTR>(szWinClassBuffer)); SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass);
UpdateWindow(hDlg); UpdateWindow(hDlg);
break; break;
} }
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(wParam))
{ {
switch (LOWORD(wParam)) {
case IDC_BUTTON_SET: case IDC_BUTTON_SET:
{ {
logger.Out(L"%s(%d): Pressed the 'Set' button", TEXT(__FUNCTION__), __LINE__);
x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE); x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE);
y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE); y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE);
w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE); w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE);
@@ -526,119 +407,114 @@ INT_PTR CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) {
SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL); SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL);
MoveWindow(hFgWnd, x, y, w, h, TRUE); MoveWindow(hFgWnd, x, y, w, h, TRUE);
SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL);
return TRUE;
logger.Out(L"%s(%d): Window with handle 0x%p was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y);
return static_cast<INT_PTR>(TRUE);
break;
}
case IDC_BUTTON_CENTER:
{
logger.Out(L"%s(%d): Pressed the 'Center' button", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE;
if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
else hFgWnd = NULL;
return static_cast<INT_PTR>(TRUE);
break; break;
} }
case IDCANCEL: case IDCANCEL:
case IDC_BUTTON_CLOSE: case IDC_BUTTON_CLOSE:
{ {
logger.Out(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
diag_log(L"Closing 'Manual editing' dialog");
break; break;
} }
} }
break;
} }
} return FALSE;
return static_cast<INT_PTR>(FALSE);
} }
BOOL IsWindowApprooved(HWND hFW) { BOOL CheckWindow(HWND hFW)
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__)); {
diag_log(L"Entering CheckWindow(), hwnd=", hFW);
BOOL bApprooved = FALSE; GetClassNameW(hFW, szWinClass, _countof(szWinClass));
if (hFW) { if (hFW)
if (GetWindowTextW(hFW, reinterpret_cast<LPWSTR>(szWinTitleBuffer), MAX_WINTITLE_BUFFER_LENGTH)) { {
logger.Out(L"%s(%d): Window handle: 0x%p. Title: '%s'", TEXT(__FUNCTION__), __LINE__, hFW, reinterpret_cast<LPWSTR>(szWinTitleBuffer)); if (wcscmp(szWinClass, szWinCore) != 0)
{
if (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman)
{
if (!IsIconic(hFW) && !IsZoomed(hFW))
{
GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR));
diag_log(L"Window with hwnd=", hFW, L"is approved");
return TRUE;
} }
else ShowError(IDS_ERR_MAXMIN);
if (IsIconic(hFW)) {
logger.Out(L"%s(%d): The window is iconified", TEXT(__FUNCTION__), __LINE__);
}
if (IsZoomed(hFW)) {
logger.Out(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)) {
logger.Out(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__);
bApprooved = TRUE;
}
else ShowError(IDS_ERR_MAXMIN, szTitle);
}
else {
logger.Out(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__);
} }
} }
if (!bApprooved) {
logger.Out(L"%s(%d): The window is not approved!", TEXT(__FUNCTION__), __LINE__);
} }
diag_log(L"Window with hwnd=", hFW, L"is not approved!");
logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__)); diag_log(L"Quiting CheckWindow()");
return FALSE;
return bApprooved;
} }
VOID HandlingTrayIcon() { VOID HandlingTrayIcon()
logger.Out(L"Entering the %s() function, fShowIcon = %s", TEXT(__FUNCTION__), fShowIcon ? L"True" : L"False"); {
diag_log(L"Entering HandlingTrayIcon(), bShowIcon =", bShowIcon);
if (fShowIcon) { if (bShowIcon)
{
BOOL bResult1 = Shell_NotifyIconW(NIM_ADD, &nid); BOOL bResult1 = Shell_NotifyIconW(NIM_ADD, &nid);
logger.Out(L"%s(%d): Shell_NotifyIconW(NIM_ADD) returned %s", TEXT(__FUNCTION__), __LINE__, bResult1 ? L"True" : L"False"); diag_log(L"Shell_NotifyIconW(NIM_ADD):", bResult1);
BOOL bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid); BOOL bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid);
logger.Out(L"%s(%d): Shell_NotifyIconW(NIM_SETVERSION) returned %s", TEXT(__FUNCTION__), __LINE__, bResult2 ? L"True" : L"False"); diag_log(L"Shell_NotifyIconW(NIM_SETVERSION):", bResult2);
if (!bResult1 || !bResult2)
if (!bResult1 || !bResult2) { {
logger.Out(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__); diag_log(L"Error creating trayicon.");
ShowError(IDS_ERR_ICON);
ShowError(IDS_ERR_ICON, szTitle); bShowIcon = FALSE;
Shell_NotifyIconW(NIM_DELETE, &nid);
fShowIcon = FALSE;
} }
} }
else { else
{
Shell_NotifyIconW(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
} }
diag_log(L"Quiting HandlingTrayIcon()");
logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
} }
VOID ShowError(UINT uID, LPCWSTR szAppTitle) { VOID ShowError(UINT uID)
{
WCHAR szErrorText[MAX_LOADSTRING]; // Error's text WCHAR szErrorText[MAX_LOADSTRING]; // Error's text
LoadStringW(GetModuleHandleW(NULL), uID, szErrorText, _countof(szErrorText)); LoadStringW(hInst, uID, szErrorText, _countof(szErrorText));
MessageBoxW(hFgWnd, szErrorText, szAppTitle, MB_OK | MB_ICONERROR | MB_TOPMOST); MessageBoxW(hWnd, szErrorText, szTitle, MB_OK | MB_ICONERROR | MB_TOPMOST);
} }
VOID ShowPopupMenu(HWND hMainWnd, POINT pt) { INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
SetForegroundWindow(hMainWnd); {
UINT uFlags = TPM_RIGHTBUTTON; INITCOMMONCONTROLSEX icex = { 0 };
GetSystemMetrics(SM_MENUDROPALIGNMENT) != 0 ? uFlags |= TPM_RIGHTALIGN : uFlags |= TPM_LEFTALIGN; icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
TrackPopupMenuEx(hPopup, uFlags, pt.x, pt.y, hMainWnd, NULL); icex.dwICC = ICC_LINK_CLASS;
PostMessageW(hMainWnd, WM_NULL, 0, 0); InitCommonControlsEx(&icex);
}
HRESULT CALLBACK AboutCallback(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, LONG_PTR lpRefData) { switch (message)
if (TDN_HYPERLINK_CLICKED == uMsg) { {
ShellExecuteW(hDlg, L"open", reinterpret_cast<LPCWSTR>(lParam), NULL, NULL, SW_SHOW); case WM_INITDIALOG:
{
SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAbout);
return (INT_PTR)TRUE;
break;
} }
return S_OK;
case WM_NOTIFY:
{
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(L"Pressed donation link");
return (INT_PTR)TRUE;
}
break;
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
diag_log(L"Closing 'About' dialog");
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
} }

View File

@@ -1,43 +1,3 @@
// wCenterWindow
// wCenterWindow.h
#pragma once #pragma once
#include "resource.h" #include "resource.h"
#define T0 10
#define T1 60
#define T2 86400
#ifdef _WIN64
#define ARCH 64
#else
#define ARCH 86
#endif
#define MAX_LOADSTRING 64
// Windows Header Files
#include <fstream>
#include <sstream>
#include <filesystem>
#include <string>
#include <vector>
#include <strsafe.h>
#include <windows.h>
#include <windowsx.h>
#include <wininet.h>
#include <shellapi.h>
#include <CommCtrl.h>
#include <process.h>
// Logger header file
#include "CLogger.h"
// VerionInfo header file
#include "VersionInfo.h"
// wCenterWindow's title
extern WCHAR szTitle[MAX_LOADSTRING];
// An instance of the "CLogger" class
extern CLogger logger;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -3,6 +3,13 @@
<description>Centers windows by hotkey (C++)</description> <description>Centers windows by hotkey (C++)</description>
<assemblyIdentity
version="2.3.3.0"
processorArchitecture="x86"
name="W0LF.wCenterWindow.C++"
type="win32">
</assemblyIdentity>
<dependency> <dependency>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity <assemblyIdentity
@@ -25,18 +32,11 @@
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--ID Windows 8.1 --> <!--ID Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--ID Windows 10/11 --> <!--ID Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application> </application>
</compatibility> </compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings> <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware> </windowsSettings>
<windowsSettings> <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness> </windowsSettings>
<windowsSettings> <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware> </windowsSettings>
<windowsSettings> <heapType xmlns="http://schemas.microsoft.com/SMI/2020/WindowsSettings">SegmentHeap</heapType> </windowsSettings>
</application>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security> <security>
<requestedPrivileges> <requestedPrivileges>

Binary file not shown.

View File

@@ -73,25 +73,16 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<EnableMicrosoftCodeAnalysis>false</EnableMicrosoftCodeAnalysis>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<CopyCppRuntimeToOutputDir>false</CopyCppRuntimeToOutputDir> <CopyCppRuntimeToOutputDir>false</CopyCppRuntimeToOutputDir>
<CopyLocalDeploymentContent>false</CopyLocalDeploymentContent>
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDebugSymbols>false</CopyLocalDebugSymbols>
<EnableMicrosoftCodeAnalysis>false</EnableMicrosoftCodeAnalysis>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<CopyLocalDeploymentContent>false</CopyLocalDeploymentContent>
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDebugSymbols>false</CopyLocalDebugSymbols>
<CopyCppRuntimeToOutputDir>false</CopyCppRuntimeToOutputDir>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@@ -104,16 +95,11 @@
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<Manifest> <Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles> <AdditionalManifestFiles>$(ProjectName).manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
<ManifestFromManagedAssembly>
</ManifestFromManagedAssembly>
</Manifest> </Manifest>
<PreBuildEvent>
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
@@ -122,8 +108,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>false</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
@@ -131,14 +117,11 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<Manifest> <Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles> <AdditionalManifestFiles>$(ProjectName).manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest> </Manifest>
<PreBuildEvent>
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
@@ -151,15 +134,8 @@
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link> </Link>
<Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PreBuildEvent>
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
@@ -170,48 +146,36 @@
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link> </Link>
<Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PreBuildEvent>
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="CLogger.h" />
<ClInclude Include="framework.h" /> <ClInclude Include="framework.h" />
<ClInclude Include="picojson.h" /> <ClInclude Include="Logger.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="Resource.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
<ClInclude Include="updater.h" />
<ClInclude Include="wCenterWindow.h" /> <ClInclude Include="wCenterWindow.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CLogger.cpp" /> <ClCompile Include="Logger.cpp" />
<ClCompile Include="updater.cpp" />
<ClCompile Include="wCenterWindow.cpp" /> <ClCompile Include="wCenterWindow.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="wCenterWindow.rc" /> <ResourceCompile Include="wCenterWindow.rc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="small.ico" />
<Image Include="wCenterWindow.ico" /> <Image Include="wCenterWindow.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Manifest Include="wCenterWindow.exe.manifest" /> <Manifest Include="wCenterWindow.manifest" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@@ -27,13 +27,7 @@
<ClInclude Include="wCenterWindow.h"> <ClInclude Include="wCenterWindow.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="picojson.h"> <ClInclude Include="Logger.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="updater.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CLogger.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
@@ -41,10 +35,7 @@
<ClCompile Include="wCenterWindow.cpp"> <ClCompile Include="wCenterWindow.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="updater.cpp"> <ClCompile Include="Logger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CLogger.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
@@ -54,16 +45,16 @@
</ResourceCompile> </ResourceCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="small.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="wCenterWindow.ico"> <Image Include="wCenterWindow.ico">
<Filter>Resource Files</Filter> <Filter>Resource Files</Filter>
</Image> </Image>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Manifest Include="wCenterWindow.exe.manifest"> <Manifest Include="wCenterWindow.manifest">
<Filter>Resource Files</Filter> <Filter>Resource Files</Filter>
</Manifest> </Manifest>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,21 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>/noupdate</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>/test1 /test2</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>/noupdate</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
</Project> </Project>