简体   繁体   English

使用Win32子类化现有窗口

[英]Subclass existing window with Win32

I am currently trying to grab all of the user input to the windows calculator app. 我目前正在尝试获取Windows计算器应用程序的所有用户输入。 It seems the way to do this is to use Win32 to intercept all of the keyboard and mouse inputs that are intended for the calculator window. 看来,执行此操作的方法是使用Win32拦截打算用于计算器窗口的所有键盘和鼠标输入。 I have read the MSDN page on subclassing a window at the link below and have done some research on subclassing. 我已经阅读了下面链接中关于子窗口化的MSDN页面,并对子类做了一些研究。

I have the syntax for subclassing a window, but I am not sure how to tell the program which window I am looking to subclass. 我有子类化窗口的语法,但是我不确定如何告诉程序我要子类化哪个窗口。

the code that I have so far is listed below. 下面列出了我到目前为止的代码。 My problem right now is that I am not sure how the variable "hWndEdit" is assigned. 我现在的问题是我不确定如何分配变量“ hWndEdit”。 I am pretty new to Win32 programming so any help is appreciated. 我是Win32编程的新手,因此可以提供任何帮助。

(link) http://msdn.microsoft.com/en-us/library/windows/desktop/ms633570(v=vs.85).aspx (链接) http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms633570 ( v=vs.85 ) .aspx

WNDPROC wpOrigEditProc; 

wpOrigEditProc = (WNDPROC) SetWindowLong(hWndEdit,GWL_WNDPROC,(long) WndEditProc);

LRESULT CALLBACK WndEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
        {
        case WM_CHAR:
        case WM_KEYUP:
        case WM_KEYDOWN:
            if (hWnd == hWndEdit)
                return 0;
        break;
        case WM_DESTROY: 
            // Remove the subclass from the edit control. 
            SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG) wpOrigEditProc); 
        break;
        default:
            return CallWindowProc((WNDPROC ) wpOrigEditProc, hWnd, message, wParam, lParam);
        }
    return CallWindowProc((WNDPROC ) wpOrigEditProc, hWnd, message, wParam, lParam);
}

To find a window, first use Spy++ (A tool that gets installed with Visual Studio) to find the class name and the window name of the calculator main window. 要查找窗口,请首先使用Spy ++(随Visual Studio一起安装的工具)查找计算器主窗口的类名和窗口名。 Then, in your application, use the FindWindow API: 然后,在您的应用程序中,使用FindWindow API:

hWndEdit = FindWindow(className, windowName);

Although, I'm not sure that subclassing is the right method here since the Calculator window is not owned by your application. 虽然,我不确定在这里子类化是正确的方法,因为“计算器”窗口不属于您的应用程序。 You should do this with hooks . 您应该使用钩子执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM