为什么要注册windows类 [英] Why to register windows class

查看:79
本文介绍了为什么要注册windows类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





RegisterClass()或RegisterClassEx()是注册Window Class的功能,但是为什么要注册一个窗口。我只是想知道这里有两件事,''注册''和''类'',它的意义是什么。



给出答案,但我仍然感到困惑,因为它建议只是接受它。 [ ^ ]



提前谢谢

Hi,

RegisterClass() or RegisterClassEx() are function to register Window Class, but why to register a window. I just wanted to know two things here, ''Register'' and ''class'' and what is its significance.

Answer is given but I am still confused, because it suggests just to accept it as it is.[^]

Thanks in advance

推荐答案

当你注册一个窗口类时,你将它的_properties和behaviour_与它关联起来班级名称。即它的字体,颜色,背景和对WM_消息的响应。



然后,这允许您只需通过引用它来创建特定类型的窗口名称。除了1/2个预定义的Windows类(可能用数字引用),这就是ms窗口的工作方式。



通过注册一个类,您可以重复使用特定控件(或窗口,以继续使用此处使用的术语)的行为和外观,以用于同一程序中的许多不同内容。



您可能有一个位图按钮类,它将图像从彩色变为黑白,分为50步。如果你想再次使用这种类型的按钮,你可以(a)重写(复制/粘贴)它的代码并更改它引用的图像,最后将新窗口的窗口过程设置为一个在注册新窗口类之前,它会淡化图像或(b)创建一个窗口过程,通过发送给它的消息接受新图像。



Windows然后每次创建它的实例时,都会负责创建用于控制此类窗口的代码副本。这意味着您可以拥有100个位图按钮实例,每个实例具有不同的图像 - 但您只需要在注册窗口时与窗口关联的窗口过程中维护单个实例的存储。
When you register a window class, you associate it''s _properties and behaviour_ with its class name. I.e it''s font, colour, background and response to WM_ messages.

This then allows you to create a window of a particular type simply by referring to it by name. With the exception of 1/2 a dozen pre-defined windows classes (which may be reffered to with a number), this is the way that ms windows works.

By registering a class, you can re-use the behaviour and appearance of a particular control (or window, to continue with the terminology used here) for many different things within the same program.

You may have a bitmap-button class, that fades the image from colour to black and white in 50 steps. If you then want to use this type of button again, you either (a) re-write (copy/paste) it''s code and change the images it references, finally setting the window proc of a new window to be the one that fades the image or (b) create a window procedure that will accept new images via a message sent to it, before registering the new window class.

Ms Windows then takes care of creating copies of the code used to control this type of window each time you create an instance of it. This means you can have 100 instances of the bitmap-button, each with different images - yet you only need to maintain storage for a single one inside the window-procedure that is associated with the window when you register it.


因为你正在创建一个自定义窗口,因此你需要注册一个类。



如果使用默认窗口你不需要注册一个类如Dialog等
because you are creating a custom window and hence you need to register a class.

you do not need to register a class if using default windows such as Dialog, etc


这篇关于为什么要注册windows类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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