Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10db7316fa | |||
| 5e9a553b67 | |||
| e74c775f90 | |||
| aadba59546 | |||
| b58039b4ab | |||
| 9dd557311e | |||
| 8df89dc8e1 | |||
| cf16651ae2 | |||
| 9fe46f867c | |||
| bb904723fa | |||
| eaed0ae8dc | |||
| 854a9a473b | |||
|
|
61b5f1d39c | ||
| c035b8a980 |
BIN
Version.ini
BIN
Version.ini
Binary file not shown.
@@ -4,20 +4,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "targetver.h"
|
#include "targetver.h"
|
||||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||||
|
|
||||||
// Windows Header Files
|
|
||||||
#include <fstream>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
#include <strsafe.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#include <shellapi.h>
|
|
||||||
#include <CommCtrl.h>
|
|
||||||
|
|
||||||
// Project Specific Header Files
|
|
||||||
#include "logger.h"
|
|
||||||
#include "VersionInfo.h"
|
|
||||||
|
|
||||||
// Extern variables
|
|
||||||
#define MAX_LOADSTRING 50
|
|
||||||
WCHAR szTitle[MAX_LOADSTRING]; // wCenterWindow's title
|
|
||||||
|
|||||||
15
wCenterWindow/globals.h
Normal file
15
wCenterWindow/globals.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// wCenterWindow
|
||||||
|
// globals.h
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "wCenterWindow.h"
|
||||||
|
|
||||||
|
#define MAX_LOADSTRING 50
|
||||||
|
#define TBUFLEN 32
|
||||||
|
#define DBUFLEN 256
|
||||||
|
|
||||||
|
extern WCHAR szTitle[];
|
||||||
|
extern SYSTEMTIME lt;
|
||||||
|
extern wchar_t debugBuffer[DBUFLEN];
|
||||||
|
extern std::wofstream logfile;
|
||||||
|
extern CRITICAL_SECTION cs;
|
||||||
@@ -1,39 +1,36 @@
|
|||||||
// wLogger v3.1 (Edited version from RBTray project [https://github.com/benbuck/rbtray])
|
// wCenterWindow
|
||||||
// logger.h
|
// logger.cpp
|
||||||
// Usage: LOG_TO_FILE(L"%s(%d): Log message", TEXT(__FUNCTION__), __LINE__);
|
//
|
||||||
#pragma once
|
#include "globals.h"
|
||||||
#include "framework.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#define DBUFLEN 256
|
|
||||||
#define LOG_TO_FILE(fmt, ...) do { StringCchPrintfW(debugBuffer, DBUFLEN, fmt, ##__VA_ARGS__); logfile << GetTimeStamp() << debugBuffer << std::endl; } while (0)
|
|
||||||
|
|
||||||
SYSTEMTIME lt;
|
SYSTEMTIME lt;
|
||||||
wchar_t debugTimeBuffer[32];
|
wchar_t debugTimeBuffer[TBUFLEN];
|
||||||
wchar_t debugBuffer[DBUFLEN];
|
wchar_t debugBuffer[DBUFLEN];
|
||||||
std::wofstream logfile;
|
std::wofstream logfile;
|
||||||
|
|
||||||
extern wchar_t szTitle[];
|
|
||||||
|
|
||||||
wchar_t* GetTimeStamp()
|
wchar_t* GetTimeStamp()
|
||||||
{
|
{
|
||||||
GetLocalTime(<);
|
GetLocalTime(<);
|
||||||
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);
|
StringCchPrintfW(debugTimeBuffer, TBUFLEN, L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
|
||||||
return debugTimeBuffer;
|
return debugTimeBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenLogFile()
|
void OpenLogFile(const wchar_t appTitle[], const wchar_t appVersion[])
|
||||||
{
|
{
|
||||||
|
WCHAR appTitleVer[MAX_LOADSTRING]{ 0 };
|
||||||
|
StringCchPrintfW(appTitleVer, MAX_LOADSTRING, L"%s v%s", appTitle, appVersion);
|
||||||
WCHAR lpszPath[MAX_PATH + 1] = { 0 };
|
WCHAR lpszPath[MAX_PATH + 1] = { 0 };
|
||||||
DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, MAX_PATH);
|
DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, MAX_PATH);
|
||||||
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", szTitle, MB_OK | MB_ICONWARNING);
|
MessageBoxW(NULL, L"Path to logfile is too long! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (NULL == dwPathLength)
|
if (NULL == dwPathLength)
|
||||||
{
|
{
|
||||||
MessageBoxW(NULL, L"Can't get module filename! Working without logging", szTitle, MB_OK | MB_ICONWARNING);
|
MessageBoxW(NULL, L"Can't get module filename! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,12 +48,12 @@ void OpenLogFile()
|
|||||||
{
|
{
|
||||||
logfile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
logfile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
||||||
logfile.imbue(std::locale("en-US.utf8"));
|
logfile.imbue(std::locale("en-US.utf8"));
|
||||||
logfile << GetTimeStamp() << "[ " << szTitle << " ] Start log." << std::endl;
|
logfile << GetTimeStamp() << "[ " << appTitleVer << " ] Start log." << std::endl;
|
||||||
logfile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
logfile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBoxW(NULL, L"Can't open logfile! Working without logging", szTitle, MB_OK | MB_ICONWARNING);
|
MessageBoxW(NULL, L"Can't open logfile! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -65,7 +62,7 @@ void CloseLogFile()
|
|||||||
{
|
{
|
||||||
if (logfile)
|
if (logfile)
|
||||||
{
|
{
|
||||||
logfile << GetTimeStamp() << "[ " << szTitle << " ] Stop log." << std::endl;
|
logfile << GetTimeStamp() << "Stop log." << std::endl;
|
||||||
logfile.close();
|
logfile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
17
wCenterWindow/logger.h
Normal file
17
wCenterWindow/logger.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// wCenterWindow
|
||||||
|
// logger.h
|
||||||
|
// wLogger v3.3 (Edited version from RBTray project [https://github.com/benbuck/rbtray])
|
||||||
|
//
|
||||||
|
// Usage: LOG_TO_FILE(L"%s(%d): Log message", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#define LOG_TO_FILE(fmt, ...) do {\
|
||||||
|
EnterCriticalSection(&cs); \
|
||||||
|
StringCchPrintfW(debugBuffer, DBUFLEN, fmt, ##__VA_ARGS__); \
|
||||||
|
logfile << GetTimeStamp() << debugBuffer << std::endl; \
|
||||||
|
LeaveCriticalSection(&cs); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
wchar_t* GetTimeStamp();
|
||||||
|
void OpenLogFile(const wchar_t[], const wchar_t[]);
|
||||||
|
void CloseLogFile();
|
||||||
1010
wCenterWindow/picojson.h
Normal file
1010
wCenterWindow/picojson.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -33,10 +33,11 @@
|
|||||||
#define IDC_BUTTON_CLOSE 1007
|
#define IDC_BUTTON_CLOSE 1007
|
||||||
#define IDC_ABOUTHELP 1008
|
#define IDC_ABOUTHELP 1008
|
||||||
#define IDC_DONATIONLINK 1009
|
#define IDC_DONATIONLINK 1009
|
||||||
#define IDC_ABOUT_PROGNAME 1010
|
#define IDC_DONATIONTEXT 1010
|
||||||
#define IDC_ABOUT_COPYRIGHT 1011
|
#define IDC_ABOUT_PROGNAME 1011
|
||||||
#define IDC_ABOUT_BUILDTIME 1012
|
#define IDC_ABOUT_COPYRIGHT 1012
|
||||||
#define IDC_ABOUTEDIT 1013
|
#define IDC_ABOUT_BUILDTIME 1013
|
||||||
|
#define IDC_ABOUTEDIT 1014
|
||||||
#define IDC_STATIC -1
|
#define IDC_STATIC -1
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
#define _APS_NO_MFC 1
|
#define _APS_NO_MFC 1
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
#define _APS_NEXT_RESOURCE_VALUE 130
|
||||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1014
|
#define _APS_NEXT_CONTROL_VALUE 1015
|
||||||
#define _APS_NEXT_SYMED_VALUE 122
|
#define _APS_NEXT_SYMED_VALUE 122
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
216
wCenterWindow/updater.cpp
Normal file
216
wCenterWindow/updater.cpp
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
// wCenterWindow
|
||||||
|
// updater.h
|
||||||
|
//
|
||||||
|
#include "globals.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "updater.h"
|
||||||
|
#include "picojson.h"
|
||||||
|
|
||||||
|
#define GITHUB_URL TEXT("api.github.com")
|
||||||
|
#define GITHUB_URI TEXT("/repos/dreamforceinc/wCenterWindow/releases/latest")
|
||||||
|
|
||||||
|
picojson::value json;
|
||||||
|
WCHAR errMessageBuffer[DBUFLEN]{ 0 };
|
||||||
|
|
||||||
|
struct Version
|
||||||
|
{
|
||||||
|
UINT Major = 0;
|
||||||
|
UINT Minor = 0;
|
||||||
|
UINT Build = 0;
|
||||||
|
UINT Revision = 0;
|
||||||
|
} verApp, verGh;
|
||||||
|
|
||||||
|
bool GetLatestRelease(const std::wstring& urn);
|
||||||
|
void FillVersionStructure(Version& ver, const std::wstring& str);
|
||||||
|
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim);
|
||||||
|
std::wstring ConvertUtf8ToWide(const std::string& str);
|
||||||
|
|
||||||
|
DWORD WINAPI Updater(LPVOID)
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||||
|
|
||||||
|
if (!GetLatestRelease(GITHUB_URI))
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
StringCchPrintfW(errMessageBuffer, DBUFLEN, L"Failed getting releases!");
|
||||||
|
MessageBoxW(NULL, errMessageBuffer, szTitle, MB_OK | MB_ICONERROR);
|
||||||
|
return 101;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring j_tag_name, j_file_name, j_file_ext, j_file_url, j_page_url;
|
||||||
|
int64_t j_file_size = 0;
|
||||||
|
picojson::object obj, obj2;
|
||||||
|
picojson::object::iterator it, it2;
|
||||||
|
|
||||||
|
if (json.is<picojson::object>())
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
|
obj = json.get<picojson::object>();
|
||||||
|
it = obj.find("message"), it2;
|
||||||
|
if (it != obj.end())
|
||||||
|
{
|
||||||
|
std::string u = (*it).second.get<std::string>();
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u);
|
||||||
|
return 102;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (it = obj.begin(); it != obj.end(); it++)
|
||||||
|
{
|
||||||
|
if ((*it).first == "tag_name") j_tag_name = ConvertUtf8ToWide((*it).second.to_str());
|
||||||
|
if ((*it).first == "html_url") j_page_url = ConvertUtf8ToWide((*it).second.to_str());
|
||||||
|
if ((*it).first == "assets" && (*it).second.is<picojson::array>())
|
||||||
|
{
|
||||||
|
picojson::array a = (*it).second.get<picojson::array>();
|
||||||
|
obj2 = a[0].get<picojson::object>();
|
||||||
|
for (it2 = obj2.begin(); it2 != obj2.end(); it2++)
|
||||||
|
{
|
||||||
|
if ((*it2).first == "name") j_file_name = ConvertUtf8ToWide((*it2).second.to_str());
|
||||||
|
if ((*it2).first == "browser_download_url") j_file_url = ConvertUtf8ToWide((*it2).second.to_str());
|
||||||
|
if ((*it2).first == "size") j_file_size = static_cast<int64_t>((*it2).second.get<double>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
return 103;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring gh_version = j_tag_name.substr(1);
|
||||||
|
|
||||||
|
LOG_TO_FILE(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());
|
||||||
|
//LOG_TO_FILE(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);
|
||||||
|
//LOG_TO_FILE(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());
|
||||||
|
|
||||||
|
FillVersionStructure(verApp, TEXT(VERSION_STR));
|
||||||
|
FillVersionStructure(verGh, gh_version);
|
||||||
|
|
||||||
|
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__);
|
||||||
|
|
||||||
|
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__);
|
||||||
|
ShellExecuteW(NULL, L"open", j_page_url.c_str(), NULL, NULL, SW_SHOW);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
return 104;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_TO_FILE(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetLatestRelease(const std::wstring& urn)
|
||||||
|
{
|
||||||
|
std::wstring user_agent = L"User-Agent: ";
|
||||||
|
user_agent.append(szTitle);
|
||||||
|
const std::wstring url = GITHUB_URL;
|
||||||
|
bool ret = true;
|
||||||
|
DWORD err = 0;
|
||||||
|
|
||||||
|
HINTERNET hInternet = InternetOpenW(user_agent.c_str(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
|
||||||
|
if (hInternet != NULL)
|
||||||
|
{
|
||||||
|
HINTERNET hConnect = InternetConnectW(hInternet, url.c_str(), INTERNET_DEFAULT_HTTPS_PORT, L"", L"", INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
|
||||||
|
if (hConnect != NULL)
|
||||||
|
{
|
||||||
|
HINTERNET hRequest = HttpOpenRequestW(hConnect, L"GET", urn.c_str(), NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_UI, 0);
|
||||||
|
if (hRequest != NULL)
|
||||||
|
{
|
||||||
|
BOOL isSend = HttpSendRequestW(hRequest, NULL, 0, 0, 0);
|
||||||
|
if (isSend)
|
||||||
|
{
|
||||||
|
char szData[1024]{ 0 };
|
||||||
|
DWORD dwBytesRead = 0;
|
||||||
|
std::string buffer;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
InternetReadFile(hRequest, szData, sizeof(szData), &dwBytesRead);
|
||||||
|
buffer.append(szData, dwBytesRead);
|
||||||
|
} while (dwBytesRead != 0);
|
||||||
|
|
||||||
|
picojson::parse(json, buffer);
|
||||||
|
std::string jerr = picojson::get_last_error();
|
||||||
|
if (!jerr.empty())
|
||||||
|
{
|
||||||
|
std::cout << jerr << std::endl;
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = GetLastError();
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = GetLastError();
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
InternetCloseHandle(hRequest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = GetLastError();
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
InternetCloseHandle(hConnect);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = GetLastError();
|
||||||
|
LOG_TO_FILE(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
InternetCloseHandle(hInternet);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim)
|
||||||
|
{
|
||||||
|
std::vector<std::wstring> result;
|
||||||
|
std::wstringstream ss(s);
|
||||||
|
std::wstring item;
|
||||||
|
while (getline(ss, item, delim)) result.push_back(item);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FillVersionStructure(Version& ver, const std::wstring& str)
|
||||||
|
{
|
||||||
|
std::vector<std::wstring> v;
|
||||||
|
v = Split(str, '.');
|
||||||
|
if (v.size() < 4) v.push_back(L"0");
|
||||||
|
ver.Major = std::stoul(v[0]);
|
||||||
|
ver.Minor = std::stoul(v[1]);
|
||||||
|
ver.Build = std::stoul(v[2]);
|
||||||
|
ver.Revision = std::stoul(v[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring ConvertUtf8ToWide(const std::string& str)
|
||||||
|
{
|
||||||
|
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
|
||||||
|
std::wstring wstr(count, 0);
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], count);
|
||||||
|
return wstr;
|
||||||
|
}
|
||||||
5
wCenterWindow/updater.h
Normal file
5
wCenterWindow/updater.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// wCenterWindow
|
||||||
|
// updater.h
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
DWORD WINAPI Updater(LPVOID);
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// wCenterWindow.cpp
|
// wCenterWindow.cpp
|
||||||
|
//
|
||||||
|
// TODO: Licensing.
|
||||||
|
// TODO: Change keyboard low-level hook to RegisterHotKey function.
|
||||||
|
// TODO: Make x64 version.
|
||||||
//
|
//
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "wCenterWindow.h"
|
#include "updater.h"
|
||||||
|
|
||||||
#define NO_DONATION
|
#define NO_DONATION
|
||||||
#define KEY_I 0x49
|
#define KEY_I 0x49
|
||||||
@@ -15,11 +20,11 @@
|
|||||||
|
|
||||||
// Global variables:
|
// Global variables:
|
||||||
HINSTANCE hInst; // Instance
|
HINSTANCE hInst; // Instance
|
||||||
extern WCHAR szTitle[];
|
WCHAR szTitle[MAX_LOADSTRING]; // wCenterWindow's title
|
||||||
WCHAR szClass[MAX_LOADSTRING]; // Window's class
|
WCHAR szClass[MAX_LOADSTRING]; // Window's class
|
||||||
WCHAR szWinTitle[256];
|
WCHAR szWinTitle[256];
|
||||||
WCHAR szWinClass[256];
|
WCHAR szWinClass[256];
|
||||||
HANDLE hHeap = NULL;
|
HANDLE hHeap = NULL, hUpdater = NULL;
|
||||||
HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles
|
HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles
|
||||||
HICON hIcon = NULL;
|
HICON hIcon = NULL;
|
||||||
HMENU hMenu = NULL, hPopup = NULL;
|
HMENU hMenu = NULL, hPopup = NULL;
|
||||||
@@ -33,9 +38,10 @@ LPKBDLLHOOKSTRUCT pkhs = { 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 } };
|
||||||
|
|
||||||
// Forward declarations of functions included in this code module:
|
// Forward declarations of functions included in this code module:
|
||||||
VOID HandlingTrayIcon();
|
VOID HandlingTrayIcon();
|
||||||
@@ -86,11 +92,12 @@ 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);
|
||||||
|
|
||||||
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"%s(%d): Moving the window to %d, %d", TEXT(__FUNCTION__), __LINE__, x, y);
|
|
||||||
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +114,21 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenLogFile();
|
InitializeCriticalSection(&cs);
|
||||||
|
OpenLogFile(szTitle, TEXT(VERSION_STR));
|
||||||
|
|
||||||
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
|
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
WNDCLASSEX wcex = { 0 };
|
WNDCLASSEX wcex = { 0 };
|
||||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||||
wcex.lpfnWndProc = WndProc;
|
wcex.lpfnWndProc = WndProc;
|
||||||
@@ -176,8 +194,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
|||||||
|
|
||||||
LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam);
|
LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam);
|
||||||
|
|
||||||
CloseLogFile();
|
|
||||||
HeapFree(hHeap, NULL, szBuffer);
|
HeapFree(hHeap, NULL, szBuffer);
|
||||||
|
CloseHandle(hUpdater);
|
||||||
|
CloseLogFile();
|
||||||
|
DeleteCriticalSection(&cs);
|
||||||
|
|
||||||
return (int)msg.wParam;
|
return (int)msg.wParam;
|
||||||
}
|
}
|
||||||
@@ -186,131 +206,132 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
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__);
|
LOG_TO_FILE(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__);
|
||||||
ShowError(IDS_ERR_MENU);
|
|
||||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
LOG_TO_FILE(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
hPopup = GetSubMenu(hMenu, 0);
|
hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
|
||||||
if (!hPopup)
|
if (!hMenu)
|
||||||
{
|
|
||||||
LOG_TO_FILE(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
ShowError(IDS_ERR_POPUP);
|
|
||||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
LOG_TO_FILE(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
mii.cbSize = sizeof(MENUITEMINFO);
|
|
||||||
mii.fMask = MIIM_STATE;
|
|
||||||
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
|
||||||
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
|
||||||
|
|
||||||
nid.cbSize = sizeof(NOTIFYICONDATAW);
|
|
||||||
nid.hWnd = hWnd;
|
|
||||||
nid.uVersion = NOTIFYICON_VERSION;
|
|
||||||
nid.uCallbackMessage = WM_WCW;
|
|
||||||
nid.hIcon = hIcon;
|
|
||||||
nid.uID = IDI_TRAYICON;
|
|
||||||
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
|
||||||
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__);
|
|
||||||
|
|
||||||
ShowError(IDS_ERR_HOOK);
|
|
||||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
LOG_TO_FILE(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
#endif // !_DEBUG
|
|
||||||
|
|
||||||
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
|
|
||||||
if (!hKbdHook)
|
|
||||||
{
|
|
||||||
LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
ShowError(IDS_ERR_HOOK);
|
|
||||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
LOG_TO_FILE(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_WCW: // Popup menu handler
|
|
||||||
{
|
|
||||||
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__);
|
|
||||||
|
|
||||||
SetForegroundWindow(hWnd);
|
|
||||||
POINT pt;
|
|
||||||
GetCursorPos(&pt);
|
|
||||||
int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
|
|
||||||
if (ID_POPUPMENU_ICON == idMenu)
|
|
||||||
{
|
{
|
||||||
LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__);
|
LOG_TO_FILE(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
ShowError(IDS_ERR_MENU);
|
||||||
bShowIcon = FALSE;
|
|
||||||
HandlingTrayIcon();
|
|
||||||
}
|
|
||||||
if (ID_POPUPMENU_AREA == idMenu)
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed)
|
|
||||||
{
|
|
||||||
LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
bKPressed = TRUE;
|
|
||||||
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);
|
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
LOG_TO_FILE(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
LOG_TO_FILE(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
|
hPopup = GetSubMenu(hMenu, 0);
|
||||||
|
if (!hPopup)
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
ShowError(IDS_ERR_POPUP);
|
||||||
|
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
|
}
|
||||||
|
LOG_TO_FILE(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
|
mii.cbSize = sizeof(MENUITEMINFO);
|
||||||
|
mii.fMask = MIIM_STATE;
|
||||||
|
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
||||||
|
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
||||||
|
|
||||||
|
nid.cbSize = sizeof(NOTIFYICONDATAW);
|
||||||
|
nid.hWnd = hWnd;
|
||||||
|
nid.uVersion = NOTIFYICON_VERSION;
|
||||||
|
nid.uCallbackMessage = WM_WCW;
|
||||||
|
nid.hIcon = hIcon;
|
||||||
|
nid.uID = IDI_TRAYICON;
|
||||||
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||||
|
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__);
|
||||||
|
|
||||||
|
ShowError(IDS_ERR_HOOK);
|
||||||
|
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
|
}
|
||||||
|
LOG_TO_FILE(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
#endif // !_DEBUG
|
||||||
|
|
||||||
|
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
|
||||||
|
if (!hKbdHook)
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
|
ShowError(IDS_ERR_HOOK);
|
||||||
|
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
|
}
|
||||||
|
LOG_TO_FILE(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_QUERYENDSESSION:
|
case WM_WCW: // Popup menu handler
|
||||||
{
|
{
|
||||||
LOG_TO_FILE(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)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__);
|
||||||
|
|
||||||
CloseLogFile();
|
SetForegroundWindow(hWnd);
|
||||||
return TRUE;
|
POINT pt;
|
||||||
break;
|
GetCursorPos(&pt);
|
||||||
}
|
int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
|
||||||
|
if (ID_POPUPMENU_ICON == idMenu)
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
case WM_DESTROY:
|
bShowIcon = FALSE;
|
||||||
{
|
HandlingTrayIcon();
|
||||||
LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
|
}
|
||||||
|
if (ID_POPUPMENU_AREA == idMenu)
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
PostQuitMessage(0);
|
bWorkArea = !bWorkArea;
|
||||||
break;
|
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");
|
||||||
|
}
|
||||||
|
if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed)
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
default:
|
bKPressed = TRUE;
|
||||||
return DefWindowProcW(hWnd, message, wParam, lParam);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
DeleteCriticalSection(&cs);
|
||||||
|
return TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WM_DESTROY:
|
||||||
|
{
|
||||||
|
LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return DefWindowProcW(hWnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -392,57 +413,57 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
|
|||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
switch (dlgmsg)
|
switch (dlgmsg)
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
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));
|
|
||||||
GetWindowRect(hFgWnd, &rcFW);
|
|
||||||
x = rcFW.left;
|
|
||||||
y = rcFW.top;
|
|
||||||
w = rcFW.right - rcFW.left;
|
|
||||||
h = rcFW.bottom - rcFW.top;
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_X, x, TRUE);
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE);
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE);
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE);
|
|
||||||
SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle);
|
|
||||||
SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass);
|
|
||||||
UpdateWindow(hDlg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_COMMAND:
|
|
||||||
switch (LOWORD(wParam))
|
|
||||||
{
|
{
|
||||||
case IDC_BUTTON_SET:
|
LOG_TO_FILE(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||||
{
|
|
||||||
LOG_TO_FILE(L"%s(%d): Pressed the 'Set' button", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE);
|
SetWindowTextW(hDlg, szTitle);
|
||||||
y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE);
|
GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
|
||||||
w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE);
|
GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass));
|
||||||
h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE);
|
GetWindowRect(hFgWnd, &rcFW);
|
||||||
SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL);
|
x = rcFW.left;
|
||||||
MoveWindow(hFgWnd, x, y, w, h, TRUE);
|
y = rcFW.top;
|
||||||
SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL);
|
w = rcFW.right - rcFW.left;
|
||||||
|
h = rcFW.bottom - rcFW.top;
|
||||||
LOG_TO_FILE(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y);
|
SetDlgItemInt(hDlg, IDC_EDIT_X, x, TRUE);
|
||||||
|
SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE);
|
||||||
return TRUE;
|
SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE);
|
||||||
|
SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE);
|
||||||
|
SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle);
|
||||||
|
SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass);
|
||||||
|
UpdateWindow(hDlg);
|
||||||
break;
|
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));
|
case WM_COMMAND:
|
||||||
break;
|
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);
|
||||||
|
h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE);
|
||||||
|
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));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -545,61 +566,63 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
{
|
||||||
LOG_TO_FILE(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
LOG_TO_FILE(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];
|
||||||
WCHAR szAboutBuildTime[MAX_LOADSTRING];
|
WCHAR szAboutBuildTime[MAX_LOADSTRING];
|
||||||
WCHAR szAboutHelp[MAX_LOADSTRING * 12];
|
WCHAR szAboutHelp[MAX_LOADSTRING * 12];
|
||||||
MultiByteToWideChar(1251, 0, PRODUCT_NAME_FULL, _countof(PRODUCT_NAME_FULL), szAboutProgName, MAX_LOADSTRING);
|
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, PRODUCT_COPYRIGHT, _countof(PRODUCT_COPYRIGHT), szAboutCopyright, MAX_LOADSTRING);
|
||||||
MultiByteToWideChar(1251, 0, ABOUT_BUILD, _countof(ABOUT_BUILD), szAboutBuildTime, MAX_LOADSTRING);
|
MultiByteToWideChar(1251, 0, ABOUT_BUILD, _countof(ABOUT_BUILD), szAboutBuildTime, MAX_LOADSTRING);
|
||||||
LoadStringW(hInst, IDS_ABOUT, szAboutHelp, _countof(szAboutHelp));
|
LoadStringW(hInst, IDS_ABOUT, szAboutHelp, _countof(szAboutHelp));
|
||||||
SetDlgItemTextW(hDlg, IDC_ABOUT_PROGNAME, szAboutProgName);
|
SetDlgItemTextW(hDlg, IDC_ABOUT_PROGNAME, szAboutProgName);
|
||||||
SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright);
|
SetDlgItemTextW(hDlg, IDC_ABOUT_COPYRIGHT, szAboutCopyright);
|
||||||
SetDlgItemTextW(hDlg, IDC_ABOUT_BUILDTIME, szAboutBuildTime);
|
SetDlgItemTextW(hDlg, IDC_ABOUT_BUILDTIME, szAboutBuildTime);
|
||||||
SetDlgItemTextW(hDlg, IDC_ABOUTEDIT, szAboutHelp);
|
SetDlgItemTextW(hDlg, IDC_ABOUTEDIT, szAboutHelp);
|
||||||
#ifdef NO_DONATION
|
#ifdef NO_DONATION
|
||||||
HWND hLink = GetDlgItem(hDlg, IDC_DONATIONLINK);
|
HWND hLink = GetDlgItem(hDlg, IDC_DONATIONLINK);
|
||||||
if (hLink) DestroyWindow(hLink);
|
if (hLink) DestroyWindow(hLink);
|
||||||
|
HWND hText = GetDlgItem(hDlg, IDC_DONATIONTEXT);
|
||||||
|
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__);
|
LOG_TO_FILE(L"%s(%d): End of initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
return (INT_PTR)TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_NOTIFY:
|
|
||||||
{
|
|
||||||
LPNMHDR pNMHdr = (LPNMHDR)lParam;
|
|
||||||
if ((NM_CLICK == pNMHdr->code || NM_RETURN == pNMHdr->code) && IDC_DONATIONLINK == pNMHdr->idFrom)
|
|
||||||
{
|
|
||||||
PNMLINK pNMLink = (PNMLINK)pNMHdr;
|
|
||||||
LITEM item = pNMLink->item;
|
|
||||||
ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
|
|
||||||
|
|
||||||
LOG_TO_FILE(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
return (INT_PTR)TRUE;
|
return (INT_PTR)TRUE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_NOTIFY:
|
||||||
{
|
|
||||||
if (IDOK == LOWORD(wParam) || IDCANCEL == LOWORD(wParam))
|
|
||||||
{
|
{
|
||||||
EndDialog(hDlg, LOWORD(wParam));
|
LPNMHDR pNMHdr = (LPNMHDR)lParam;
|
||||||
|
if ((NM_CLICK == pNMHdr->code || NM_RETURN == pNMHdr->code) && IDC_DONATIONLINK == pNMHdr->idFrom)
|
||||||
|
{
|
||||||
|
PNMLINK pNMLink = (PNMLINK)pNMHdr;
|
||||||
|
LITEM item = pNMLink->item;
|
||||||
|
ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
|
||||||
|
|
||||||
LOG_TO_FILE(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
LOG_TO_FILE(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
return (INT_PTR)TRUE;
|
return (INT_PTR)TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WM_COMMAND:
|
||||||
|
{
|
||||||
|
if (IDOK == LOWORD(wParam) || IDCANCEL == LOWORD(wParam))
|
||||||
|
{
|
||||||
|
EndDialog(hDlg, LOWORD(wParam));
|
||||||
|
|
||||||
|
LOG_TO_FILE(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
|
||||||
|
return (INT_PTR)TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (INT_PTR)FALSE;
|
return (INT_PTR)FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// wCenterWindow.h
|
// wCenterWindow.h
|
||||||
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
|
// Windows Header Files
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <strsafe.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <wininet.h>
|
||||||
|
#include <shellapi.h>
|
||||||
|
#include <CommCtrl.h>
|
||||||
|
|
||||||
|
// VerionInfo header file
|
||||||
|
#include "VersionInfo.h"
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 113 KiB |
Binary file not shown.
@@ -104,7 +104,7 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
<Manifest>
|
<Manifest>
|
||||||
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
||||||
@@ -131,13 +131,13 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
<Manifest>
|
<Manifest>
|
||||||
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
<Command>powershell -ExecutionPolicy RemoteSigned -File "$(SolutionDir)Update_Version.ps1" && move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"</Command>
|
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"</Command>
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -187,19 +187,23 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="framework.h" />
|
<ClInclude Include="framework.h" />
|
||||||
|
<ClInclude Include="globals.h" />
|
||||||
<ClInclude Include="logger.h" />
|
<ClInclude Include="logger.h" />
|
||||||
<ClInclude Include="Resource.h" />
|
<ClInclude Include="picojson.h" />
|
||||||
|
<ClInclude Include="resource.h" />
|
||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
|
<ClInclude Include="updater.h" />
|
||||||
<ClInclude Include="wCenterWindow.h" />
|
<ClInclude Include="wCenterWindow.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="logger.cpp" />
|
||||||
|
<ClCompile Include="updater.cpp" />
|
||||||
<ClCompile Include="wCenterWindow.cpp" />
|
<ClCompile Include="wCenterWindow.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="wCenterWindow.rc" />
|
<ResourceCompile Include="wCenterWindow.rc" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="small.ico" />
|
|
||||||
<Image Include="wCenterWindow.ico" />
|
<Image Include="wCenterWindow.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -30,11 +30,26 @@
|
|||||||
<ClInclude Include="logger.h">
|
<ClInclude Include="logger.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="globals.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="picojson.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="updater.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="wCenterWindow.cpp">
|
<ClCompile Include="wCenterWindow.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="logger.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="updater.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="wCenterWindow.rc">
|
<ResourceCompile Include="wCenterWindow.rc">
|
||||||
@@ -42,9 +57,6 @@
|
|||||||
</ResourceCompile>
|
</ResourceCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="small.ico">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Image>
|
|
||||||
<Image Include="wCenterWindow.ico">
|
<Image Include="wCenterWindow.ico">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<LocalDebuggerCommandArguments>/test1 /test2</LocalDebuggerCommandArguments>
|
<LocalDebuggerCommandArguments>
|
||||||
|
</LocalDebuggerCommandArguments>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user