TONT 41713 WPARAM和LPARAM中的W和L是什么意思?

历史的点滴。

原文链接:https://blogs.msdn.microsoft.com/oldnewthing/20031125-00/?p=41713

Once upon a time, Windows was 16-bit. Each message could carry with it two pieces of data, called WPARAM and LPARAM. The first one was a 16-bit value (“word”), so it was called W. The second one was a 32-bit value (“long”), so it was called L.

从前的时候,Windows是16位的,每条系统消息可以承载两则数据,分别被称为WPARAM和LPARAM。前者是一个16位的值(即所谓的『字』),所以是W开头的(Word)。后者是一个32位的值(长整形),所以是L开头的(Long)。

You used the W parameter to pass things like handles and integers. You used the L parameter to pass pointers.

开发人员可以用W参数传递句柄和整型类数据,用L参数传递指针。

When Windows was converted to 32-bit, the WPARAM parameter grew to a 32-bit value as well. So even though the “W” stands for “word”, it isn’t a word any more. (And in 64-bit Windows, both parameters are 64-bit values!)

后来Windows进入了32位时代,WPARAM参数也进化为了一个32位的值,所以尽管W代表『字』(Word),WPARAM也不再是一个『字』了。(何况在64位Windows中,两个参数还都进化成64位了呢!)

It is helpful to understand the origin of the terms. If you look at the design of window messages, you will see that if the message takes a pointer, the pointer is usually passed in the LPARAM, whereas if the message takes a handle or an integer, then it is passed in the WPARAM. (And if a message takes both, the integer goes in the WPARAM and the pointer goes in the LPARAM.)

了解这些术语的起源很有帮助。观察一下窗体消息的的设计,你就会发现如果消息接受指针的话,指针通常在LPARAM中进行传递,而对于接受句柄或整型的消息,那么数据通常会传入WPARAM。(如果是同时接受两个参数的,那么整型传入WPARAM,指针传入LPARAM。)

Once you learn this, it makes remembering the parameters for window messages a little easier. Conversely, if a message breaks this rule, then it sort of makes your brain say, “No, that’s not right.”

对此有所了解后,对于记住窗体消息的参数(应该传入哪类数据)就简单一点了。反之,如果某条消息传入的参数不符合以上规则,那么你潜意识里可能就会觉得:『噢,好像有点不对劲。』

注:所有评论将在审核通过后显示,请不要在评论内容的任何位置出现链接,否则您的评论将被自动移入回收站,且永远不会被复审。

All comments will be available after being manually reviewed, please do not include any links anywhere in your comment, otherwise your comment will be automatically deleted and are not eligible for review.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注