@@ -143,6 +143,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
143
143
}
144
144
catch (...) {}
145
145
}
146
+
146
147
PostQuitMessage (0 );
147
148
break ;
148
149
}
@@ -185,6 +186,36 @@ void WinEventProc(
185
186
HandleWindow (hwnd);
186
187
}
187
188
189
+ bool IsWindowOfInterest (HWND hWnd)
190
+ {
191
+ if (!IsWindow (hWnd) || !IsWindowVisible (hWnd))
192
+ return false ;
193
+
194
+ WCHAR lpClassName[MAX_PATH];
195
+
196
+ GetClassName (hWnd, lpClassName, MAX_PATH);
197
+
198
+ auto styleEx = GetWindowLongPtrW (hWnd, GWL_EXSTYLE);
199
+
200
+ if (styleEx & WS_EX_NOACTIVATE || styleEx & WS_EX_LAYERED)
201
+ return false ;
202
+
203
+ if (styleEx & WS_EX_APPWINDOW)
204
+ return true ;
205
+
206
+ auto style = GetWindowLongPtrW (hWnd, GWL_STYLE);
207
+
208
+ if (!style)
209
+ return false ;
210
+
211
+ auto hasTitleBar = style & WS_BORDER && style & WS_DLGFRAME;
212
+
213
+ if ((styleEx & WS_EX_TOOLWINDOW || style & WS_POPUP) && !hasTitleBar)
214
+ return false ;
215
+
216
+ return true ;
217
+ }
218
+
188
219
void HandleWindow (HWND hwnd)
189
220
{
190
221
DWORD processId;
@@ -196,15 +227,33 @@ void HandleWindow(HWND hwnd)
196
227
CloseHandle (processHandle);
197
228
198
229
// Check if the process is the Windows Explorer
199
- if (_wcsicmp (processName, L" C:\\ Windows\\ explorer.exe" ) == 0 && hookingMap. find (tid) == hookingMap. end () )
230
+ if (_wcsicmp (processName, L" C:\\ Windows\\ explorer.exe" ) == 0 )
200
231
{
201
- HMODULE dll = LoadLibrary (L" Injector.dll" );
202
- if (!dll)
203
- return ;
204
- auto procAddr = GetProcAddress (dll, " InjectExplorerHook" );
205
- auto method = reinterpret_cast <PFN_INJECT_EXPLORER_HOOK>(procAddr);
206
- HHOOK hook = method (hwnd);
207
- hookingMap.insert (std::pair<DWORD, HHOOK>(tid, hook));
208
- FreeLibrary (dll);
232
+ bool isInjectionSuccessful = true ;
233
+ if (hookingMap.find (tid) == hookingMap.end ())
234
+ {
235
+ HMODULE dll = LoadLibrary (L" Injector.dll" );
236
+ if (!dll)
237
+ return ;
238
+ auto procAddr = GetProcAddress (dll, " InjectExplorerHook" );
239
+ auto method = reinterpret_cast <PFN_INJECT_EXPLORER_HOOK>(procAddr);
240
+ HHOOK hook = method (hwnd);
241
+ if (hook != NULL )
242
+ hookingMap.insert (std::pair<DWORD, HHOOK>(tid, hook));
243
+ else
244
+ isInjectionSuccessful = false ;
245
+ FreeLibrary (dll);
246
+ }
247
+
248
+ if (IsWindowOfInterest (hwnd) && isInjectionSuccessful)
249
+ {
250
+ MARGINS margins = MARGINS {
251
+ .cxLeftWidth = -1 ,
252
+ .cxRightWidth = -1 ,
253
+ .cyTopHeight = -1 ,
254
+ .cyBottomHeight = -1
255
+ };
256
+ DwmExtendFrameIntoClientArea (hwnd, &margins);
257
+ }
209
258
}
210
259
}
0 commit comments