-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (99 loc) · 3.93 KB
/
Copy pathmain.cpp
File metadata and controls
123 lines (99 loc) · 3.93 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright 2023 GregVido
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <Windows.h>
#include <iostream>
#include <vector>
#include <psapi.h>
#include "app.h"
const int max_length = 256;
char *processSearch;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
std::vector<HWND> *handles = reinterpret_cast<std::vector<HWND> *>(lParam);
DWORD processId;
GetWindowThreadProcessId(hwnd, &processId);
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
char processName[max_length] = "";
HMODULE moduleHandle;
DWORD cbNeeded;
if (EnumProcessModules(processHandle, &moduleHandle, sizeof(moduleHandle), &cbNeeded))
{
GetModuleBaseNameA(processHandle, moduleHandle, processName, sizeof(processName) / sizeof(char));
}
CloseHandle(processHandle);
char *result = strstr(processName, processSearch);
if (result)
{
std::cout << "Window process name: " << processName << " HWND: " << hwnd << std::endl;
handles->push_back(hwnd);
}
return TRUE;
}
int applyEffect(char *processName, int effect)
{
processSearch = processName;
std::vector<HWND> notepadHandles;
// Find Notepad window handle
EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(¬epadHandles));
if (notepadHandles.empty())
{
std::cout << "No windows found." << std::endl;
return 1;
}
const HINSTANCE dwmapi = LoadLibrary(TEXT("dwmapi.dll"));
const pDwmSetWindowAttribute DwmSetWindowAttribute = (pDwmSetWindowAttribute)GetProcAddress(dwmapi, "DwmSetWindowAttribute");
const pDwmExtendFrameIntoClientArea DwmExtendFrameIntoClientArea = (pDwmExtendFrameIntoClientArea)GetProcAddress(dwmapi, "DwmExtendFrameIntoClientArea");
for (const HWND &hwnd : notepadHandles)
{
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &effect, sizeof(int));
MARGINS margins = {-1};
DwmExtendFrameIntoClientArea(hwnd, &margins);
}
FreeLibrary(dwmapi);
return 0;
}
int main(int argc, char **argv)
{
if (argc == 2 && strcmp(argv[1], "--help") == 0)
{
std::cout << "Run the command like this : app.exe <processname> <effect>\n" << std::endl;
std::cout << "<processname>" << std::endl;
std::cout << "\tprocess name (ex: Notepad, explorer)\n"
<< std::endl;
std::cout << "<effect>" << std::endl;
std::cout << "\teffect name" << std::endl;
std::cout << "\t\t- mica : applies the mica effect" << std::endl;
std::cout << "\t\t- tabbed_mica : applies the tabbed mica effect" << std::endl;
std::cout << "\t\t- acrylic : apply an acrylic effect" << std::endl;
std::cout << "\t\t- none : deactivate the effect" << std::endl;
std::cout << "\nVersion: 1.0" << std::endl;
return 1;
}
if (argc != 3)
{
std::cout << "Command failed (app.exe <processname> <effect>)" << std::endl;
std::cout << "app.exe --help for more info" << std::endl;
return 0;
}
if (strcmp(argv[2], "mica") == 0)
return applyEffect(argv[1], 2);
if (strcmp(argv[2], "tabbed_mica") == 0)
return applyEffect(argv[1], 4);
if (strcmp(argv[2], "acrylic") == 0)
return applyEffect(argv[1], 3);
if (strcmp(argv[2], "none") == 0)
return applyEffect(argv[1], 1);
std::cout << "Unknown effect" << std::endl;
std::cout << "app.exe --help for more info" << std::endl;
return 0;
}