理解RegisterClass

最近在学习windows环境下的编程,遇到了RegisterClass这个函数,不明白是干嘛用的

stackoverflow上找到个说法:

RegisterClass is basically you defining a class and including it in your program (much like a #include in C++).

CreateWindow is conceptually the same as you doing a new in C++. You're asking Windows to create a new window, and you've got to tell it the type of window. Windows includes a set of predefined windows, such as Button or Edit, but if you want to create an instance of your own window then that's fine, you just need to tell it the "class" you'd like to create. You've already registered this class by calling RegisterClass, so Windows can now go straight to the definition and create an instance of your window.

大意应该是:

RegisterClass定义了一个类并且包含在你的程序中(就像c++里的#include)。

createwindow概念上和c++里的new差不多。当你要求系统创建一个新窗口时,你要告诉系统新窗口的类型。Windows系统包含一系列的预定义的窗口,例如按钮(button)、编辑框(edit)等。但如果你要创建一个属于你自己的个性窗口,你就要告诉系统这个窗口的“类”。而这个类你已经通过RegisterClass注册过了,所以系统会直接创建你定制的这个窗口类的实例。


《MFC windows程序设计》里也有一段话:

WinMain首先调用API函数RegisterClass来注册一个窗口类。窗口类定义了窗口的重要特性,如窗口过程地址、默认背景色以及图标等。这些属性通过填写一个WNDCLASS结构的字段来定义,随后传递个RegisterClass。当应用程序生成一个窗口类时,它必须指定一个窗口类,在该类能被使用之前,必须先对其进行注册。这就是为什么RegisterClass在程序的开始即被调用的原因。


总结下来,应该是WNDCLASS结构体定义了一些窗口的特性(窗口过程地址或者叫消息处理函数,背景颜色,图标,光标等等)后,调用RegisterClass()来向系统申报,构造满足这些条件的个性化窗口类,可以被代码调用,而后才能用CreateWindow()实例化该个性化窗口。(小白刚刚起步,理解偏差的地方望指正)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值