From 5bf973347f897d4864db516e99d8110bf25ac4e9 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Tue, 7 Nov 2023 17:38:24 +0300 Subject: [PATCH] Added a timer to periodically check for updates. --- wCenterWindow/resource.h | 8 ++-- wCenterWindow/wCenterWindow.cpp | 72 +++++++++++++++++++++----------- wCenterWindow/wCenterWindow.rc | Bin 13116 -> 13226 bytes 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/wCenterWindow/resource.h b/wCenterWindow/resource.h index 51ec2ad..84b2373 100644 --- a/wCenterWindow/resource.h +++ b/wCenterWindow/resource.h @@ -19,8 +19,10 @@ #define IDS_ERR_MENU 117 #define IDS_ERR_POPUP 118 #define IDS_ERR_HOOK 119 -#define IDS_ERR_MAXMIN 120 -#define IDS_RUNNING 121 +#define IDS_ERR_TIMER 120 +#define IDS_ERR_MAXMIN 121 +#define IDS_RUNNING 122 +#define IDT_TIMER 123 #define IDR_MAINFRAME 128 #define IDD_MANUAL_EDITING 129 #define IDC_EDIT_X 1000 @@ -48,6 +50,6 @@ #define _APS_NEXT_RESOURCE_VALUE 130 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1015 -#define _APS_NEXT_SYMED_VALUE 122 +#define _APS_NEXT_SYMED_VALUE 124 #endif #endif diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index f6c2a00..f1ecebd 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -16,7 +16,7 @@ #define KEY_V 0x56 #define BUF_LEN 1024 -#define WM_WCW 0x8F00 +#define WM_WCW (WM_APP + 0x0F00) // Global variables: HINSTANCE hInst; // Instance @@ -134,25 +134,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd } LocalFree(szArglist); - if (fCheckUpdates) - { - LOG_TO_FILE(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); - if (NULL == hUpdater) - { - DWORD dwLastError = GetLastError(); - LOG_TO_FILE(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError); - MessageBoxW(NULL, L"Creating Updater thread failed!", szTitle, MB_OK | MB_ICONERROR); - CloseLogFile(); - return dwLastError; - } - } - else - { - LOG_TO_FILE(L"%s(%d): Checking for updates is disabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False"); - } - WNDCLASSEX wcex = { 0 }; wcex.cbSize = sizeof(WNDCLASSEX); wcex.lpfnWndProc = WndProc; @@ -254,6 +235,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle); + if (fCheckUpdates) + { + if (!SetTimer(hWnd, IDT_TIMER, 20000, NULL)) + { + LOG_TO_FILE(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__); + ShowError(IDS_ERR_TIMER); + } + LOG_TO_FILE(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__); + } + #ifndef _DEBUG hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL); if (!hMouseHook) @@ -278,6 +269,36 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } + case WM_TIMER: + { + if (fCheckUpdates) + { + LOG_TO_FILE(L"%s(%d): Checking for updates is enabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False"); + + Sleep(10000); + hUpdater = CreateThread(NULL, 0, &Updater, nullptr, 0, nullptr); + if (NULL == hUpdater) + { + DWORD dwLastError = GetLastError(); + LOG_TO_FILE(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError); + } + else + { + if (!SetTimer(hWnd, IDT_TIMER, 86390000, NULL)) + { + LOG_TO_FILE(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__); + ShowError(IDS_ERR_TIMER); + } + LOG_TO_FILE(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__); + } + } + else + { + LOG_TO_FILE(L"%s(%d): Checking for updates is disabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False"); + } + break; + } + case WM_WCW: // Popup menu handler { if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam)) @@ -342,11 +363,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } - default: - return DefWindowProcW(hWnd, message, wParam, lParam); - } - return 0; + default: return DefWindowProcW(hWnd, message, wParam, lParam); } + return 0; +} LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) { @@ -450,6 +470,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) } case WM_COMMAND: + { switch (LOWORD(wParam)) { case IDC_BUTTON_SET: @@ -478,8 +499,9 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) break; } } + } + return FALSE; } - return FALSE; } BOOL IsWindowApprooved(HWND hFW) diff --git a/wCenterWindow/wCenterWindow.rc b/wCenterWindow/wCenterWindow.rc index ad777eb4d9fa18dd5b26881b0e9b828cb9cd4329..28ec78acabea2081343c34c52fcb7e537d4c1cb4 100644 GIT binary patch delta 48 zcmdm!wkmzYIX%u022TcG23Lll$%SI#lLd5TCePF3;4ERtWXNSmWhk2LsHeF3oL(La E0CF-8TmS$7 delta 12 TcmZ3Lz9((NIlav``gtq>DRBjG