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
17 changed files with 424 additions and 688 deletions

3
.gitignore vendored
View File

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

View File

@@ -1,22 +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).
This program centers the current active window by a `LCTRL + LWIN + C` hotkey,
or pressing `LCTRL + LWIN + MMB` (Middle Mouse Button).
```LCTRL + LWIN + V``` - manual editing of size and position of the window.
`LCTRL + LWIN + V` - manual editing of size and position of the window.
You can use ```LCTRL + LWIN + I``` hotkey for hide/show trayicon.
You can also use commandline option ```/hide``` for hide trayicon at startup.
You can use `LCTRL + LWIN + I` hotkey for hide/show trayicon.
You can also use commandline option `/hide` for hide trayicon at startup.
`Use workarea` option means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used.
```Use workarea``` option 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').\
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.\
**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".

View File

@@ -1,173 +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]$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 (-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
$verRevision = $config.Revision
$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 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
$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"
$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
"// 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 " 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

Binary file not shown.

View File

@@ -1,19 +0,0 @@
@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
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

View File

@@ -1,15 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
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
Version.ini = Version.ini
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64

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();
}
}

View File

@@ -1,71 +1,60 @@
// 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__);
// wCenterWindow, v2.3.3
// Logger.h
//
#pragma once
#include "framework.h"
#define DBUFLEN 256
#define LOG_TO_FILE(fmt, ...) do { StringCchPrintfW(debugBuffer, DBUFLEN, fmt, ##__VA_ARGS__); logfile << GetTimeStamp() << debugBuffer << std::endl; } while (0)
extern std::wofstream logfile;
std::wstring GetTimeStamp();
std::wstring PrintTitle();
SYSTEMTIME lt;
wchar_t debugTimeBuffer[32];
wchar_t debugBuffer[DBUFLEN];
std::wofstream logfile;
extern wchar_t szTitle[];
wchar_t* GetTimeStamp()
template <typename T1>
void diag_log(T1 arg1)
{
GetLocalTime(&lt);
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;
logfile << GetTimeStamp() << arg1 << std::endl;
}
void OpenLogFile()
template <typename T1, typename T2>
void diag_log(T1 arg1, T2 arg2)
{
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;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << std::endl;
}
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())
template <typename T1, typename T2, typename T3>
void diag_log(T1 arg1, T2 arg2, T3 arg3)
{
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;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << std::endl;
}
void CloseLogFile()
template <typename T1, typename T2, typename T3, typename T4>
void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
if (logfile)
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() << "[ " << szTitle << " ] Stop log." << std::endl;
logfile.close();
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,11 +1,14 @@
// wCenterWindow
// framework.h
// header.h : include file for standard system include files,
// or project specific include files
//
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
@@ -14,10 +17,10 @@
#include <shellapi.h>
#include <CommCtrl.h>
// Project Specific Header Files
#include "logger.h"
#include "VersionInfo.h"
// C RunTime Header Files
//#include <stdlib.h>
//#include <malloc.h>
//#include <memory.h>
// Extern variables
#define MAX_LOADSTRING 50
WCHAR szTitle[MAX_LOADSTRING]; // wCenterWindow's title
// Project Specific Header Files
#include "Logger.h"

View File

@@ -13,13 +13,12 @@
#define ID_POPUPMENU_EXIT 111
#define IDS_ABOUT 112
#define IDS_ERR_MAIN 113
#define IDS_ERR_CLASS 114
#define IDS_ERR_WND 115
#define IDS_ERR_ICON 116
#define IDS_ERR_MENU 117
#define IDS_ERR_POPUP 118
#define IDS_ERR_HOOK 119
#define IDS_ERR_MAXMIN 120
#define IDS_ERR_WND 114
#define IDS_ERR_ICON 115
#define IDS_ERR_MENU 116
#define IDS_ERR_POPUP 117
#define IDS_ERR_HOOK 118
#define IDS_ERR_MAXMIN 119
#define IDS_RUNNING 121
#define IDR_MAINFRAME 128
#define IDD_MANUAL_EDITING 129
@@ -33,10 +32,6 @@
#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 IDC_ABOUTEDIT 1013
#define IDC_STATIC -1
// Next default values for new objects
@@ -46,7 +41,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1014
#define _APS_NEXT_CONTROL_VALUE 1010
#define _APS_NEXT_SYMED_VALUE 122
#endif
#endif

View File

@@ -1,29 +1,33 @@
// wCenterWindow
// wCenterWindow.cpp
// wCenterWindow, v2.3.3
//
// TODO: More verbose logs - partially done.
// TODO: More verbose error messages
// TODO: Window's title in logs (Impossible?)
#include "framework.h"
#include "logger.h"
#include "wCenterWindow.h"
#define NO_DONATION
#define KEY_I 0x49
#define KEY_C 0x43
#define KEY_V 0x56
#define BUF_LEN 1024
#define BUF_LEN 4096
#define MAX_LOADSTRING 50
#define WM_WCW 0x8F00
// Global variables:
HINSTANCE hInst; // Instance
extern WCHAR szTitle[];
WCHAR szTitle[MAX_LOADSTRING]; // Window's title
WCHAR szClass[MAX_LOADSTRING]; // Window's class
WCHAR szAbout[MAX_LOADSTRING * 12]; // Description text
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;
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;
@@ -40,23 +44,26 @@ 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 CheckWindow(HWND);
BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
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);
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
{
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
//diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd, L"Title:", (LPWSTR)szBuffer);
diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd);
RECT fgwrc = { 0 };
GetWindowRect(hwnd, &fgwrc);
LONG nWidth = fgwrc.right - fgwrc.left;
LONG nHeight = fgwrc.bottom - fgwrc.top;
LOG_TO_FILE(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 };
mi.cbSize = sizeof(MONITORINFO);
@@ -90,12 +97,34 @@ VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
MoveWindow(hwnd, x, y, nWidth, nHeight, TRUE);
SendMessageW(hwnd, WM_EXITSIZEMOVE, NULL, NULL);
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__));
diag_log(L"Moving window to x =", x, L"y =", y);
diag_log(L"Quiting MoveWindowToMonitorCenter()");
}
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));
@@ -107,27 +136,8 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
return FALSE;
}
OpenLogFile();
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
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;
hIcon = wcex.hIcon;
if (!RegisterClassExW(&wcex))
{
ShowError(IDS_ERR_CLASS);
return FALSE;
}
hWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
MyRegisterClass(hInstance);
hWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
if (!hWnd)
{
ShowError(IDS_ERR_WND);
@@ -137,11 +147,10 @@ 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);
diag_log(L"Arguments:", nArgs - 1);
for (int i = 1; i < nArgs; i++)
{
LOG_TO_FILE(L"Argument %d: %s", i, szArglist[i]);
diag_log(L"Argument", i, L":", szArglist[i]);
}
(nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], L"/hide")) ? bShowIcon = FALSE : bShowIcon = TRUE;
@@ -151,6 +160,10 @@ 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;
@@ -172,10 +185,8 @@ 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);
diag_log(L"Quiting WinMain(), msg.wParam =", (int)msg.wParam);
CloseLogFile();
HeapFree(hHeap, NULL, szBuffer);
@@ -188,25 +199,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_CREATE:
{
LOG_TO_FILE(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__);
hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
if (!hMenu)
{
LOG_TO_FILE(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Loading context menu failed!");
ShowError(IDS_ERR_MENU);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
LOG_TO_FILE(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Context menu successfully loaded");
hPopup = GetSubMenu(hMenu, 0);
if (!hPopup)
{
LOG_TO_FILE(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Creating popup menu failed!");
ShowError(IDS_ERR_POPUP);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
LOG_TO_FILE(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Popup menu successfully created");
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
@@ -220,91 +229,67 @@ 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
hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
if (!hMouseHook)
{
LOG_TO_FILE(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Creating mouse hook failed!");
ShowError(IDS_ERR_HOOK);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
LOG_TO_FILE(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
#endif // !_DEBUG
diag_log(L"Mouse hook was successfully set");
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
if (!hKbdHook)
{
LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Creating keyboard hook failed!");
ShowError(IDS_ERR_HOOK);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
LOG_TO_FILE(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Keyboard hook was successfully set");
LoadStringW(hInst, IDS_ABOUT, szAbout, _countof(szAbout));
break;
}
case WM_WCW: // Popup menu handler
case WM_WCW:
{
if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam))
if ((lParam == WM_RBUTTONDOWN || lParam == WM_LBUTTONDOWN) && wParam == IDI_TRAYICON)
{
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)
if (idMenu == ID_POPUPMENU_ICON)
{
LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__);
bShowIcon = FALSE;
HandlingTrayIcon();
}
if (ID_POPUPMENU_AREA == idMenu)
if (idMenu == ID_POPUPMENU_AREA)
{
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);
LOG_TO_FILE(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);
}
if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed)
if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed)
{
LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE;
diag_log(L"Opening 'About' dialog");
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
bKPressed = FALSE;
}
if (ID_POPUPMENU_EXIT == idMenu)
{
LOG_TO_FILE(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
if (idMenu == ID_POPUPMENU_EXIT) SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
}
LOG_TO_FILE(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
}
break;
}
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;
}
case WM_DESTROY:
{
LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
PostQuitMessage(0);
break;
}
@@ -317,14 +302,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, 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;
if (wParam == WM_MBUTTONDOWN && bLCTRL && bLWIN && !bMPressed)
{
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Pressed LCTRL + LWIN + MMB");
bMPressed = TRUE;
hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
BOOL bApproved = CheckWindow(hFgWnd);
if (bApproved) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
else hFgWnd = NULL;
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
@@ -333,49 +318,48 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
pkhs = (KBDLLHOOKSTRUCT*)lParam;
if (WM_KEYUP == wParam)
if (wParam == WM_KEYUP)
{
if (VK_LCONTROL == pkhs->vkCode) bLCTRL = FALSE;
if (VK_LWIN == pkhs->vkCode) bLWIN = FALSE;
if (pkhs->vkCode == VK_LCONTROL) bLCTRL = FALSE;
if (pkhs->vkCode == VK_LWIN) bLWIN = 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;
if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key
if (bLCTRL && bLWIN && pkhs->vkCode == KEY_I && !bKPressed) // 'I' key
{
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Pressed LCTRL + LWIN + I");
bKPressed = TRUE;
bShowIcon = !bShowIcon;
HandlingTrayIcon();
return TRUE;
}
if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key
if (bLCTRL && bLWIN && pkhs->vkCode == KEY_C && !bKPressed && !bKEYV) // 'C' key
{
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Pressed LCTRL + LWIN + C");
bKPressed = TRUE;
hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd)) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
BOOL bApproved = CheckWindow(hFgWnd);
if (bApproved) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE);
else hFgWnd = NULL;
return TRUE;
}
if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key
if (bLCTRL && bLWIN && pkhs->vkCode == KEY_V && !bKPressed && !bKEYV) // 'V' key
{
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Pressed LCTRL + LWIN + V");
bKPressed = TRUE; bKEYV = TRUE;
hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd))
BOOL bApproved = CheckWindow(hFgWnd);
if (bApproved)
{
LOG_TO_FILE(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Opening 'Manual editing' dialog");
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc);
SetForegroundWindow(hFgWnd);
}
@@ -394,8 +378,6 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
{
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));
@@ -413,14 +395,11 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
UpdateWindow(hDlg);
break;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BUTTON_SET:
{
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);
@@ -428,18 +407,14 @@ 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);
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:
{
LOG_TO_FILE(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
EndDialog(hDlg, LOWORD(wParam));
diag_log(L"Closing 'Manual editing' dialog");
break;
}
}
@@ -447,93 +422,59 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
BOOL IsWindowApprooved(HWND hFW)
BOOL CheckWindow(HWND hFW)
{
LOG_TO_FILE(L"Entering the %s() function, handle = 0x%08X", TEXT(__FUNCTION__), hFW);
bool bApprooved = FALSE;
diag_log(L"Entering CheckWindow(), hwnd=", hFW);
GetClassNameW(hFW, szWinClass, _countof(szWinClass));
if (hFW)
{
if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR)))
if (wcscmp(szWinClass, szWinCore) != 0)
{
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 (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman)
{
if (!IsIconic(hFW) && !IsZoomed(hFW))
{
LOG_TO_FILE(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__);
bApprooved = TRUE;
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);
}
else
{
LOG_TO_FILE(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__);
}
}
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;
diag_log(L"Window with hwnd=", hFW, L"is not approved!");
diag_log(L"Quiting CheckWindow()");
return FALSE;
}
VOID HandlingTrayIcon()
{
LOG_TO_FILE(L"Entering the %s() function, bShowIcon = %s", TEXT(__FUNCTION__), bShowIcon ? L"True" : L"False");
diag_log(L"Entering HandlingTrayIcon(), bShowIcon =", bShowIcon);
if (bShowIcon)
{
bool bResult1 = Shell_NotifyIconW(NIM_ADD, &nid);
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);
LOG_TO_FILE(L"%s(%d): Shell_NotifyIconW(NIM_SETVERSION): %s", TEXT(__FUNCTION__), __LINE__, bResult2 ? L"True" : L"False");
BOOL bResult1 = Shell_NotifyIconW(NIM_ADD, &nid);
diag_log(L"Shell_NotifyIconW(NIM_ADD):", bResult1);
BOOL bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid);
diag_log(L"Shell_NotifyIconW(NIM_SETVERSION):", bResult2);
if (!bResult1 || !bResult2)
{
LOG_TO_FILE(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Error creating trayicon.");
ShowError(IDS_ERR_ICON);
Shell_NotifyIconW(NIM_DELETE, &nid);
bShowIcon = FALSE;
}
else
{
Shell_NotifyIconW(NIM_MODIFY, &nid);
}
}
else
{
Shell_NotifyIconW(NIM_DELETE, &nid);
}
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__));
diag_log(L"Quiting HandlingTrayIcon()");
}
VOID ShowError(UINT uID)
{
WCHAR szErrorText[MAX_LOADSTRING]; // Error's text
LoadStringW(hInst, uID, szErrorText, _countof(szErrorText));
MessageBoxW(NULL, szErrorText, szTitle, MB_OK | MB_ICONERROR | MB_TOPMOST);
MessageBoxW(hWnd, szErrorText, szTitle, MB_OK | MB_ICONERROR | MB_TOPMOST);
}
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
@@ -547,27 +488,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
{
LOG_TO_FILE(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
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, ABOUT_BUILD, _countof(ABOUT_BUILD), 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);
SetDlgItemTextW(hDlg, IDC_ABOUTEDIT, szAboutHelp);
#ifdef NO_DONATION
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__);
SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAbout);
return (INT_PTR)TRUE;
break;
}
@@ -580,26 +501,20 @@ 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);
LOG_TO_FILE(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Pressed donation link");
return (INT_PTR)TRUE;
}
break;
}
case WM_COMMAND:
{
if (IDOK == LOWORD(wParam) || IDCANCEL == LOWORD(wParam))
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
LOG_TO_FILE(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
diag_log(L"Closing 'About' dialog");
return (INT_PTR)TRUE;
}
break;
}
}
return (INT_PTR)FALSE;
}

View File

@@ -1,4 +1,3 @@
// wCenterWindow
// wCenterWindow.h
#pragma once
#include "resource.h"

View File

@@ -3,6 +3,13 @@
<description>Centers windows by hotkey (C++)</description>
<assemblyIdentity
version="2.3.3.0"
processorArchitecture="x86"
name="W0LF.wCenterWindow.C++"
type="win32">
</assemblyIdentity>
<dependency>
<dependentAssembly>
<assemblyIdentity
@@ -25,18 +32,11 @@
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--ID Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--ID Windows 10/11 -->
<!--ID Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</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">
<security>
<requestedPrivileges>

Binary file not shown.

View File

@@ -73,25 +73,16 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<EnableMicrosoftCodeAnalysis>false</EnableMicrosoftCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<CopyCppRuntimeToOutputDir>false</CopyCppRuntimeToOutputDir>
<CopyLocalDeploymentContent>false</CopyLocalDeploymentContent>
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDebugSymbols>false</CopyLocalDebugSymbols>
<EnableMicrosoftCodeAnalysis>false</EnableMicrosoftCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<CopyLocalDeploymentContent>false</CopyLocalDeploymentContent>
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDebugSymbols>false</CopyLocalDebugSymbols>
<CopyCppRuntimeToOutputDir>false</CopyCppRuntimeToOutputDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@@ -107,13 +98,8 @@
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
<ManifestFromManagedAssembly>
</ManifestFromManagedAssembly>
<AdditionalManifestFiles>$(ProjectName).manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PreBuildEvent>
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@@ -122,8 +108,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>false</ConformanceMode>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
@@ -134,11 +120,8 @@
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
<AdditionalManifestFiles>$(ProjectName).manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PreBuildEvent>
<Command>powershell -ExecutionPolicy RemoteSigned -File "$(SolutionDir)Update_Version.ps1" &amp;&amp; move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@@ -153,12 +136,6 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PreBuildEvent>
<Command>powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@@ -169,30 +146,25 @@
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PreBuildEvent>
<Command>powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="logger.h" />
<ClInclude Include="Logger.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="wCenterWindow.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Logger.cpp" />
<ClCompile Include="wCenterWindow.cpp" />
</ItemGroup>
<ItemGroup>
@@ -203,10 +175,7 @@
<Image Include="wCenterWindow.ico" />
</ItemGroup>
<ItemGroup>
<Manifest Include="wCenterWindow.exe.manifest" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
<Manifest Include="wCenterWindow.manifest" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -27,7 +27,7 @@
<ClInclude Include="wCenterWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="logger.h">
<ClInclude Include="Logger.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
@@ -35,6 +35,9 @@
<ClCompile Include="wCenterWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Logger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="wCenterWindow.rc">
@@ -50,11 +53,8 @@
</Image>
</ItemGroup>
<ItemGroup>
<Manifest Include="wCenterWindow.exe.manifest">
<Manifest Include="wCenterWindow.manifest">
<Filter>Resource Files</Filter>
</Manifest>
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
</ItemGroup>
</Project>