-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestoreMovedWindows.c
84 lines (68 loc) · 1.91 KB
/
RestoreMovedWindows.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <shlwapi.h>
#include <strsafe.h>
#include "ListWindows.h"
typedef struct CallbackParams
{
BOOL noRestore;
int screenRight;
} CallbackParams;
static BOOL CALLBACK enum_windows_callback(HWND hwnd, LPARAM lparam)
{
CallbackParams *params = (CallbackParams*)lparam;
UNREFERENCED_PARAMETER(lparam);
HWND shellHwnd = GetShellWindow();
if(hwnd == shellHwnd)
{
return TRUE;
}
LONG styles = GetWindowLong(hwnd, GWL_STYLE);
LONG exStyles = GetWindowLong(hwnd, GWL_EXSTYLE);
BOOL isRootWindow = list_windows_is_root_window(hwnd, styles, exStyles);
if(!isRootWindow)
{
return TRUE;
}
if(!(styles & WS_VISIBLE))
{
return TRUE;
}
RECT windowRect;
GetWindowRect(hwnd, &windowRect);
if(windowRect.right > params->screenRight)
{
CHAR title[1024];
GetWindowTextA(
hwnd,
title,
sizeof(title)/sizeof(TCHAR));
if(strstr(title, "Progman"))
{
return TRUE;
}
if(strstr(title, "ApplicationFrameWindow"))
{
return TRUE;
}
printf("Restoring window, title: %s right: %d\n", title, windowRect.right);
if(!params->noRestore)
{
SetWindowPos(hwnd, NULL, 25, 25, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
}
return TRUE;
}
int main(int argc, char *argv[])
{
CallbackParams params = { FALSE, 0 };
if (argc >= 2 && strcmp(argv[1], "--NoRestore") == 0)
{
params.noRestore = TRUE;
}
params.screenRight = GetSystemMetrics(SM_CXMAXTRACK);
printf("Params: screenRight: %d, noRestore: %d\n", params.screenRight, params.noRestore);
EnumWindows(enum_windows_callback, (LPARAM)¶ms);
return 0;
}