【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_CBCLSEXTRARetrieves the size, in bytes, of the extra memory associated with the class. GCL_CBWNDEXTRARetrieves 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_HBRBACKGROUNDRetrieves a handle to the background brush associated with the class. GCLP_HCURSORRetrieves a handle to the cursor associated with the class. GCLP_HICONRetrieves a handle to the icon associated with the class. GCLP_HICONSMRetrieves a handle to the small icon associated with the class. GCLP_HMODULERetrieves a handle to the module that registered the class. GCLP_MENUNAMERetrieves the pointer to the menu name string. The string identifies the menu resource associated with the class. GCL_STYLERetrieves the window-class style bits. GCLP_WNDPROCRetrieves 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项多

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

 

演示代码

转载于:https://www.cnblogs.com/ztercel/archive/2011/08/17/2143763.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值