挂钩的Win32窗口创建/调整/大小查询 [英] Hooking Win32 windows creation/resize/querying sizes

查看:234
本文介绍了挂钩的Win32窗口创建/调整/大小查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拉伸现有的应用程序。

I'm trying to "stretch" an existing application.

目标是使现有的应用程序变得不改变该应用程序的code大。结果
:一种cosntraint 是用于拉伸应用程序不会通知,所以如果应用程序查询创建的窗口大小,它会看到原来的大小,而不是调整大小的尺寸。

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.

我设法使用,以调整窗口大小的 和SetWindowsHookEx 的:

I managed to resize the windows using 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);
}

我现在面临的问题是,我无法使该拉伸的应用程序查看原始大小。

The problem I'm facing is that I'm unable to the make the stretched application see the original sizes.

例如,如果创建一个.NET形式:

For example, if a .NET form is created:

public class SimpleForm : Form
{
    public SimpleForm()
    {
        Width = 100;
        Height = 200;
    }
}

和后来的大小查询:

void QuerySize(SimpleForm form)
{
   int width = form.Width;
   int height = form.Height;
}

我想的 宽度 的和的 高度 的为 100 200 ,而不是调整值。我无法找到合适的钩子,查询现有的窗口的大小。

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?

推荐答案

不幸的是,窗口大小的查询不被处理的消息 - 他们是直接的API调用,如<一个href=\"http://msdn.microsoft.com/en-us/library/ms633519%28v=vs.85%29.aspx\"><$c$c>GetWindowRect - 因此它们不能用标准的Windows钩截取。你可能想看看进入走弯路API ,它允许你勾任意的Win32函数。 (你可以在这里找到上走弯路教程)

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窗口创建/调整/大小查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆