Skip to content

Commit dbeec07

Browse files
Extend frame after successful hooking.
1 parent 019fa24 commit dbeec07

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

ExplorerFrame/ExplorerFrame.cpp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
143143
}
144144
catch (...) {}
145145
}
146+
146147
PostQuitMessage(0);
147148
break;
148149
}
@@ -185,6 +186,36 @@ void WinEventProc(
185186
HandleWindow(hwnd);
186187
}
187188

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+
188219
void HandleWindow(HWND hwnd)
189220
{
190221
DWORD processId;
@@ -196,15 +227,33 @@ void HandleWindow(HWND hwnd)
196227
CloseHandle(processHandle);
197228

198229
// 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)
200231
{
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+
}
209258
}
210259
}

ExplorerFrame/ExplorerFrame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void WinEventProc(
2222
DWORD dwmsEventTime);
2323
void HandleWindow(HWND hwnd);
2424

25+
bool IsWindowOfInterest(HWND);
26+
2527
// Define SetPreferredAppMode
2628
typedef enum PREFERRED_APP_MODE
2729
{

ExplorerFrame/ExplorerFrame.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
<ClCompile>
7575
<LanguageStandard>stdcpp20</LanguageStandard>
7676
</ClCompile>
77+
<Link>
78+
<AdditionalDependencies>dwmapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
79+
</Link>
7780
</ItemDefinitionGroup>
7881
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
7982
<ClCompile>

ExplorerFrame/framework.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
#include <tchar.h>
1616
#include <psapi.h>
1717
#include <shellapi.h>
18-
#include <windowsx.h>
18+
#include <windowsx.h>
19+
#include <dwmapi.h>

0 commit comments

Comments
 (0)