Im trying to resize an external process' window smaller than its minimum size constraint. What I tried to do was to inject a .dll and overwrite the WM_GETMINMAXINFO message, setting the ptMinTrackSize to {0,0}.
However this doesn't seem to work.
static LRESULT CALLBACK msghook(int code, WPARAM wParam, LPARAM lParam);
BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
hInstance = hInst;
return TRUE;
case DLL_PROCESS_DETACH:
if (hwndServer != NULL)
{
clearMyHook(hwndServer);
}
return TRUE;
}
}
_declspec(dllexport) BOOL setMyHook(HWND hwnd)
{
if (hwndServer != NULL)
{
return FALSE;
}
hook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)msghook, hInstance, 0);
if (hook != NULL)
{
hwndServer = hwnd;
return TRUE;
}
return FALSE;
}
_declspec(dllexport) BOOL clearMyHook(HWND hwnd)
{
if (hwnd != hwndServer)
{
return FALSE;
}
BOOL unhooked = UnhookWindowsHookEx(hook);
if (unhooked)
{
hwndServer = NULL;
}
return unhooked;
}
static LRESULT CALLBACK msghook(int code, WPARAM wParam, LPARAM lParam)
{
if (code < 0)
{
CallNextHookEx(hook, code, wParam, lParam);
return 0;
}
LPMSG msg = (LPMSG)lParam;
if (msg->message == WM_GETMINMAXINFO)
{
MINMAXINFO* mmInfo = (MINMAXINFO*)(lParam);
mmInfo->ptMinTrackSize.x = 0;
mmInfo->ptMinTrackSize.y = 0;
}
return CallNextHookEx(hook, code, wParam, lParam);
}
I'm then building my .exe including the .dll and linking the .lib and calling setMyHook() from there. I'm fairly new to the topic of .dll injection. Am I doing something wrong here, or is this simply not possible with the above approach?
Thanks..