Some improovements
This commit is contained in:
2022-01-14 17:32:17 +03:00
parent d1ab2b86e2
commit 166cdd0d88
6 changed files with 94 additions and 91 deletions

View File

@@ -1,16 +1,13 @@
// wCenterWindow, v2.3.1
// Logger.cpp // Logger.cpp
// //
#include <fstream> #include "framework.h"
#include <filesystem>
#include <string>
#include <strsafe.h>
#include <Windows.h>
#include "Logger.h"
#define TS_LEN 30 #define TS_LEN 30
#define PATH_LEN 1024 #define PATH_LEN 1024
std::wofstream logfile; std::wofstream logfile;
extern WCHAR szTitle[];
extern LPVOID szBuffer; extern LPVOID szBuffer;
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -24,20 +21,20 @@ std::wstring GetTimeStamp() {
SYSTEMTIME lt; SYSTEMTIME lt;
GetLocalTime(&lt); GetLocalTime(&lt);
wchar_t ts[TS_LEN]; wchar_t ts[TS_LEN];
StringCchPrintf(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); 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; return ts;
} }
void OpenLogFile() { void OpenLogFile() {
wchar_t lpszPath[PATH_LEN]{}; wchar_t lpszPath[PATH_LEN]{};
DWORD dwPathLength = GetModuleFileName(NULL, lpszPath, PATH_LEN); DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, PATH_LEN);
DWORD dwError = GetLastError(); DWORD dwError = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == dwError) { if (ERROR_INSUFFICIENT_BUFFER == dwError) {
MessageBoxW(NULL, L"Path to logfile is too long! Working without logging.", L"WARNING", MB_OK | MB_ICONWARNING); MessageBoxW(NULL, L"Path to logfile is too long! Working without logging.", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING);
return; return;
} }
if (NULL == dwPathLength) { if (NULL == dwPathLength) {
MessageBoxW(NULL, L"Can't get module filename! Working without logging.", L"WARNING", MB_OK | MB_ICONWARNING); MessageBoxW(NULL, L"Can't get module filename! Working without logging.", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING);
return; return;
} }
@@ -52,18 +49,18 @@ void OpenLogFile() {
#endif #endif
logfile.open(log_path); logfile.open(log_path);
if (logfile.is_open()) { if (logfile.is_open()) {
diag_log(L"Starting logging."); diag_log(L"Start logging.");
diag_log(L"logfile:", log_path); diag_log(L"Logfile:", log_path);
diag_log(log_path, L"successfully opened."); diag_log(log_path, L"successfully opened.");
} else { } else {
MessageBoxW(NULL, L"Can't open logfile! Working without logging.", L"WARNING", MB_OK | MB_ICONWARNING); MessageBoxW(NULL, L"Can't open logfile! Working without logging.", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING);
} }
return; return;
} }
void CloseLogFile() { void CloseLogFile() {
if (logfile) { if (logfile) {
diag_log(L"Ending logging."); diag_log(L"End logging.");
logfile.close(); logfile.close();
} }
} }

View File

@@ -1,6 +1,8 @@
// wCenterWindow, v2.3.1
// Logger.h
//
#pragma once #pragma once
#include <iostream> #include "framework.h"
#include <fstream>
extern std::wofstream logfile; extern std::wofstream logfile;
std::wstring GetTimeStamp(); std::wstring GetTimeStamp();
@@ -8,25 +10,21 @@ std::wstring PrintTitle();
template <typename T1> template <typename T1>
void diag_log(T1 arg1) { void diag_log(T1 arg1) {
//std::wcout << GetTimeStamp() << arg1 << std::endl;
logfile << GetTimeStamp() << arg1 << std::endl; logfile << GetTimeStamp() << arg1 << std::endl;
} }
template <typename T1, typename T2> template <typename T1, typename T2>
void diag_log(T1 arg1, T2 arg2) { void diag_log(T1 arg1, T2 arg2) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << std::endl;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << std::endl; logfile << GetTimeStamp() << arg1 << ' ' << arg2 << std::endl;
} }
template <typename T1, typename T2, typename T3> template <typename T1, typename T2, typename T3>
void diag_log(T1 arg1, T2 arg2, T3 arg3) { void diag_log(T1 arg1, T2 arg2, T3 arg3) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << std::endl;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << std::endl; logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << std::endl;
} }
template <typename T1, typename T2, typename T3, typename T4> template <typename T1, typename T2, typename T3, typename T4>
void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4) { void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << std::endl;
//if (typeid(T4) == typeid(WCHAR)) { //if (typeid(T4) == typeid(WCHAR)) {
// logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << PrintTitle() << std::endl; // logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << PrintTitle() << std::endl;
// return; // return;
@@ -36,25 +34,21 @@ void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
template <typename T1, typename T2, typename T3, typename T4, typename T5> template <typename T1, typename T2, typename T3, typename T4, typename T5>
void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << std::endl;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << std::endl; logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << std::endl;
} }
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> 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) { void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << std::endl;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << std::endl; 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> 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) { void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << ' ' << arg7 << std::endl;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << ' ' << arg7 << std::endl; 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> 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) { void diag_log(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) {
//std::wcout << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << ' ' << arg7 << ' ' << arg8 << std::endl;
logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << ' ' << arg7 << ' ' << arg8 << std::endl; logfile << GetTimeStamp() << arg1 << ' ' << arg2 << ' ' << arg3 << ' ' << arg4 << ' ' << arg5 << ' ' << arg6 << ' ' << arg7 << ' ' << arg8 << std::endl;
} }

View File

@@ -7,11 +7,18 @@
#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 // Windows Header Files
#include <windows.h> #include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
#include <strsafe.h> #include <strsafe.h>
#include <windows.h>
#include <CommCtrl.h> #include <CommCtrl.h>
// C RunTime Header Files // C RunTime Header Files
#include <stdlib.h> //#include <stdlib.h>
#include <malloc.h> //#include <malloc.h>
#include <memory.h> //#include <memory.h>
#include <tchar.h>
// Project Specific Header Files
#include "Logger.h"

View File

@@ -1,4 +1,4 @@
// wCenterWindow, v2.3 // wCenterWindow, v2.3.1
// //
// TODO: More verbose logs - partially done. // TODO: More verbose logs - partially done.
// TODO: More verbose error messages // TODO: More verbose error messages
@@ -6,7 +6,6 @@
#include "framework.h" #include "framework.h"
#include "wCenterWindow.h" #include "wCenterWindow.h"
#include "Logger.h"
#define KEY_I 0x49 #define KEY_I 0x49
#define KEY_C 0x43 #define KEY_C 0x43
@@ -18,12 +17,12 @@
// Global variables: // Global variables:
HINSTANCE hInst; // Instance HINSTANCE hInst; // Instance
TCHAR szTitle[MAX_LOADSTRING]; // Window's title WCHAR szTitle[MAX_LOADSTRING]; // Window's title
TCHAR szClass[MAX_LOADSTRING]; // Window's class WCHAR szClass[MAX_LOADSTRING]; // Window's class
TCHAR szAbout[MAX_LOADSTRING * 12]; // Description text WCHAR szAbout[MAX_LOADSTRING * 12]; // Description text
TCHAR szWinTitle[256]; WCHAR szWinTitle[256];
TCHAR szWinClass[256]; WCHAR szWinClass[256];
TCHAR szWinCore[] = TEXT("Windows.UI.Core.CoreWindow"); WCHAR szWinCore[] = TEXT("Windows.UI.Core.CoreWindow");
HANDLE hHeap = NULL; HANDLE hHeap = NULL;
HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles
HICON hIcon = NULL; HICON hIcon = NULL;
@@ -56,12 +55,12 @@ ATOM MyRegisterClass(HINSTANCE hInstance) {
wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = WndProc; wcex.lpfnWndProc = WndProc;
wcex.hInstance = hInstance; wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TRAYICON)); wcex.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_TRAYICON));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
wcex.lpszClassName = szClass; wcex.lpszClassName = szClass;
wcex.hIconSm = wcex.hIcon; wcex.hIconSm = wcex.hIcon;
hIcon = wcex.hIcon; hIcon = wcex.hIcon;
return RegisterClassEx(&wcex); return RegisterClassExW(&wcex);
} }
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) { VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) {
@@ -76,7 +75,7 @@ VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) {
MONITORINFO mi; MONITORINFO mi;
mi.cbSize = sizeof(MONITORINFO); mi.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi); GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi);
RECT area; RECT area;
if (bWorkArea) { if (bWorkArea) {
area.bottom = mi.rcWork.bottom; area.bottom = mi.rcWork.bottom;
@@ -99,9 +98,9 @@ VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) {
int x = (aw - nWidth) / 2; int x = (aw - nWidth) / 2;
int y = (ah - nHeight) / 2; int y = (ah - nHeight) / 2;
SendMessage(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);
SendMessage(hwnd, WM_EXITSIZEMOVE, NULL, NULL); SendMessageW(hwnd, WM_EXITSIZEMOVE, NULL, NULL);
diag_log(L"Moving window to x =", x, L"y =", y); diag_log(L"Moving window to x =", x, L"y =", y);
diag_log(L"Quiting MoveWindowToMonitorCenter()"); diag_log(L"Quiting MoveWindowToMonitorCenter()");
@@ -109,7 +108,7 @@ VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) {
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);
@@ -118,16 +117,16 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
hInst = hInstance; hInst = hInstance;
LoadString(hInstance, IDS_APP_TITLE, szTitle, _countof(szTitle)); LoadStringW(hInstance, IDS_APP_TITLE, szTitle, _countof(szTitle));
LoadString(hInstance, IDS_CLASSNAME, szClass, _countof(szClass)); LoadStringW(hInstance, IDS_CLASSNAME, szClass, _countof(szClass));
if (FindWindow(szClass, NULL)) { if (FindWindowW(szClass, NULL)) {
ShowError(IDS_RUNNING); ShowError(IDS_RUNNING);
return FALSE; return FALSE;
} }
MyRegisterClass(hInstance); MyRegisterClass(hInstance);
hWnd = CreateWindowEx(0, szClass, szTitle, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); hWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) { if (!hWnd) {
ShowError(IDS_ERR_WND); ShowError(IDS_ERR_WND);
return FALSE; return FALSE;
@@ -136,38 +135,41 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
int nArgs = 0; int nArgs = 0;
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
diag_log(L"nArgs =", nArgs, L", Args: ", *szArglist); diag_log(L"Arguments:", nArgs);
for (int i = 0; i < nArgs; i++) {
diag_log(L"Argument", i, L":", szArglist[i]);
}
(nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], TEXT("/hide"))) ? bShowIcon = FALSE : bShowIcon = TRUE; (nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], L"/hide")) ? bShowIcon = FALSE : bShowIcon = TRUE;
LocalFree(szArglist); LocalFree(szArglist);
HandlingTrayIcon(); HandlingTrayIcon();
hHeap = GetProcessHeap(); hHeap = GetProcessHeap();
szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, BUF_LEN); szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, BUF_LEN);
hTaskBar = FindWindow(TEXT("Shell_TrayWnd"), NULL); hTaskBar = FindWindowW(L"Shell_TrayWnd", NULL);
hProgman = FindWindow(TEXT("Progman"), NULL); hProgman = FindWindowW(L"Progman", NULL);
hDesktop = GetDesktopWindow(); hDesktop = GetDesktopWindow();
MSG msg; MSG msg;
BOOL bRet; BOOL bRet;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) { while ((bRet = GetMessageW(&msg, NULL, 0, 0)) != 0) {
if (bRet == -1) { if (bRet == -1) {
ShowError(IDS_ERR_MAIN); ShowError(IDS_ERR_MAIN);
return -1; return -1;
} else { } else {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessageW(&msg);
} }
} }
if (hMouseHook) UnhookWindowsHookEx(hMouseHook); if (hMouseHook) UnhookWindowsHookEx(hMouseHook);
if (hKbdHook) UnhookWindowsHookEx(hKbdHook); if (hKbdHook) UnhookWindowsHookEx(hKbdHook);
if (hMenu) DestroyMenu(hMenu); if (hMenu) DestroyMenu(hMenu);
Shell_NotifyIcon(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
diag_log(L"Quiting WinMain(). msg.wParam =", (int)msg.wParam); diag_log(L"Quiting WinMain(), msg.wParam =", (int)msg.wParam);
CloseLogFile(); CloseLogFile();
HeapFree(hHeap, NULL, szBuffer); HeapFree(hHeap, NULL, szBuffer);
@@ -178,11 +180,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message) { switch (message) {
case WM_CREATE: case WM_CREATE:
{ {
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU)); hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
if (!hMenu) { if (!hMenu) {
diag_log(L"Loading context menu failed!"); diag_log(L"Loading context menu failed!");
ShowError(IDS_ERR_MENU); ShowError(IDS_ERR_MENU);
SendMessage(hWnd, WM_CLOSE, NULL, NULL); SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
diag_log(L"Context menu successfully loaded"); diag_log(L"Context menu successfully loaded");
@@ -190,14 +192,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (!hPopup) { if (!hPopup) {
diag_log(L"Creating popup menu failed!"); diag_log(L"Creating popup menu failed!");
ShowError(IDS_ERR_POPUP); ShowError(IDS_ERR_POPUP);
SendMessage(hWnd, WM_CLOSE, NULL, NULL); SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
diag_log(L"Popup menu successfully created"); diag_log(L"Popup menu successfully created");
mii.cbSize = sizeof(MENUITEMINFO); mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE; mii.fMask = MIIM_STATE;
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
nid.cbSize = sizeof(NOTIFYICONDATA); nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd; nid.hWnd = hWnd;
@@ -207,25 +209,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
nid.uID = IDI_TRAYICON; nid.uID = IDI_TRAYICON;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.dwInfoFlags = NIIF_INFO; nid.dwInfoFlags = NIIF_INFO;
StringCchCopy(nid.szTip, _countof(nid.szTip), szTitle); StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle);
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, hInst, NULL); hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
if (!hMouseHook) { if (!hMouseHook) {
diag_log(L"Creating mouse hook failed!"); diag_log(L"Creating mouse hook failed!");
ShowError(IDS_ERR_HOOK); ShowError(IDS_ERR_HOOK);
SendMessage(hWnd, WM_CLOSE, NULL, NULL); SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
diag_log(L"Mouse hook was successfully set"); diag_log(L"Mouse hook was successfully set");
hKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
if (!hKbdHook) { if (!hKbdHook) {
diag_log(L"Creating keyboard hook failed!"); diag_log(L"Creating keyboard hook failed!");
ShowError(IDS_ERR_HOOK); ShowError(IDS_ERR_HOOK);
SendMessage(hWnd, WM_CLOSE, NULL, NULL); SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
diag_log(L"Keyboard hook was successfully set"); diag_log(L"Keyboard hook was successfully set");
LoadString(hInst, IDS_ABOUT, szAbout, _countof(szAbout)); LoadStringW(hInst, IDS_ABOUT, szAbout, _countof(szAbout));
} }
break; break;
@@ -243,16 +245,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (idMenu == ID_POPUPMENU_AREA) { if (idMenu == ID_POPUPMENU_AREA) {
bWorkArea = !bWorkArea; bWorkArea = !bWorkArea;
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
diag_log(L"Changed 'Use workarea' option to", bWorkArea); diag_log(L"Changed 'Use workarea' option to", bWorkArea);
} }
if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed) { if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed) {
bKPressed = TRUE; bKPressed = TRUE;
diag_log(L"Opening 'About' dialog"); diag_log(L"Opening 'About' dialog");
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
bKPressed = FALSE; bKPressed = FALSE;
} }
if (idMenu == ID_POPUPMENU_EXIT) SendMessage(hWnd, WM_CLOSE, NULL, NULL); if (idMenu == ID_POPUPMENU_EXIT) SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
} }
break; break;
@@ -264,7 +266,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
default: default:
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProcW(hWnd, message, wParam, lParam);
} }
return 0; return 0;
} }
@@ -323,7 +325,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
BOOL bApproved = CheckWindow(hFgWnd); BOOL bApproved = CheckWindow(hFgWnd);
if (bApproved) { if (bApproved) {
diag_log(L"Opening 'Manual editing' dialog"); diag_log(L"Opening 'Manual editing' dialog");
DialogBox(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hWnd, (DLGPROC)DlgProc); DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hWnd, (DLGPROC)DlgProc);
} else hFgWnd = NULL; } else hFgWnd = NULL;
bKEYV = FALSE; bKEYV = FALSE;
return TRUE; return TRUE;
@@ -337,9 +339,9 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) {
switch (dlgmsg) { switch (dlgmsg) {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
SetWindowText(hDlg, szTitle); SetWindowTextW(hDlg, szTitle);
GetWindowText(hFgWnd, szWinTitle, _countof(szWinTitle)); GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
GetClassName(hFgWnd, szWinClass, _countof(szWinClass)); GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass));
GetWindowRect(hFgWnd, &rcFW); GetWindowRect(hFgWnd, &rcFW);
x = rcFW.left; x = rcFW.left;
y = rcFW.top; y = rcFW.top;
@@ -349,8 +351,8 @@ BOOL 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);
SetDlgItemText(hDlg, IDC_EDIT_TITLE, szWinTitle); SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle);
SetDlgItemText(hDlg, IDC_EDIT_CLASS, szWinClass); SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass);
UpdateWindow(hDlg); UpdateWindow(hDlg);
break; break;
} }
@@ -362,9 +364,9 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) {
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);
h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE); h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE);
SendMessage(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);
SendMessage(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL);
return TRUE; return TRUE;
break; break;
} }
@@ -381,13 +383,13 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) {
} }
BOOL CheckWindow(HWND hFW) { BOOL CheckWindow(HWND hFW) {
diag_log(L"Entering CheckWindow(). hwnd=", hFW); diag_log(L"Entering CheckWindow(), hwnd=", hFW);
GetClassName(hFW, szWinClass, _countof(szWinClass)); GetClassNameW(hFW, szWinClass, _countof(szWinClass));
if (hFW) { if (hFW) {
if (_tcscmp(szWinClass, szWinCore) != 0) { if (wcscmp(szWinClass, szWinCore) != 0) {
if (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman) { if (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman) {
if (!IsIconic(hFW) && !IsZoomed(hFW)) { if (!IsIconic(hFW) && !IsZoomed(hFW)) {
GetWindowText(hFW, (LPTSTR)szBuffer, BUF_LEN - sizeof(TCHAR)); GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR));
diag_log(L"Window with hwnd=", hFW, L"is approved"); diag_log(L"Window with hwnd=", hFW, L"is approved");
return TRUE; return TRUE;
} else ShowError(IDS_ERR_MAXMIN); } else ShowError(IDS_ERR_MAXMIN);
@@ -400,23 +402,23 @@ BOOL CheckWindow(HWND hFW) {
} }
VOID HandlingTrayIcon() { VOID HandlingTrayIcon() {
diag_log(L"Entering HandlingTrayIcon(). bShowIcon =", bShowIcon); diag_log(L"Entering HandlingTrayIcon(), bShowIcon =", bShowIcon);
if (bShowIcon) { if (bShowIcon) {
if (!Shell_NotifyIcon(NIM_ADD, &nid)) { if (!Shell_NotifyIconW(NIM_ADD, &nid)) {
diag_log(L"GetLastError():", GetLastError()); diag_log(L"GetLastError():", GetLastError());
ShowError(IDS_ERR_ICON); ShowError(IDS_ERR_ICON);
bShowIcon = FALSE; bShowIcon = FALSE;
} }
} else { } else {
Shell_NotifyIcon(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
} }
diag_log(L"Quiting HandlingTrayIcon()"); diag_log(L"Quiting HandlingTrayIcon()");
} }
VOID ShowError(UINT uID) { VOID ShowError(UINT uID) {
TCHAR szErrorText[MAX_LOADSTRING]; // Error's text WCHAR szErrorText[MAX_LOADSTRING]; // Error's text
LoadString(hInst, uID, szErrorText, _countof(szErrorText)); LoadStringW(hInst, uID, szErrorText, _countof(szErrorText));
MessageBox(hWnd, 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) { INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
@@ -428,7 +430,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) { switch (message) {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
SetDlgItemText(hDlg, IDC_ABOUTHELP, szAbout); SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAbout);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
break; break;
} }
@@ -442,7 +444,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
if (pNMHdr->idFrom == IDC_DONATIONLINK) { if (pNMHdr->idFrom == IDC_DONATIONLINK) {
PNMLINK pNMLink = (PNMLINK)pNMHdr; PNMLINK pNMLink = (PNMLINK)pNMHdr;
LITEM item = pNMLink->item; LITEM item = pNMLink->item;
ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
diag_log(L"Pressed donation link"); diag_log(L"Pressed donation link");
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }

Binary file not shown.

View File

@@ -1,4 +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 /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>/test1 /test2</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project> </Project>