Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (86 loc) · 3.9 KB
/
Copy pathmain.cpp
File metadata and controls
104 lines (86 loc) · 3.9 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// main.cpp -- entry point, tray initialisation, hotkey apply
// All other logic lives in the following modules:
// utils.cpp -- globals, DebugLog, IsRunAsAdmin, CustomDialogProc
// display.cpp -- EnumerateMonitors, PopulateResolutions, ChangeRes
// config.cpp -- SaveConfig, LoadConfig
// font.cpp -- EnsureJetBrainsMono
// controls.cpp -- SubclassHotkey, SubclassCombo, subclass procs
// wndproc.cpp -- WindowProc (all WM_ handlers)
#include "globals.h"
// ---- System tray setup ----
void InitTray(HWND hwnd) {
DebugLog("Initializing system tray");
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd;
nid.uID = ID_TRAY_APP_ICON;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYICON;
HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(100));
if (!hIcon) hIcon = LoadIcon(NULL, IDI_APPLICATION);
nid.hIcon = hIcon;
lstrcpyA((LPSTR)nid.szTip, "MORPHIX - Resolution Changer");
Shell_NotifyIcon(NIM_ADD, &nid);
}
// ---- Register the current hotkey values with the OS ----
void ApplyHotkeys(HWND hwnd) {
DebugLog("Applying new hotkeys");
UnregisterHotKey(hwnd, HOTKEY_GAME_MODE);
UnregisterHotKey(hwnd, HOTKEY_NORMAL_MODE);
UnregisterHotKey(hwnd, HOTKEY_COLOR1);
UnregisterHotKey(hwnd, HOTKEY_COLOR2);
WORD modGame = LOWORD(SendMessage(hHotkeyGame, HKM_GETHOTKEY, 0, 0));
WORD modNormal = LOWORD(SendMessage(hHotkeyNormal, HKM_GETHOTKEY, 0, 0));
WORD modColor1 = LOWORD(SendMessage(hHotkeyColor1, HKM_GETHOTKEY, 0, 0));
WORD modColor2 = LOWORD(SendMessage(hHotkeyColor2, HKM_GETHOTKEY, 0, 0));
if (modGame > 0) gameHotkey = modGame;
if (modNormal > 0) normalHotkey = modNormal;
if (modColor1 > 0) colorHotkey1 = modColor1;
if (modColor2 > 0) colorHotkey2 = modColor2;
RegisterHotKey(hwnd, HOTKEY_GAME_MODE, MOD_NOREPEAT, gameHotkey);
RegisterHotKey(hwnd, HOTKEY_NORMAL_MODE, MOD_NOREPEAT, normalHotkey);
RegisterHotKey(hwnd, HOTKEY_COLOR1, MOD_NOREPEAT, colorHotkey1);
RegisterHotKey(hwnd, HOTKEY_COLOR2, MOD_NOREPEAT, colorHotkey2);
DebugLog("Hotkeys applied: Game=0x%X, Normal=0x%X, Color1=0x%X, Color2=0x%X",
gameHotkey, normalHotkey, colorHotkey1, colorHotkey2);
}
// ---- Application entry point ----
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
EnsureJetBrainsMono();
if (DEBUG_MODE) {
AllocConsole();
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
SetConsoleTitleA("MORPHIX Debug Console");
}
DebugLog("MORPHIX starting up");
// Build path to config.ini next to the exe
GetModuleFileNameA(NULL, configFile, MAX_PATH);
char* lastSlash = strrchr(configFile, '\\');
if (lastSlash) strcpy(lastSlash + 1, "config.ini");
// Common controls (needed for the HotKey control class)
INITCOMMONCONTROLSEX icex = { sizeof(INITCOMMONCONTROLSEX), ICC_HOTKEY_CLASS };
InitCommonControlsEx(&icex);
HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(100));
if (!hIcon) hIcon = LoadIcon(NULL, IDI_APPLICATION);
WNDCLASSA wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = "ACRClass";
wc.hbrBackground = CreateSolidBrush(RGB(32, 32, 32));
wc.hIcon = hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClassA(&wc);
HWND hwnd = CreateWindowA("ACRClass", "MORPHIX",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 786, 448,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_HIDE);
InitNVAPI(); // Load NVAPI for digital vibrance (DVC) support; no-op if unavailable
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}