Skip to content

Commit

Permalink
Restore maximized windows before resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
alvesvaren committed Oct 5, 2024
1 parent f2401ec commit 9ae062a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions resizer2/resizer2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ static HMONITOR SysGetMonitorContainingPoint(int x, int y) {
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
// Register window class for tray icon
const wchar_t CLASS_NAME[] = L"TrayIconWindowClass";

WNDCLASS wc = {};
Expand All @@ -215,7 +214,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine

RegisterClass(&wc);

// Create a window (hidden, just for receiving messages)
HWND hWnd = CreateWindowEx(0, CLASS_NAME, L"Resizer", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
Expand All @@ -224,7 +222,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
return 0;
}

// Add the tray icon
AddTrayIcon(hWnd);

hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, 0);
Expand All @@ -235,7 +232,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
return 1;
}

// Main message loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
Expand Down Expand Up @@ -489,6 +485,13 @@ DWORD WINAPI WindowOperationThreadProc(LPVOID lpParam) {
SetGlobalCursor<SIZENESW>();
}

// Restore window if maximized
WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(ctx.targetWindow, &wp);
if (wp.showCmd == SW_MAXIMIZE) {
ShowWindow(ctx.targetWindow, SW_RESTORE);
}

while (ctx.inProgress) {
if (WaitForSingleObject(ctx.hEvent, 0) == WAIT_OBJECT_0) {
break;
Expand Down

0 comments on commit 9ae062a

Please sign in to comment.