From a4af63ed34c17d3d6f0a29e88f98a441f3317b00 Mon Sep 17 00:00:00 2001 From: W0LF Date: Fri, 30 Apr 2021 23:07:44 +0300 Subject: [PATCH] Version 2.2 Added manual editing of size and position of the widow. Added centering the window by middle mouse button. Updated project from Visual Studio 2017 to 2019. --- README.md | 12 +- wCenterWindow.sln | 24 +- wCenterWindow/framework.h | 17 + wCenterWindow/resource.h | 64 ++-- wCenterWindow/targetver.h | 6 + wCenterWindow/wCenterWindow.cpp | 327 +++++++++++++++----- wCenterWindow/wCenterWindow.h | 3 + wCenterWindow/wCenterWindow.rc | Bin 2090 -> 14622 bytes wCenterWindow/wCenterWindow.vcxproj | 98 ++++-- wCenterWindow/wCenterWindow.vcxproj.filters | 42 ++- wCenterWindow/wCenterWindow.vcxproj.user | 2 +- 11 files changed, 444 insertions(+), 151 deletions(-) create mode 100644 wCenterWindow/framework.h create mode 100644 wCenterWindow/targetver.h create mode 100644 wCenterWindow/wCenterWindow.h diff --git a/README.md b/README.md index 3070b3b..11db64c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # wCenterWindow -This program centers the current active window by a 'LCTRL + LWIN + C' hotkey. +This program centers the current active window by a ```LCTRL + LWIN + C``` hotkey, +or pressing ```LCTRL + LWIN + MMB``` (Middle Mouse Button). -You can use 'LCTRL + LWIN + I' hotkey for hide/show trayicon. +```LCTRL + LWIN + V``` - manual editing of size and position of the window. -You can also use commandline option '/hide' for hide trayicon at startup. +You can use ```LCTRL + LWIN + I``` hotkey for hide/show trayicon. +You can also use commandline option ```/hide``` for hide trayicon at startup. -'Use workarea' option means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used." +```Use workarea``` option means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used. + +If some windows does not centers you should run wCenterWindow with administrative rights. diff --git a/wCenterWindow.sln b/wCenterWindow.sln index 4778cc4..df62922 100644 --- a/wCenterWindow.sln +++ b/wCenterWindow.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.1082 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31112.23 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWindow\wCenterWindow.vcxproj", "{2494B3F2-585E-4A2E-A013-20A15AE25B9E}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wCenterWindow", "wCenterWindow\wCenterWindow.vcxproj", "{F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,19 +13,19 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Debug|x64.ActiveCfg = Debug|x64 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Debug|x64.Build.0 = Debug|x64 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Debug|x86.ActiveCfg = Debug|Win32 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Debug|x86.Build.0 = Debug|Win32 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Release|x64.ActiveCfg = Release|x64 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Release|x64.Build.0 = Release|x64 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Release|x86.ActiveCfg = Release|Win32 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E}.Release|x86.Build.0 = Release|Win32 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Debug|x64.ActiveCfg = Debug|x64 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Debug|x64.Build.0 = Debug|x64 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Debug|x86.ActiveCfg = Debug|Win32 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Debug|x86.Build.0 = Debug|Win32 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Release|x64.ActiveCfg = Release|x64 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Release|x64.Build.0 = Release|x64 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Release|x86.ActiveCfg = Release|Win32 + {F1A1603A-F5D0-47B8-8E4B-CF17747BCFBA}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {34E34C1F-8A53-40DA-BA24-78C20152D64C} + SolutionGuid = {83F3F9B6-B00E-4705-9C92-19308AAC038B} EndGlobalSection EndGlobal diff --git a/wCenterWindow/framework.h b/wCenterWindow/framework.h new file mode 100644 index 0000000..f170d66 --- /dev/null +++ b/wCenterWindow/framework.h @@ -0,0 +1,17 @@ +// header.h : include file for standard system include files, +// or project specific include files +// + +#pragma once + +#include "targetver.h" +//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include +#include +#include +// C RunTime Header Files +#include +#include +#include +#include diff --git a/wCenterWindow/resource.h b/wCenterWindow/resource.h index 7bff434..96bfd60 100644 --- a/wCenterWindow/resource.h +++ b/wCenterWindow/resource.h @@ -1,19 +1,47 @@ -#pragma once +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by wCenterWindow.rc +// +#define IDS_CLASSNAME 102 +#define IDS_APP_TITLE 103 +#define IDD_ABOUTBOX 104 +#define IDI_TRAYICON 105 +#define IDR_MENU 106 +#define ID_POPUPMENU_ICON 107 +#define ID_POPUPMENU_AREA 108 +#define ID_POPUPMENU_ABOUT 110 +#define ID_POPUPMENU_EXIT 111 +#define IDS_ABOUT 112 +#define IDS_ERR_MAIN 113 +#define IDS_ERR_WND 114 +#define IDS_ERR_ICON 115 +#define IDS_ERR_MENU 116 +#define IDS_ERR_POPUP 117 +#define IDS_ERR_HOOK 118 +#define IDS_ERR_MAXMIN 119 +#define IDS_RUNNING 121 +#define IDR_MAINFRAME 128 +#define IDD_MANUAL_EDITING 129 +#define IDC_EDIT_X 1000 +#define IDC_EDIT_Y 1001 +#define IDC_EDIT_WIDTH 1002 +#define IDC_EDIT_HEIGHT 1003 +#define IDC_EDIT_TITLE 1004 +#define IDC_EDIT_CLASS 1005 +#define IDC_BUTTON_SET 1006 +#define IDC_BUTTON_CLOSE 1007 +#define IDC_ABOUTHELP 1008 +#define IDC_DONATIONLINK 1009 +#define IDC_STATIC -1 -#define IDS_APP_TITLE 100 -#define IDS_CLASSNAME 101 -#define IDS_ABOUT 102 -#define IDI_TRAYICON 103 -#define IDR_MENU 104 -#define ID_POPUPMENU_ICON 105 -#define ID_POPUPMENU_AREA 106 -#define ID_POPUPMENU_ABOUT 107 -#define ID_POPUPMENU_EXIT 108 -#define IDS_ERR_MAIN 109 -#define IDS_ERR_WND 110 -#define IDS_ERR_ICON 111 -#define IDS_ERR_MENU 112 -#define IDS_ERR_POPUP 113 -#define IDS_ERR_HOOK 114 -#define IDS_RUNNING 115 -#define IDC_STATIC -1 +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_NEXT_RESOURCE_VALUE 130 +#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_CONTROL_VALUE 1010 +#define _APS_NEXT_SYMED_VALUE 122 +#endif +#endif diff --git a/wCenterWindow/targetver.h b/wCenterWindow/targetver.h new file mode 100644 index 0000000..bf75e08 --- /dev/null +++ b/wCenterWindow/targetver.h @@ -0,0 +1,6 @@ +#pragma once + +// // Including SDKDDKVer.h defines the highest available Windows platform. +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. +#include diff --git a/wCenterWindow/wCenterWindow.cpp b/wCenterWindow/wCenterWindow.cpp index dbd28a4..4b49f87 100644 --- a/wCenterWindow/wCenterWindow.cpp +++ b/wCenterWindow/wCenterWindow.cpp @@ -1,38 +1,105 @@ -// wCenterWindow, v2.1 +// wCenterWindow, v2.2 +// -#include -#include -#include "resource.h" -#include "S:\MyFunctions\MoveWindowToMonitorCenter.h" +#include "framework.h" +#include "wCenterWindow.h" -#define MAX_LOADSTRING 32 +#define KEY_I 0x49 +#define KEY_C 0x43 +#define KEY_V 0x56 + +#define MAX_LOADSTRING 50 #define WM_WCW 0x8F00 // Global variables: -HINSTANCE hInst; // Instance -CHAR szTitle[MAX_LOADSTRING]; // Window's title -CHAR szClass[MAX_LOADSTRING]; // Window's class -CHAR szAbout[MAX_LOADSTRING * 14]; // Description text -HHOOK KeyboardHook; -HICON hIcon; -HMENU hMenu, hPopup; -HWND hWnd, hTaskBar, hDesktop, hProgman; -BOOL bPressed = FALSE, bShowIcon = TRUE, bWorkArea = TRUE; -BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYI = FALSE, bKEYC = FALSE; +HINSTANCE hInst; // Instance +TCHAR szTitle[MAX_LOADSTRING]; // Window's title +TCHAR szClass[MAX_LOADSTRING]; // Window's class +TCHAR szAbout[MAX_LOADSTRING * 12]; // Description text +TCHAR szWinTitle[256]; +TCHAR szWinClass[256]; +TCHAR szWinCore[] = TEXT("Windows.UI.Core.CoreWindow"); +HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles +HICON hIcon = NULL; +HMENU hMenu = NULL, hPopup = NULL; +HWND hWnd = NULL, hFgWnd = NULL, hTaskBar = NULL, hDesktop = NULL, hProgman = NULL; +BOOL bKPressed = FALSE, bMPressed = FALSE, bShowIcon = TRUE, bWorkArea = TRUE; +BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE; +RECT rcFW = { 0 }; NOTIFYICONDATA nid = { 0 }; LPKBDLLHOOKSTRUCT pkhs; MENUITEMINFO mii; -POINT ptMousePos; -// Function's prototypes -ATOM MyRegisterClass(HINSTANCE); +// Forward declarations of functions included in this code module: VOID HandlingTrayIcon(); VOID ShowError(UINT); +BOOL CheckWindow(HWND); +BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK KeyboardHookProc(int, WPARAM, LPARAM); +LRESULT CALLBACK MouseHookProc(int, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) + + +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEX wcex = { 0 }; + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.lpfnWndProc = WndProc; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TRAYICON)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.lpszClassName = szClass; + wcex.hIconSm = wcex.hIcon; + hIcon = wcex.hIcon; + return RegisterClassEx(&wcex); +} + +VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize) +{ + RECT fgwrc; + GetWindowRect(hwnd, &fgwrc); + LONG nWidth = fgwrc.right - fgwrc.left; + LONG nHeight = fgwrc.bottom - fgwrc.top; + + MONITORINFO mi; + mi.cbSize = sizeof(MONITORINFO); + GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi); + RECT area; + if (bWorkArea) + { + area.bottom = mi.rcWork.bottom; + area.left = mi.rcWork.left; + area.right = mi.rcWork.right; + area.top = mi.rcWork.top; + } + else + { + area.bottom = mi.rcMonitor.bottom; + area.left = mi.rcMonitor.left; + area.right = mi.rcMonitor.right; + area.top = mi.rcMonitor.top; + } + + int aw = area.right - area.left; + int ah = area.bottom - area.top; + if (nWidth > aw && bResize) nWidth = aw; + if (nHeight > ah && bResize) nHeight = ah; + if (area.left < 0) aw = -aw; + if (area.top < 0) ah = -ah; + int x = (aw - nWidth) / 2; + int y = (ah - nHeight) / 2; + + SendMessage(hwnd, WM_ENTERSIZEMOVE, NULL, NULL); + MoveWindow(hwnd, x, y, nWidth, nHeight, TRUE); + SendMessage(hwnd, WM_EXITSIZEMOVE, NULL, NULL); +} + + + +int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); @@ -57,13 +124,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi } int nArgs = 0; - LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); - (nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], L"/hide")) ? bShowIcon = FALSE : bShowIcon = TRUE; + LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); + (nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], TEXT("/hide"))) ? bShowIcon = FALSE : bShowIcon = TRUE; LocalFree(szArglist); HandlingTrayIcon(); - hTaskBar = FindWindow("Shell_TrayWnd", NULL); - hProgman = FindWindow("Progman", NULL); + hTaskBar = FindWindow(TEXT("Shell_TrayWnd"), NULL); + hProgman = FindWindow(TEXT("Progman"), NULL); hDesktop = GetDesktopWindow(); MSG msg; @@ -82,21 +149,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi DispatchMessage(&msg); } } - return (int)msg.wParam; -} -ATOM MyRegisterClass(HINSTANCE hInstance) -{ - WNDCLASSEX wcex = { 0 }; - wcex.cbSize = sizeof(WNDCLASSEX); - wcex.lpfnWndProc = WndProc; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TRAYICON)); - wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); - wcex.lpszClassName = szClass; - wcex.hIconSm = wcex.hIcon; - hIcon = wcex.hIcon; - return RegisterClassEx(&wcex); + if (hMouseHook) UnhookWindowsHookEx(hMouseHook); + if (hKbdHook) UnhookWindowsHookEx(hKbdHook); + if (hMenu) DestroyMenu(hMenu); + Shell_NotifyIcon(NIM_DELETE, &nid); + + return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) @@ -134,8 +193,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) nid.dwInfoFlags = NIIF_INFO; StringCchCopy(nid.szTip, _countof(nid.szTip), szTitle); - KeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); - if (!KeyboardHook) + hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, hInst, NULL); + if (!hMouseHook) + { + ShowError(IDS_ERR_HOOK); + SendMessage(hWnd, WM_CLOSE, NULL, NULL); + } + + hKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL); + if (!hKbdHook) { ShowError(IDS_ERR_HOOK); SendMessage(hWnd, WM_CLOSE, NULL, NULL); @@ -147,7 +213,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_WCW: { - if (lParam == WM_RBUTTONDOWN && wParam == IDI_TRAYICON) + if ((lParam == WM_RBUTTONDOWN || lParam == WM_LBUTTONDOWN) && wParam == IDI_TRAYICON) { SetForegroundWindow(hWnd); POINT pt; @@ -164,10 +230,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED; SetMenuItemInfo(hPopup, ID_POPUPMENU_AREA, FALSE, &mii); } - if (idMenu == ID_POPUPMENU_ABOUT && !bPressed) + if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed) { - bPressed = TRUE; - if (MessageBox(hWnd, szAbout, szTitle, MB_OK | MB_TOPMOST | MB_ICONINFORMATION) == IDOK) bPressed = FALSE; + bKPressed = TRUE; + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About); + bKPressed = FALSE; } if (idMenu == ID_POPUPMENU_EXIT) SendMessage(hWnd, WM_CLOSE, NULL, NULL); } @@ -176,9 +243,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: { - if (KeyboardHook) UnhookWindowsHookEx(KeyboardHook); - if (hMenu) DestroyMenu(hMenu); - Shell_NotifyIcon(NIM_DELETE, &nid); PostQuitMessage(0); } break; @@ -189,6 +253,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return 0; } +LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) +{ + if (wParam == WM_MBUTTONUP) bMPressed = FALSE; + if (wParam == WM_MBUTTONDOWN && bLCTRL && bLWIN && !bMPressed) + { + bMPressed = TRUE; + hFgWnd = GetForegroundWindow(); + BOOL bApproved = CheckWindow(hFgWnd); + if (bApproved) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); + else hFgWnd = NULL; + } + return CallNextHookEx(NULL, nCode, wParam, lParam); +} LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { @@ -198,7 +275,7 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { if (pkhs->vkCode == VK_LCONTROL) bLCTRL = FALSE; if (pkhs->vkCode == VK_LWIN) bLWIN = FALSE; - bPressed = FALSE; + bKPressed = FALSE; } if (wParam == WM_KEYDOWN) @@ -206,39 +283,105 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) if (pkhs->vkCode == VK_LCONTROL) bLCTRL = TRUE; if (pkhs->vkCode == VK_LWIN) bLWIN = TRUE; - if (bLCTRL && bLWIN && pkhs->vkCode == 0x49 && !bPressed) // 'I' key + if (bLCTRL && bLWIN && pkhs->vkCode == KEY_I && !bKPressed) // 'I' key { - bPressed = TRUE; + bKPressed = TRUE; bShowIcon = !bShowIcon; HandlingTrayIcon(); return TRUE; } - if (bLCTRL && bLWIN && pkhs->vkCode == 0x43 && !bPressed) // 'C' key + if (bLCTRL && bLWIN && pkhs->vkCode == KEY_C && !bKPressed && !bKEYV) // 'C' key { - bPressed = TRUE; - HWND hFgWnd = GetForegroundWindow(); + bKPressed = TRUE; + hFgWnd = GetForegroundWindow(); + BOOL bApproved = CheckWindow(hFgWnd); + if (bApproved) MoveWindowToMonitorCenter(hFgWnd, bWorkArea, FALSE); + else hFgWnd = NULL; + return TRUE; + } - if (hFgWnd) - { - if (hFgWnd != hDesktop && hFgWnd != hTaskBar && hFgWnd != hProgman) - { - if (!IsIconic(hFgWnd) && !IsZoomed(hFgWnd)) - { - RECT fgwrc; - GetWindowRect(hFgWnd, &fgwrc); - LONG fgWidth = fgwrc.right - fgwrc.left; - LONG fgHeight = fgwrc.bottom - fgwrc.top; - MoveWindowToMonitorCenter(hFgWnd, fgWidth, fgHeight, bWorkArea, FALSE); - } - } - } + if (bLCTRL && bLWIN && pkhs->vkCode == KEY_V && !bKPressed && !bKEYV) // 'V' key + { + bKPressed = TRUE; bKEYV = TRUE; + hFgWnd = GetForegroundWindow(); + BOOL bApproved = CheckWindow(hFgWnd); + if (bApproved) DialogBox(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hWnd, (DLGPROC)DlgProc); + else hFgWnd = NULL; + bKEYV = FALSE; return TRUE; } } return CallNextHookEx(NULL, nCode, wParam, lParam); } +BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam) +{ + int x, y, w, h; + switch (dlgmsg) + { + case WM_INITDIALOG: + { + SetWindowText(hDlg, szTitle); + GetWindowText(hFgWnd, szWinTitle, _countof(szWinTitle)); + GetClassName(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); + SetDlgItemText(hDlg, IDC_EDIT_TITLE, szWinTitle); + SetDlgItemText(hDlg, IDC_EDIT_CLASS, szWinClass); + UpdateWindow(hDlg); + break; + } + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDC_BUTTON_SET: + { + 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); + SendMessage(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL); + MoveWindow(hFgWnd, x, y, w, h, TRUE); + SendMessage(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL); + return TRUE; + break; + } + case IDCANCEL: + case IDC_BUTTON_CLOSE: + { + EndDialog(hDlg, LOWORD(wParam)); + break; + } + } + } + return FALSE; +} + +BOOL CheckWindow(HWND hFW) +{ + GetClassName(hFW, szWinClass, _countof(szWinClass)); + if (hFW) + { + if (_tcscmp(szWinClass, szWinCore) != 0) + { + if (hFW != hDesktop && hFW != hTaskBar && hFW != hProgman) + { + if (!IsIconic(hFW) && !IsZoomed(hFW)) return TRUE; + else ShowError(IDS_ERR_MAXMIN); + } + } + } + return FALSE; +} + VOID HandlingTrayIcon() { if (bShowIcon) @@ -257,7 +400,53 @@ VOID HandlingTrayIcon() VOID ShowError(UINT uID) { - CHAR szErrorText[MAX_LOADSTRING]; // Error's text + TCHAR szErrorText[MAX_LOADSTRING]; // Error's text LoadString(hInst, uID, szErrorText, _countof(szErrorText)); - MessageBox(hWnd, szErrorText, szTitle, MB_OK | MB_ICONERROR); + MessageBox(hWnd, szErrorText, szTitle, MB_OK | MB_ICONERROR | MB_TOPMOST); +} + +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + INITCOMMONCONTROLSEX icex; + icex.dwSize = sizeof(INITCOMMONCONTROLSEX); + icex.dwICC = ICC_LINK_CLASS; + InitCommonControlsEx(&icex); + + switch (message) + { + case WM_INITDIALOG: + { + SetDlgItemText(hDlg, IDC_ABOUTHELP, szAbout); + return (INT_PTR)TRUE; + break; + } + + case WM_NOTIFY: + { + LPNMHDR pNMHdr = (LPNMHDR)lParam; + switch (pNMHdr->code) + { + case NM_CLICK: + case NM_RETURN: + if (pNMHdr->idFrom == IDC_DONATIONLINK) + { + PNMLINK pNMLink = (PNMLINK)pNMHdr; + LITEM item = pNMLink->item; + ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); + return (INT_PTR)TRUE; + } + break; + } + break; + } + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + break; + } + } + return (INT_PTR)FALSE; } diff --git a/wCenterWindow/wCenterWindow.h b/wCenterWindow/wCenterWindow.h new file mode 100644 index 0000000..d00d47e --- /dev/null +++ b/wCenterWindow/wCenterWindow.h @@ -0,0 +1,3 @@ +#pragma once + +#include "resource.h" diff --git a/wCenterWindow/wCenterWindow.rc b/wCenterWindow/wCenterWindow.rc index 75288f23ffb151c13c027cd8eb91cb5346fb56e5..5079055d857c789ca33d5c118789888c126edeb5 100644 GIT binary patch literal 14622 zcmeI3X-^wj7KZQVk>)>CJ0Fs0Xc8dZ=|nvvfmzj#u~>r?$s%D1YBm|ugwg!=?s=bk ze7IG1l^3#zXh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BPgG?wnuPuf^} zCU{yV^5#Boq+P>rWUh5vNw`&aY(d1$hSn{M1z|-_WL147oj<7GM-#<+eH1EnKup#- ziZF^p*Pq1J&~v_Z{d zTUTWGz~<^wz(;i=@7~z&BS=9`Y7Sn| zNnUUrBjNi!VQHQ*3jCn@0NsJ2cE5sr@qtJvBoVSaV5sip(CnVcdx{Ok3=yi*tnvaZ zLX|w;J;zM$aDHN*k`(W2B6`3PDvnt}dz!Q<^ITt1d8s$VH`=`CER&enF+=y7s_m!! zbK9H{?+VNHTSmn9RPJz)z)= - + Debug @@ -19,37 +19,38 @@ - 15.0 - {2494B3F2-585E-4A2E-A013-20A15AE25B9E} + 16.0 + Win32Proj + {f1a1603a-f5d0-47b8-8e4b-cf17747bcfba} wCenterWindow - 10.0.17763.0 + 10.0 Application true - v141 - MultiByte + v142 + Unicode Application false - v141 + v142 true - MultiByte + Unicode Application true - v141 - MultiByte + v142 + Unicode Application false - v141 + v142 true - MultiByte + Unicode @@ -69,37 +70,42 @@ - + + true + + + false + false + + + true + + + false + Level3 - Disabled true + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true Windows - false - - - - - Level3 - Disabled - true - true - - - Console + true + comctl32.lib;%(AdditionalDependencies) + + $(ProjectName).manifest %(AdditionalManifestFiles) + Level3 - MaxSpeed true true true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true MultiThreaded @@ -107,35 +113,59 @@ Windows true true - HighestAvailable false + comctl32.lib;%(AdditionalDependencies) + + + $(ProjectName).manifest %(AdditionalManifestFiles) + + + + + Level3 + true + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true Level3 - MaxSpeed true true true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - Console + Windows true true + true - + + + + + + - - + - + + + + + diff --git a/wCenterWindow/wCenterWindow.vcxproj.filters b/wCenterWindow/wCenterWindow.vcxproj.filters index 04f26e0..3d0c9ac 100644 --- a/wCenterWindow/wCenterWindow.vcxproj.filters +++ b/wCenterWindow/wCenterWindow.vcxproj.filters @@ -3,36 +3,52 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + Source Files - - Source Files - - - - - Header Files - - - Header Files - Resource Files + + + Resource Files + + + Resource Files + + + + + Resource Files + + \ No newline at end of file diff --git a/wCenterWindow/wCenterWindow.vcxproj.user b/wCenterWindow/wCenterWindow.vcxproj.user index 6e2aec7..0f14913 100644 --- a/wCenterWindow/wCenterWindow.vcxproj.user +++ b/wCenterWindow/wCenterWindow.vcxproj.user @@ -1,4 +1,4 @@  - + \ No newline at end of file