I'm trying to "stretch" an existing application.
The goal is to make an existing application become larger without changing the code of that application.
A cosntraint is that the stretched application will not "notice" it, so if the application query a created window size it'll see the original size and not the resized size.
I managed to resize the windows using SetWindowsHookEx
:
HHOOK hMessHook = SetWindowsHookEx(WH_CBT,CBTProc, hInst, 0);
And:
LRESULT CALLBACK CBTProc( __in int nCode,
__in WPARAM wParam,
__in LPARAM lParam)
{
if (HCBT_CREATEWND == nCode)
{
CBT_CREATEWND *WndData = (CBT_CREATEWND*) lParam;
// Calculate newWidth and newHeight values...
WndData->lpcs->cx = newWidth;
WndData->lpcs->cy = newHeight;
}
CallNextHookEx(hMessHook, nCode, wParam, lParam);
}
The problem I'm facing is that I'm unable to the make the stretched application see the original sizes.
For example, if a .NET form is created:
public class SimpleForm : Form
{
public SimpleForm()
{
Width = 100;
Height = 200;
}
}
And later the size is queried:
void QuerySize(SimpleForm form)
{
int width = form.Width;
int height = form.Height;
}
I'd like width
and height
be 100
and 200
and not the resized values. I was unable to find the right hook which queries the size of an existing window.
What is the right way to hook window size querying?
Unfortunately, queries for window size aren't handled by messages -- they are direct API calls such as
GetWindowRect
-- so they can't be intercepted by standard Windows hooks. You might want to look into the Detours API, which allows you to hook arbitrary Win32 functions. (You can find a tutorial on Detours here)