zoukankan      html  css  js  c++  java
  • 【Demo 0027】获取窗体类信息(2)

    在上一节中我们有测试过使用GetClassInfoEx读取不到窗体类信息,我们这一节将学习通过GetClassLongPtr获取非窗体所在的进程类信息

    (一) 函数声明

          ULONG_PTR GetClassLongPtr(HWND hWnd, int nIndex );

          获取指定窗体(可进程也可进程外)特定类信息项值(数据源:窗体类分配的WNDCLASSEX参数值),可支持32、64位的OS

          DWORD GetClassLong(HWND hWnd, int nIndex);

          功能同GetClassLongPtr, 仅支持32位的OS

          nIndex 值参考:

          GCW_ATOM

    Retrieves an ATOM value that uniquely identifies the window class. This is the same atom that the RegisterClassEx function returns.
    GCL_CBCLSEXTRA
    Retrieves the size, in bytes, of the extra memory associated with the class.
    GCL_CBWNDEXTRA
    Retrieves the size, in bytes, of the extra window memory associated with each window in the class.
    For information on how to access this memory, see GetWindowLongPtr.
    GCLP_HBRBACKGROUND
    Retrieves a handle to the background brush associated with the class.
    GCLP_HCURSOR
    Retrieves a handle to the cursor associated with the class.
    GCLP_HICON
    Retrieves a handle to the icon associated with the class.
    GCLP_HICONSM
    Retrieves a handle to the small icon associated with the class.
    GCLP_HMODULE
    Retrieves a handle to the module that registered the class.
    GCLP_MENUNAME
    Retrieves the pointer to the menu name string. The string identifies the menu resource associated with the class.
    GCL_STYLE
    Retrieves the window-class style bits.
    GCLP_WNDPROC
    Retrieves the address of the window procedure, or a handle representing the address of the window procedure.
    You must use the CallWindowProc function to call the window procedure.
     

          Code:  以下代码演示

          1.  获取NotePad窗体句柄

          2.  获取NotePad 类信息通过(GetClassLongPtr)       

         


    HWND hWndNotePad = FindWindowEx(NULL, NULL, _T("Notepad"), NULL);
    if (NULL != hWndNotePad && IsWindow(hWndNotePad))
    {
        int        nIndexList[]    = { GCW_ATOM, GCL_CBCLSEXTRA, GCL_CBWNDEXTRA, GCLP_HBRBACKGROUND, GCLP_HCURSOR,
                                    GCLP_HICON, GCLP_HICONSM, GCLP_HMODULE, GCLP_MENUNAME, GCL_STYLE, GCLP_WNDPROC };
        int*    nValueList        = new int[sizeof(nIndexList) / sizeof(*nIndexList)];
        const TCHAR* szInfo[]    = { _T("Atom:\t\t    0x%06X\n"),
                                    _T("class Extra:\t    0x%06X\n"),
                                    _T("Wnd Extra:        0x%06X\n"),   
                                    _T("hBackground:        0x%06X\n"),
                                    _T("hCursor:\t        0x%06X\n"),
                                    _T("hIcon:            0x%06X\n"),
                                    _T("hIconSM:        0x%06X\n"),
                                    _T("hModule:        0x%06X\n"),
                                    _T("MenuName:        0x%06X\n"),
                                    _T("Style:            0x%06X\n"),
                                    _T("WndProc:        0x%06X\n")};
        assert((sizeof(nIndexList) / sizeof(*nIndexList)) == (sizeof(szInfo) / sizeof(*szInfo)));
        
        TCHAR szClassInfo[1024] = {0};
        TCHAR szTemp[256];
        for (int ii = 0; ii < sizeof(nIndexList) / sizeof(*nIndexList); ii++)
        {
            nValueList[ii] = GetClassLongPtr(hWndNotePad, nIndexList[ii]);

            TCHAR szTemp[256];
            _stprintf_s(szTemp, szInfo[ii], nValueList[ii]);
            _tcscat(szClassInfo, szTemp);
        }
        SetWindowText(GetDlgItem(hWnd, ID_LABINFO), szClassInfo);
        OutputDebugString(szClassInfo);
        delete[] nValueList;
    }


           我们读取后的值与SPY++ 中类信息对比

          image

          疑问: 1.  MenuName 不一致;

                    2.  根据hCursor句柄值如何得到对应的资源ID == IDC_IBEAM

                    3.  根据hBackground句柄值如何得到对应的资源ID == COLOR_WINDOW

        

    (二) 特别说明

          此函数返回的数据没有WNDCLASSEX项多

          对于以上疑问需努力学习!

    演示代码

  • 相关阅读:
    inner join ,left join ,right join 以及java时间转换
    华为机试-整形数组合并
    华为机试-公共字串计算
    两个字符串的最长公共子序列的长度
    华为机试-字符串通配符
    工作中总结的编程小技巧
    C语言高效编程的几招(绝对实用,绝对经典)
    Java float保留两位小数或多位小数
    新浪云、阿里云、百度云、谷歌云、亚马逊云
    java经典40+分析
  • 原文地址:https://www.cnblogs.com/ztercel/p/2143763.html
Copyright © 2011-2022 走看看