我真不想放弃! 等我真正搞明白了,我再发分,一定很多很多。 (50分)

《windows 核心编程》微软出的,白色。<br>读一下吧,我个人认为是windows开发的必读书籍。
 
好像刚回答过类似问题,我的理解:<br>case integer of 表示告诉编译器,后面是一个变体记录,所占长度为sizeof(integer),<br>至于怎样变体,分几种情况,分别表示为0,1,2,3,这里的数字没有特别含义,就是表示<br>变体的分类,但是每种情况,必须保证所占字节合计等于sizeof(integer)
 
不对,好像我的理解也是错的
 
咳,这个问题应该很容易的。不过还是说一下,省得你化这许多力气在这里。<br>&nbsp;TMessage = packed record<br>&nbsp; &nbsp; Msg: Cardinal; &nbsp; &nbsp; &nbsp; &nbsp; // 消息ID<br>&nbsp; &nbsp; case Integer of &nbsp; &nbsp; &nbsp; &nbsp;// 此处的Integer针对什么来说的?<br>&nbsp; &nbsp; &nbsp; 0: ( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 什么时候用到?<br>&nbsp; &nbsp; &nbsp; &nbsp; WParam: Longint; &nbsp;// wparam 在MFC中是什么意思?<br>&nbsp; &nbsp; &nbsp; &nbsp; LParam: Longint; &nbsp;// lparam 在MFC中是什么意思?<br>&nbsp; &nbsp; &nbsp; &nbsp; Result: Longint);<br>&nbsp; &nbsp; &nbsp; 1: ( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 什么时候用到?<br>&nbsp; &nbsp; &nbsp; &nbsp; WParamLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; WParamHi: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParamLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; LParamHi: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; ResultLo: Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; ResultHi: Word);<br>&nbsp; end;<br>就是告诉编译器,TMessage这个数据类型是这样的:<br>00~03:Msg: Cardinal;<br>04~05:WParamLo: Word;--1<br>06~07:WParamHi: Word;--2; 1,2和起来是: WParam: Longint<br>08~09:LParamLo: Word;--3<br>0A~0B:LParamHi: Word;--4; 3,4和起来是: LParam: Longint<br>0C~0D:ResultLo: Word;--5<br>0E~0F:ResultHi: Word;--6; 5,6和起来是:Result: Longint<br>你即可以用WParamLo,WParamHi,LParamLo,LParamHi,ResultLo,ResultHi来访问04~0F的数据<br>也可以用WParam,LParam,Result来访问04~0F的数据。<br>你想怎么访问都可以。就是使你用起来更方便。<br><br>比如有一个记录:<br>type <br>&nbsp;MyRecord=Record<br>&nbsp; a:Integer;<br>&nbsp; Data:Integer<br>&nbsp;end; <br>比如,我想访问Data的高16位和低16位,就可以这样定义:<br>type <br>&nbsp;MyRecord2=Record<br>&nbsp; a:Integer;<br>&nbsp; case integer of<br>&nbsp; &nbsp;0:(Data:Integer);<br>&nbsp; &nbsp;1:(DataHi,DataLow:Word) ;<br>&nbsp;end; <br>其实,MyRecord2和MyRecord的内存使用是完全一样的,但你可以通过<br>DataHi,DataLow来访问Data的高16位和低16位。<br>具体的实现细节,我希望你自己去找吧!<br>
 
综合上面的,不难给出:<br>TMessage2 = packed record<br>&nbsp; &nbsp; Msg: Cardinal; &nbsp; &nbsp;<br>&nbsp; &nbsp; WParam: Longint; &nbsp;<br>&nbsp; &nbsp; LParam: Longint; &nbsp;<br>&nbsp; &nbsp; Result: Longint;<br>end;<br>和TMessage在具体的物理内存上是一样的。<br>有的时候可能不一样,比如:<br>type<br>&nbsp;TestRec=Record<br>&nbsp; a:Byte;<br>&nbsp; case integer of<br>&nbsp; &nbsp;0:(b:Integer);<br>&nbsp; &nbsp;1:(c,d,e:Word);//多出一个e,内存就会强制加大<br>&nbsp;end;<br>&nbsp;TestRec2=Record<br>&nbsp; a:Byte;<br>&nbsp; b:Integer;<br>&nbsp;end;<br>TestRec和TestRec2就不相等。
 
至于什么时候Integer为0,1的问题,<br>因为Integer不是变量,而是类型,<br>这不过是Delphi编译器这样来定义这种数据结构而已。<br>
 
不要抱着message不放,看一下有关windows消息的书籍,使用sendmessage()来实践。<br>另外,不要听那些人说,rad不好,要学VC。那些人自己对delphi知之甚少,就说delphi<br>不好。听说windows还是basic编写的。
 
多谢!<br>我懂了。但是怎么多发分呢?
 
[:(!][:)][:D][8D][:(][?][red][/red][h1][/h1]
代码:
[:D]
 
顶部