Replaced macro calling.

The macro call has been replaced with a call to the Out() method of an instance of the CLogger class.
This commit is contained in:
2023-11-28 17:02:14 +03:00
parent 14ee12cb85
commit 1f8fb92dbe
3 changed files with 92 additions and 89 deletions

View File

@@ -29,11 +29,11 @@ std::wstring ConvertUtf8ToWide(const std::string& str);
//DWORD WINAPI Updater(LPVOID) //DWORD WINAPI Updater(LPVOID)
UINT WINAPI Updater(LPVOID) UINT WINAPI Updater(LPVOID)
{ {
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__)); logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
if (!GetLatestRelease(GITHUB_URI)) if (!GetLatestRelease(GITHUB_URI))
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
StringCchPrintfW(errMessageBuffer, DBUFLEN, L"Failed getting releases!"); StringCchPrintfW(errMessageBuffer, DBUFLEN, L"Failed getting releases!");
MessageBoxW(NULL, errMessageBuffer, szTitle, MB_OK | MB_ICONERROR); MessageBoxW(NULL, errMessageBuffer, szTitle, MB_OK | MB_ICONERROR);
return 101; return 101;
@@ -46,14 +46,14 @@ UINT WINAPI Updater(LPVOID)
if (json.is<picojson::object>()) if (json.is<picojson::object>())
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__); logger.Out(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
obj = json.get<picojson::object>(); obj = json.get<picojson::object>();
it = obj.find("message"), it2; it = obj.find("message"), it2;
if (it != obj.end()) if (it != obj.end())
{ {
std::string u = (*it).second.get<std::string>(); std::string u = (*it).second.get<std::string>();
LOG_TO_FILE(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u); logger.Out(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u);
return 102; return 102;
} }
@@ -76,7 +76,7 @@ UINT WINAPI Updater(LPVOID)
} }
else else
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
return 103; return 103;
} }
@@ -84,12 +84,12 @@ UINT WINAPI Updater(LPVOID)
while (std::iswdigit(j_tag_name.at(pos)) == 0) pos++; while (std::iswdigit(j_tag_name.at(pos)) == 0) pos++;
std::wstring gh_version = j_tag_name.substr(pos); std::wstring gh_version = j_tag_name.substr(pos);
LOG_TO_FILE(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR)); logger.Out(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR));
LOG_TO_FILE(L"[UPDT] %s(%d): GitVersion : %s", TEXT(__FUNCTION__), __LINE__, gh_version.c_str()); logger.Out(L"[UPDT] %s(%d): GitVersion : %s", TEXT(__FUNCTION__), __LINE__, gh_version.c_str());
//LOG_TO_FILE(L"[UPDT] %s(%d): FileName : %s", TEXT(__FUNCTION__), __LINE__, j_file_name.c_str()); //logger.Out(L"[UPDT] %s(%d): FileName : %s", TEXT(__FUNCTION__), __LINE__, j_file_name.c_str());
//LOG_TO_FILE(L"[UPDT] %s(%d): FileSize : %d", TEXT(__FUNCTION__), __LINE__, j_file_size); //logger.Out(L"[UPDT] %s(%d): FileSize : %d", TEXT(__FUNCTION__), __LINE__, j_file_size);
//LOG_TO_FILE(L"[UPDT] %s(%d): File Url : %s", TEXT(__FUNCTION__), __LINE__, j_file_url.c_str()); //logger.Out(L"[UPDT] %s(%d): File Url : %s", TEXT(__FUNCTION__), __LINE__, j_file_url.c_str());
//LOG_TO_FILE(L"[UPDT] %s(%d): Page Url : %s", TEXT(__FUNCTION__), __LINE__, j_page_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(verApp, TEXT(VERSION_STR));
FillVersionStructure(verGh, gh_version); FillVersionStructure(verGh, gh_version);
@@ -97,24 +97,24 @@ UINT WINAPI Updater(LPVOID)
if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Revision > verApp.Revision)) if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Revision > verApp.Revision))
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): An update is available!", TEXT(__FUNCTION__), __LINE__); 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)) if (IDYES == MessageBoxW(NULL, L"An update is available!\nDo you want to open the download page?", szTitle, MB_YESNO | MB_ICONINFORMATION))
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): Opening download page by default browser", TEXT(__FUNCTION__), __LINE__); 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); ShellExecuteW(NULL, L"open", j_page_url.c_str(), NULL, NULL, SW_SHOW);
} }
else else
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__); logger.Out(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
} }
} }
else else
{ {
LOG_TO_FILE(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__); logger.Out(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
} }
LOG_TO_FILE(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__)); logger.Out(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
//return 0; //return 0;
_endthreadex(0); _endthreadex(0);
@@ -161,14 +161,14 @@ bool GetLatestRelease(const std::wstring& urn)
else else
{ {
err = GetLastError(); err = GetLastError();
LOG_TO_FILE(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err); logger.Out(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false; ret = false;
} }
} }
else else
{ {
err = GetLastError(); err = GetLastError();
LOG_TO_FILE(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err); logger.Out(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false; ret = false;
} }
InternetCloseHandle(hRequest); InternetCloseHandle(hRequest);
@@ -176,7 +176,7 @@ bool GetLatestRelease(const std::wstring& urn)
else else
{ {
err = GetLastError(); err = GetLastError();
LOG_TO_FILE(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err); logger.Out(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false; ret = false;
} }
InternetCloseHandle(hConnect); InternetCloseHandle(hConnect);
@@ -184,7 +184,7 @@ bool GetLatestRelease(const std::wstring& urn)
else else
{ {
err = GetLastError(); err = GetLastError();
LOG_TO_FILE(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err); logger.Out(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
ret = false; ret = false;
} }
InternetCloseHandle(hInternet); InternetCloseHandle(hInternet);

View File

@@ -6,8 +6,7 @@
// TODO: Make x64 version. // TODO: Make x64 version.
// //
#include "framework.h" #include "framework.h"
#include "globals.h" #include "wCenterWindow.h"
#include "logger.h"
#include "updater.h" #include "updater.h"
#define NO_DONATION #define NO_DONATION
@@ -32,12 +31,12 @@ HMENU hMenu = NULL, hPopup = NULL;
HWND hWnd = NULL, hFgWnd = NULL; HWND hWnd = NULL, hFgWnd = NULL;
BOOL bKPressed = FALSE, bMPressed = FALSE, fShowIcon = TRUE, fCheckUpdates = TRUE, bWorkArea = TRUE; BOOL bKPressed = FALSE, bMPressed = FALSE, fShowIcon = TRUE, fCheckUpdates = TRUE, bWorkArea = TRUE;
BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE; BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE;
CLogger logger(TEXT(PRODUCT_NAME), TEXT(VERSION_STR));
NOTIFYICONDATAW nid = { 0 }; NOTIFYICONDATAW nid = { 0 };
MENUITEMINFO mii = { 0 }; MENUITEMINFO mii = { 0 };
LPVOID szBuffer; LPVOID szBuffer;
CRITICAL_SECTION cs;
// {2D7B7F30-4B5F-4380-9807-57D7A2E37F6C} // {2D7B7F30-4B5F-4380-9807-57D7A2E37F6C}
// static const GUID guid = { 0x2d7b7f30, 0x4b5f, 0x4380, { 0x98, 0x7, 0x57, 0xd7, 0xa2, 0xe3, 0x7f, 0x6c } }; // static const GUID guid = { 0x2d7b7f30, 0x4b5f, 0x4380, { 0x98, 0x7, 0x57, 0xd7, 0xa2, 0xe3, 0x7f, 0x6c } };
@@ -54,14 +53,14 @@ INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
{ {
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__)); logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
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;
LOG_TO_FILE(L"%s(%d): Moving the window from %d, %d", TEXT(__FUNCTION__), __LINE__, fgwrc.left, fgwrc.top); logger.Out(L"%s(%d): Moving the window from %d, %d", TEXT(__FUNCTION__), __LINE__, fgwrc.left, fgwrc.top);
MONITORINFO mi = { 0 }; MONITORINFO mi = { 0 };
mi.cbSize = sizeof(MONITORINFO); mi.cbSize = sizeof(MONITORINFO);
@@ -91,13 +90,13 @@ 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;
LOG_TO_FILE(L"%s(%d): Moving the window to %d, %d", TEXT(__FUNCTION__), __LINE__, x, y); 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);
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
} }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
@@ -113,21 +112,18 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
return FALSE; return FALSE;
} }
InitializeCriticalSection(&cs); logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
OpenLogFile(szTitle, TEXT(VERSION_STR));
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
int nArgs = 0; int nArgs = 0;
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
LOG_TO_FILE(L"Arguments count: %d", nArgs - 1); logger.Out(L"Arguments count: %d", nArgs - 1);
if (nArgs > 1) if (nArgs > 1)
{ {
for (int i = 1; i < nArgs; i++) for (int i = 1; i < nArgs; i++)
{ {
LOG_TO_FILE(L"Argument %d: %s", i, 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"/hide")) fShowIcon = FALSE;
if (0 == lstrcmpiW(szArglist[i], L"/noupdate")) fCheckUpdates = FALSE; if (0 == lstrcmpiW(szArglist[i], L"/noupdate")) fCheckUpdates = FALSE;
} }
@@ -186,12 +182,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
Shell_NotifyIconW(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
DestroyIcon(hIcon); DestroyIcon(hIcon);
LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam); logger.Out(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam);
HeapFree(hHeap, NULL, szBuffer); HeapFree(hHeap, NULL, szBuffer);
CloseHandle(hUpdater); CloseHandle(hUpdater);
CloseLogFile();
DeleteCriticalSection(&cs);
return (int)msg.wParam; return (int)msg.wParam;
} }
@@ -202,25 +196,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
case WM_CREATE: case WM_CREATE:
{ {
LOG_TO_FILE(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__);
hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU)); hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
if (!hMenu) if (!hMenu)
{ {
LOG_TO_FILE(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_MENU); ShowError(IDS_ERR_MENU);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL); PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
LOG_TO_FILE(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
hPopup = GetSubMenu(hMenu, 0); hPopup = GetSubMenu(hMenu, 0);
if (!hPopup) if (!hPopup)
{ {
LOG_TO_FILE(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_POPUP); ShowError(IDS_ERR_POPUP);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL); PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
LOG_TO_FILE(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
mii.cbSize = sizeof(MENUITEMINFO); mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE; mii.fMask = MIIM_STATE;
@@ -240,34 +234,34 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
if (!SetTimer(hWnd, IDT_TIMER, 20000, NULL)) // 20 seconds if (!SetTimer(hWnd, IDT_TIMER, 20000, NULL)) // 20 seconds
{ {
LOG_TO_FILE(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_TIMER); ShowError(IDS_ERR_TIMER);
fCheckUpdates = FALSE; fCheckUpdates = FALSE;
} }
LOG_TO_FILE(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__);
} }
#ifndef _DEBUG #ifndef _DEBUG
hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL); hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
if (!hMouseHook) if (!hMouseHook)
{ {
LOG_TO_FILE(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_HOOK); ShowError(IDS_ERR_HOOK);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL); PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
LOG_TO_FILE(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
#endif // !_DEBUG #endif // !_DEBUG
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
if (!hKbdHook) if (!hKbdHook)
{ {
LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_HOOK); ShowError(IDS_ERR_HOOK);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL); PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
LOG_TO_FILE(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
break; break;
} }
@@ -277,29 +271,29 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
Sleep(10000); // 10 seconds Sleep(10000); // 10 seconds
LOG_TO_FILE(L"%s(%d): Checking for updates is enabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False"); logger.Out(L"%s(%d): Checking for updates is enabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False");
//hUpdater = CreateThread(NULL, 0, &Updater, nullptr, 0, nullptr); //hUpdater = CreateThread(NULL, 0, &Updater, nullptr, 0, nullptr);
hUpdater = (HANDLE)_beginthreadex(NULL, 0, &Updater, NULL, 0, &dwUpdaterID); hUpdater = (HANDLE)_beginthreadex(NULL, 0, &Updater, NULL, 0, &dwUpdaterID);
if (NULL == hUpdater) if (NULL == hUpdater)
{ {
DWORD dwLastError = GetLastError(); DWORD dwLastError = GetLastError();
LOG_TO_FILE(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError); logger.Out(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError);
} }
else else
{ {
if (!SetTimer(hWnd, IDT_TIMER, 86390000, NULL)) // 1 day - 10 seconds if (!SetTimer(hWnd, IDT_TIMER, 86390000, NULL)) // 1 day - 10 seconds
{ {
LOG_TO_FILE(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_TIMER); ShowError(IDS_ERR_TIMER);
fCheckUpdates = FALSE; fCheckUpdates = FALSE;
} }
LOG_TO_FILE(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__);
} }
} }
else else
{ {
LOG_TO_FILE(L"%s(%d): Checking for updates is disabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False"); logger.Out(L"%s(%d): Checking for updates is disabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False");
} }
break; break;
} }
@@ -308,7 +302,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam)) if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam))
{ {
LOG_TO_FILE(L"%s(%d): Entering the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Entering the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
SetForegroundWindow(hWnd); SetForegroundWindow(hWnd);
POINT pt; POINT pt;
@@ -316,23 +310,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL); int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
if (ID_POPUPMENU_ICON == idMenu) if (ID_POPUPMENU_ICON == idMenu)
{ {
LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__);
fShowIcon = FALSE; fShowIcon = FALSE;
HandlingTrayIcon(); HandlingTrayIcon();
} }
if (ID_POPUPMENU_AREA == idMenu) if (ID_POPUPMENU_AREA == idMenu)
{ {
LOG_TO_FILE(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__); 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);
LOG_TO_FILE(L"%s(%d): Changed 'Use workarea' option to %s", TEXT(__FUNCTION__), __LINE__, bWorkArea ? L"True" : L"False"); logger.Out(L"%s(%d): Changed 'Use workarea' option to %s", TEXT(__FUNCTION__), __LINE__, bWorkArea ? L"True" : L"False");
} }
if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed) if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed)
{ {
LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE; bKPressed = TRUE;
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
@@ -340,29 +334,28 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
if (ID_POPUPMENU_EXIT == idMenu) if (ID_POPUPMENU_EXIT == idMenu)
{ {
LOG_TO_FILE(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__);
PostMessageW(hWnd, WM_CLOSE, NULL, NULL); PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
} }
LOG_TO_FILE(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
} }
break; break;
} }
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION:
{ {
LOG_TO_FILE(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)lParam); logger.Out(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)lParam);
CloseLogFile(); PostQuitMessage(0);
DeleteCriticalSection(&cs);
return TRUE; return TRUE;
break; break;
} }
case WM_DESTROY: case WM_DESTROY:
{ {
LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
PostQuitMessage(0); PostQuitMessage(0);
break; break;
@@ -378,7 +371,7 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
if (WM_MBUTTONUP == wParam) bMPressed = FALSE; if (WM_MBUTTONUP == wParam) bMPressed = FALSE;
if (WM_MBUTTONDOWN == wParam && bLCTRL && bLWIN && !bMPressed) if (WM_MBUTTONDOWN == wParam && bLCTRL && bLWIN && !bMPressed)
{ {
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__);
bMPressed = TRUE; bMPressed = TRUE;
hFgWnd = GetForegroundWindow(); hFgWnd = GetForegroundWindow();
@@ -406,7 +399,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key
{ {
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE; bKPressed = TRUE;
fShowIcon = !fShowIcon; fShowIcon = !fShowIcon;
@@ -416,7 +409,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key
{ {
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE; bKPressed = TRUE;
hFgWnd = GetForegroundWindow(); hFgWnd = GetForegroundWindow();
@@ -427,13 +420,13 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key
{ {
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__);
bKPressed = TRUE; bKEYV = TRUE; bKPressed = TRUE; bKEYV = TRUE;
hFgWnd = GetForegroundWindow(); hFgWnd = GetForegroundWindow();
if (IsWindowApprooved(hFgWnd)) if (IsWindowApprooved(hFgWnd))
{ {
LOG_TO_FILE(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc); DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc);
SetForegroundWindow(hFgWnd); SetForegroundWindow(hFgWnd);
@@ -454,7 +447,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
LOG_TO_FILE(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
SetWindowTextW(hDlg, szTitle); SetWindowTextW(hDlg, szTitle);
GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle)); GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
@@ -480,7 +473,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
{ {
case IDC_BUTTON_SET: case IDC_BUTTON_SET:
{ {
LOG_TO_FILE(L"%s(%d): Pressed the 'Set' button", TEXT(__FUNCTION__), __LINE__); 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);
@@ -490,7 +483,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
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);
LOG_TO_FILE(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y); logger.Out(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y);
return TRUE; return TRUE;
break; break;
@@ -498,7 +491,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
case IDCANCEL: case IDCANCEL:
case IDC_BUTTON_CLOSE: case IDC_BUTTON_CLOSE:
{ {
LOG_TO_FILE(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
break; break;
@@ -512,24 +505,24 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
BOOL IsWindowApprooved(HWND hFW) BOOL IsWindowApprooved(HWND hFW)
{ {
LOG_TO_FILE(L"Entering the %s() function, handle = 0x%08X", TEXT(__FUNCTION__), hFW); logger.Out(L"Entering the %s() function, handle = 0x%08X", TEXT(__FUNCTION__), hFW);
bool bApprooved = FALSE; bool bApprooved = FALSE;
if (hFW) if (hFW)
{ {
if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR))) if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR)))
{ {
LOG_TO_FILE(L"%s(%d): Window title: '%s'", TEXT(__FUNCTION__), __LINE__, (LPWSTR)szBuffer); logger.Out(L"%s(%d): Window title: '%s'", TEXT(__FUNCTION__), __LINE__, (LPWSTR)szBuffer);
} }
if (IsIconic(hFW)) if (IsIconic(hFW))
{ {
LOG_TO_FILE(L"%s(%d): The window is iconified", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The window is iconified", TEXT(__FUNCTION__), __LINE__);
} }
if (IsZoomed(hFW)) if (IsZoomed(hFW))
{ {
LOG_TO_FILE(L"%s(%d): The window is maximized", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The window is maximized", TEXT(__FUNCTION__), __LINE__);
} }
LONG_PTR wlp = GetWindowLongPtrW(hFW, GWL_STYLE); LONG_PTR wlp = GetWindowLongPtrW(hFW, GWL_STYLE);
@@ -537,7 +530,7 @@ BOOL IsWindowApprooved(HWND hFW)
{ {
if (!IsIconic(hFW) && !IsZoomed(hFW)) if (!IsIconic(hFW) && !IsZoomed(hFW))
{ {
LOG_TO_FILE(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__);
bApprooved = TRUE; bApprooved = TRUE;
} }
@@ -545,35 +538,35 @@ BOOL IsWindowApprooved(HWND hFW)
} }
else else
{ {
LOG_TO_FILE(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__);
} }
} }
if (!bApprooved) if (!bApprooved)
{ {
LOG_TO_FILE(L"%s(%d): The window is not approved!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): The window is not approved!", TEXT(__FUNCTION__), __LINE__);
} }
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
return bApprooved; return bApprooved;
} }
VOID HandlingTrayIcon() VOID HandlingTrayIcon()
{ {
LOG_TO_FILE(L"Entering the %s() function, fShowIcon = %s", TEXT(__FUNCTION__), fShowIcon ? L"True" : L"False"); logger.Out(L"Entering the %s() function, fShowIcon = %s", TEXT(__FUNCTION__), fShowIcon ? L"True" : L"False");
if (fShowIcon) if (fShowIcon)
{ {
bool bResult1 = Shell_NotifyIconW(NIM_ADD, &nid); 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"); logger.Out(L"%s(%d): Shell_NotifyIconW(NIM_ADD): %s", TEXT(__FUNCTION__), __LINE__, bResult1 ? L"True" : L"False");
bool bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid); 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"); logger.Out(L"%s(%d): Shell_NotifyIconW(NIM_SETVERSION): %s", TEXT(__FUNCTION__), __LINE__, bResult2 ? L"True" : L"False");
if (!bResult1 || !bResult2) if (!bResult1 || !bResult2)
{ {
LOG_TO_FILE(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__);
ShowError(IDS_ERR_ICON); ShowError(IDS_ERR_ICON);
Shell_NotifyIconW(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
@@ -589,7 +582,7 @@ VOID HandlingTrayIcon()
Shell_NotifyIconW(NIM_DELETE, &nid); Shell_NotifyIconW(NIM_DELETE, &nid);
} }
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__)); logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
} }
VOID ShowError(UINT uID) VOID ShowError(UINT uID)
@@ -610,7 +603,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
LOG_TO_FILE(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
WCHAR szAboutProgName[MAX_LOADSTRING]; WCHAR szAboutProgName[MAX_LOADSTRING];
WCHAR szAboutCopyright[MAX_LOADSTRING]; WCHAR szAboutCopyright[MAX_LOADSTRING];
@@ -631,7 +624,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
if (hText) DestroyWindow(hText); if (hText) DestroyWindow(hText);
#endif // !NO_DONATION #endif // !NO_DONATION
LOG_TO_FILE(L"%s(%d): End of initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): End of initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
break; break;
@@ -646,7 +639,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
LITEM item = pNMLink->item; LITEM item = pNMLink->item;
ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
LOG_TO_FILE(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
@@ -659,7 +652,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
LOG_TO_FILE(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__); logger.Out(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }

View File

@@ -4,6 +4,8 @@
#pragma once #pragma once
#include "resource.h" #include "resource.h"
#define MAX_LOADSTRING 50
// Windows Header Files // Windows Header Files
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@@ -17,6 +19,14 @@
#include <CommCtrl.h> #include <CommCtrl.h>
#include <process.h> #include <process.h>
// Logger header file
#include "CLogger.h"
// VerionInfo header file // VerionInfo header file
#include "VersionInfo.h" #include "VersionInfo.h"
// wCenterWindow's title
extern WCHAR szTitle[MAX_LOADSTRING];
// An instance of the "CLogger" class
extern CLogger logger;