Hooking Win32 windows creation/resize/querying sizes

允我心安 提交于 2019-12-06 07:32:18

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/5204717/hooking-win32-windows-creation-resize-querying-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!