-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (51 loc) · 2.16 KB
/
main.cpp
File metadata and controls
62 lines (51 loc) · 2.16 KB
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
#include "classes/overlay.h"
#define OVERLAY_Y_OFFSET 107
int main(int argc, char* argv[])
{
Overlay overlay;
if (!overlay.Init()) return 0;
HWND hwnd_overlay = overlay.Show();
HANDLE sf2 = overlay.Run("..\\SIDFactoryII.exe", *argv);
SDL_Delay(400); // HWND is 0 if too fast
HWND hwnd_sf2 = overlay.GetWindow(sf2),
foreground, last_foreground = GetForegroundWindow();
RECT rc, rcOverlay, rcSF2;
SDL_Event event;
// Don't set milliseconds to 0 (smooth but eats CPU time)
while (overlay.IsRunning(sf2, 10))
{
// Must poll messages or Windows will think the program is dead
SDL_PollEvent(&event);
if (event.type == SDL_QUIT) return 0; // Close overlay only
GetWindowRect(hwnd_sf2, &rcSF2);
GetWindowRect(hwnd_overlay, &rcOverlay);
CopyRect(&rc, &rcSF2);
OffsetRect(&rcOverlay, -rcOverlay.left, -rcOverlay.top);
OffsetRect(&rc, -rc.left, -rc.top);
OffsetRect(&rc, -rcOverlay.right, -rcOverlay.bottom);
// Move the overlay in sync with SF2
SetWindowPos(hwnd_overlay,
HWND_TOP,
rcSF2.left + (rc.right / 2),
rcSF2.top + (rc.bottom / 2) - OVERLAY_Y_OFFSET,
0, 0, // Ignore size
SWP_NOSIZE);
foreground = GetForegroundWindow();
if (foreground != last_foreground)
{
last_foreground = foreground;
if (foreground == hwnd_sf2)
{
// If SF2 is made active again then also set the overlay active just behind it
SetWindowPos(hwnd_overlay, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
SetWindowPos(hwnd_overlay, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(hwnd_sf2, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(hwnd_sf2, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}
else if (foreground == hwnd_overlay)
// If the overlay is made active then make sure SF2 gets the attention on top of it
SetForegroundWindow(hwnd_sf2);
}
}
return 0;
}