I currently have an IntPtr of a window handle, and I tried getting its Window using HwndSource.FromHwnd but it returns null. If the Window element was retrieved, it would have been possible to set its MaxWidth attribute.
Are there other ways to set the maximum width just from having a window handle of an external application?
EDIT: Trying to see if RbMm's approach works. The question's tagged C# but this could be worth a shot using a C++ custom DLL:
bool InitializeMaxWidthHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
{
return false;
}
SetProp(GetDesktopWindow(), "WILSON_HOOK_HCBT_MINMAX", destination);
hookMaxWidth = SetWindowsHookEx(WH_CBT, (HOOKPROC)MinMaxHookCallback, g_appInstance, threadID);
return hookMaxWidth != NULL;
}
void UninitializeMaxWidthHook()
{
if (hookMaxWidth != NULL)
UnhookWindowsHookEx(hookMaxWidth);
hookMaxWidth = NULL;
}
static LRESULT CALLBACK MinMaxHookCallback(int code, WPARAM wparam, LPARAM lparam)
{
if (code >= 0)
{
UINT msg = 0;
if (code == HCBT_MINMAX)
msg = RegisterWindowMessage("WILSON_HOOK_HCBT_MINMAX");
HWND dstWnd = (HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HCBT_MINMAX");
if (msg != 0)
SendNotifyMessage(dstWnd, msg, wparam, lparam);
}
return CallNextHookEx(hookMaxWidth, code, wparam, lparam);
}
I'll update the question again after tinkering with this.