挂钩 Win32 窗口创建/调整大小/查询大小
我正在尝试“扩展”现有的应用程序。
目标是在不更改现有应用程序代码的情况下使现有应用程序变得更大。
一个约束是拉伸的应用程序不会“注意到”它,因此如果应用程序查询创建的窗口大小,它将看到原始大小,而不是调整后的大小。
我设法使用 SetWindowsHookEx
调整窗口大小:
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;
// Calculate newWidth and newHeight values...
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;
}
我想要 宽度
和 高度
< /em> 为 100
和 200
,而不是调整大小的值。我无法找到查询现有窗口大小的正确钩子。
挂钩窗口大小查询的正确方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,窗口大小的查询不是由消息处理的——它们是直接的 API 调用,例如
GetWindowRect
- 因此它们不能被标准 Windows 挂钩拦截。您可能需要查看 Detours API,它允许您挂钩任意Win32 函数。 (您可以在此处找到有关 Detours 的教程)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)