{"id":2320,"date":"2018-09-07T09:51:25","date_gmt":"2018-09-07T01:51:25","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=2320"},"modified":"2018-09-07T09:51:25","modified_gmt":"2018-09-07T01:51:25","slug":"tont-41713-wparam%e5%92%8clparam%e4%b8%ad%e7%9a%84w%e5%92%8cl%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/2320","title":{"rendered":"TONT 41713 WPARAM\u548cLPARAM\u4e2d\u7684W\u548cL\u662f\u4ec0\u4e48\u610f\u601d\uff1f"},"content":{"rendered":"<p>\u5386\u53f2\u7684\u70b9\u6ef4\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20031125-00\/?p=41713\" target=\"_blank\" rel=\"noopener\">https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20031125-00\/?p=41713<\/a><\/p>\n<p>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 (&#8220;word&#8221;), so it was called W. The second one was a 32-bit value (&#8220;long&#8221;), so it was called L.<\/p>\n<p>\u4ece\u524d\u7684\u65f6\u5019\uff0cWindows\u662f16\u4f4d\u7684\uff0c\u6bcf\u6761\u7cfb\u7edf\u6d88\u606f\u53ef\u4ee5\u627f\u8f7d\u4e24\u5219\u6570\u636e\uff0c\u5206\u522b\u88ab\u79f0\u4e3aWPARAM\u548cLPARAM\u3002\u524d\u8005\u662f\u4e00\u4e2a16\u4f4d\u7684\u503c\uff08\u5373\u6240\u8c13\u7684\u300e\u5b57\u300f\uff09\uff0c\u6240\u4ee5\u662fW\u5f00\u5934\u7684\uff08Word\uff09\u3002\u540e\u8005\u662f\u4e00\u4e2a32\u4f4d\u7684\u503c\uff08\u957f\u6574\u5f62\uff09\uff0c\u6240\u4ee5\u662fL\u5f00\u5934\u7684\uff08Long\uff09\u3002<\/p>\n<p>You used the W parameter to pass things like handles and integers. You used the L parameter to pass pointers.<\/p>\n<p>\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u7528W\u53c2\u6570\u4f20\u9012\u53e5\u67c4\u548c\u6574\u578b\u7c7b\u6570\u636e\uff0c\u7528L\u53c2\u6570\u4f20\u9012\u6307\u9488\u3002<\/p>\n<p>When Windows was converted to 32-bit, the WPARAM parameter grew to a 32-bit value as well. So even though the &#8220;W&#8221; stands for &#8220;word&#8221;, it isn&#8217;t a word any more. (And in 64-bit Windows, both parameters are 64-bit values!)<\/p>\n<p>\u540e\u6765Windows\u8fdb\u5165\u4e8632\u4f4d\u65f6\u4ee3\uff0cWPARAM\u53c2\u6570\u4e5f\u8fdb\u5316\u4e3a\u4e86\u4e00\u4e2a32\u4f4d\u7684\u503c\uff0c\u6240\u4ee5\u5c3d\u7ba1W\u4ee3\u8868\u300e\u5b57\u300f\uff08Word\uff09\uff0cWPARAM\u4e5f\u4e0d\u518d\u662f\u4e00\u4e2a\u300e\u5b57\u300f\u4e86\u3002\uff08\u4f55\u51b5\u572864\u4f4dWindows\u4e2d\uff0c\u4e24\u4e2a\u53c2\u6570\u8fd8\u90fd\u8fdb\u5316\u621064\u4f4d\u4e86\u5462\uff01\uff09<\/p>\n<p>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.)<\/p>\n<p>\u4e86\u89e3\u8fd9\u4e9b\u672f\u8bed\u7684\u8d77\u6e90\u5f88\u6709\u5e2e\u52a9\u3002\u89c2\u5bdf\u4e00\u4e0b\u7a97\u4f53\u6d88\u606f\u7684\u7684\u8bbe\u8ba1\uff0c\u4f60\u5c31\u4f1a\u53d1\u73b0\u5982\u679c\u6d88\u606f\u63a5\u53d7\u6307\u9488\u7684\u8bdd\uff0c\u6307\u9488\u901a\u5e38\u5728LPARAM\u4e2d\u8fdb\u884c\u4f20\u9012\uff0c\u800c\u5bf9\u4e8e\u63a5\u53d7\u53e5\u67c4\u6216\u6574\u578b\u7684\u6d88\u606f\uff0c\u90a3\u4e48\u6570\u636e\u901a\u5e38\u4f1a\u4f20\u5165WPARAM\u3002\uff08\u5982\u679c\u662f\u540c\u65f6\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\u7684\uff0c\u90a3\u4e48\u6574\u578b\u4f20\u5165WPARAM\uff0c\u6307\u9488\u4f20\u5165LPARAM\u3002\uff09<\/p>\n<p>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, &#8220;No, that&#8217;s not right.&#8221;<\/p>\n<p>\u5bf9\u6b64\u6709\u6240\u4e86\u89e3\u540e\uff0c\u5bf9\u4e8e\u8bb0\u4f4f\u7a97\u4f53\u6d88\u606f\u7684\u53c2\u6570\uff08\u5e94\u8be5\u4f20\u5165\u54ea\u7c7b\u6570\u636e\uff09\u5c31\u7b80\u5355\u4e00\u70b9\u4e86\u3002\u53cd\u4e4b\uff0c\u5982\u679c\u67d0\u6761\u6d88\u606f\u4f20\u5165\u7684\u53c2\u6570\u4e0d\u7b26\u5408\u4ee5\u4e0a\u89c4\u5219\uff0c\u90a3\u4e48\u4f60\u6f5c\u610f\u8bc6\u91cc\u53ef\u80fd\u5c31\u4f1a\u89c9\u5f97\uff1a\u300e\u5662\uff0c\u597d\u50cf\u6709\u70b9\u4e0d\u5bf9\u52b2\u3002\u300f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5386\u53f2\u7684\u70b9\u6ef4\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2320","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=2320"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2320\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=2320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=2320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=2320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}