GetClassInfo函数解析

本文介绍了如何使用GetClassInfo函数检查窗体类是否已注册,并提供了注册wndClass结构体的具体实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我们知道一个窗体建立的过程.首先注册一个wndClass的结构体.然后才是用createWindow函数来建立窗体.
现在有个问题了,我们想知道我们建立的wndClass结构体是否已经注册了,怎么办?

GetClassInfo就是用来解决这个问题的.

先看msdn中的东西.

The GetClassInfo function retrieves information about a window class. 
这个函数返回一些信息关于某个windowClass

Note   The GetClassInfo function has been superseded by the GetClassInfoEx function. You can still useGetClassInfo, however, if you do not need information about the class small icon. 
需要注意的是这个函数已经被GetClassInfoEx 取代了,如果你不需要小图标的信息 当然还是可以继续用这个函数的.
BOOL GetClassInfo(      

    HINSTANCE hInstance,     LPCTSTR lpClassName,     LPWNDCLASS lpWndClass );
 
hInstance
[in] Handle to the instance of the application that created the class. To retrieve information about classes defined by the system (such as buttons or list boxes), set this parameter to NULL.
用第二个参数建立的实例.如果是系统自定义的windowClass那么这个参数为null,delphi中就是0; 
lpClassName
[in] 

Pointer to a null-terminated string containing the class name. The name must be that of a preregistered class or a class registered by a previous call to the RegisterClass or RegisterClassExfunction.

Alternatively, this parameter can be an atom. If so, it must be a class atom created by a previous call to RegisterClass or RegisterClassEx. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
windowClass结构体.

lpWndClass
[out] Pointer to a WNDCLASS structure that receives the information about the class.
返回的结构体的信息会储存在这里.delphi中这个就是一个var 参数.

返回值 boolean;

例子会在综合后面几个API后一起给出来.

BOOL CMyTest::RegisterWindowClass(HINSTANCE hInstance)   
{   
      LPCSTR className = "CMyWin1";//"CMyWin"控件?的名字   
       WNDCLASS windowclass;         
    
       if(hInstance)   
              hInstance = AfxGetInstanceHandle();   
          
       if (!(::GetClassInfo(hInstance, className, &windowclass)))   
       {                
              windowclass.style = CS_DBLCLKS;   
              windowclass.lpfnWndProc = ::DefWindowProc;   
              windowclass.cbClsExtra = windowclass.cbWndExtra = 0;   
              windowclass.hInstance = hInstance;   
              windowclass.hIcon = NULL;   
              windowclass.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);   
              windowclass.hbrBackground= (HBRUSH)(COLOR_BTNFACE+1);
              windowclass.lpszMenuName = NULL;   
              windowclass.lpszClassName = className;   
    
              if (!AfxRegisterClass(&windowclass))   
              {   
                     AfxThrowResourceException();   
                     return FALSE;   
              }   
       }   
    
       return TRUE;   
} 

注册窗口:

CMyTest::CMyTest()
{
	RegisterWindowClass();   
}

  

转载于:https://www.cnblogs.com/cwbo-win/articles/3519466.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值