问题描述
该应用程序的代码。一个cosntraint 是伸展的应用程序不会注意它,所以如果应用程序查询创建的窗口大小,它会看到原始大小和我设法使用
SetWindowsHookEx
来调整窗口大小: / p> HHOOK hMessHook = SetWindowsHookEx(WH_CBT,CBTProc,hInst,0);
和:
LRESULT CALLBACK CBTProc(__in int nCode,
__in WPARAM wParam,
__in LPARAM lParam)
{
if(HCBT_CREATEWND == nCode)
{
CBT_CREATEWND * WndData =(CBT_CREATEWND *)lParam;
//计算newWidth和newHeight值...
WndData-> lpcs-> cx = newWidth;
WndData-> lpcs-> cy = newHeight;
}
CallNextHookEx(hMessHook,nCode,wParam,lParam);
}
我面临的问题是我无法使
例如,如果创建了.NET表单:
public class SimpleForm:Form
{
public SimpleForm()
{
Width = 100;
Height = 200;
}
}
稍后查询大小:
void QuerySize(SimpleForm form)
{
int width = form.Width;
int height = form.Height;
}
我想要 code>
和 height
be 100
$ c> 200 ,而不是调整大小的值。我无法找到查询现有窗口大小的正确挂钩。
挂钩窗口大小查询的正确方法是什么?
$ b $不幸的是,对窗口大小的查询不是由消息处理的 - 它们是直接的API调用,例如 - 因此无法拦截通过标准的Windows钩子。您可能希望查看,它允许您挂接任意的Win32函数。 (您可以在Deuturs 找到教程)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)
这篇关于挂钩Win32窗口创建/调整大小/查询大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!