有没有办法知道窗口过程是否被子类化? [英] Is there any way to know if a window procedure was subclassed?

查看:38
本文介绍了有没有办法知道窗口过程是否被子类化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查窗口窗体的 winproc 是否被子类化.任何 winapi 或 spy++ 技巧可以做到这一点?

I want to check if winproc of a window form was subclassed. Any winapi or spy++ trick to do this?

推荐答案

你可以使用下一个代码来确定被另一个模块子类化的窗口(不同于注册窗口类的模块)

you can use next code for determinate is window subclassed by another module (different from module which register window class )

BOOL IsSubclassed(HWND hwnd)
{
    LPARAM pfn = (IsWindowUnicode(hwnd) ? GetWindowLongPtrW : GetWindowLongPtrA)
        (hwnd, GWLP_WNDPROC);

    HMODULE hmod;
    //if (RtlPcToFileHeader(pfn, &hmod))
    if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|
            GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (PCWSTR)pfn, &hmod))
    {
        DbgPrint("pfn=%p hmod=%p\n", pfn, hmod);

        return hmod != (HMODULE)GetClassLongPtrW(hwnd, GCLP_HMODULE);
    }

    // pfn not in any module - guess subclassed
    return TRUE;
}

<小时>

注意:GetWindowLongPtrA(hwnd, GWLP_WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC) - 总是返回不同的结果 - 窗口过程的一个地址和另一个 - 句柄代表窗口过程的地址:仅对有意义的特殊内部值 CallWindowProc - 确定哪个版本 AW 检索窗口过程的地址 - 需要调用 IsWindowUnicode.这是无证的,但合理的.如果子类过程具有与原始过程相同的 ANSI 或 UNICODE 本机,则它可以直接调用原始过程.如果本机不同 - 需要对窗口消息进行翻译(Unicode <-> ANSI).windows 假定调用者或 GetWindowLongPtrA 是本机 ANSI 窗口,而 GetWindowLongPtrW 的调用者是本机 UNICODE 窗口.如果相同的本机(AAWW),则返回指向窗口过程的指针,否则返回手柄


note: GetWindowLongPtrA(hwnd, GWLP_WNDPROC) and GetWindowLongPtrW(hwnd, GWLP_WNDPROC) - always return different result - one address of the window procedure and another - handle representing the address of the window procedure : special internal value meaningful only to CallWindowProc - for determine which version A or W retrieves the address of the window procedure - need call IsWindowUnicode. this is undocumented, but reasonable. if subclassed procedure have the same ANSI or UNICODE native that original procedure it can direct call original. if native is different - need translation (Unicode <-> ANSI) for window messages. windows assume that caller or GetWindowLongPtrA is native ANSI window and caller of GetWindowLongPtrW is native UNICODE window. and return pointer to the window procedure if the same native (A and A or W and W) otherwise returned handle

从另一边 GetClassLongPtrW(hwnd, GCLP_HMODULE)GetClassLongPtrA(hwnd, GCLP_HMODULE) - 总是返回相同的结果

from another side GetClassLongPtrW(hwnd, GCLP_HMODULE) and GetClassLongPtrA(hwnd, GCLP_HMODULE) - always return the same result

这篇关于有没有办法知道窗口过程是否被子类化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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