标签:
比如这个结构就带句柄(放到了第二个参数):
TWMContextMenu = packed record Msg: Cardinal; hWnd: HWND; case Integer of 0: ( XPos: Smallint; YPos: Smallint); 1: ( Pos: TSmallPoint; Result: Longint); end;
这个也带,因为确实需要:
TWMDropFiles = packed record Msg: Cardinal; Drop: THANDLE; Unused: Longint; Result: Longint; end;
这里甚至带了2个句柄:
TWMSizeClipboard = packed record Msg: Cardinal; Viewer: HWND; RC: THandle; Result: Longint; end;
而大多数消息都是不带句柄的:
TWMSize = packed record Msg: Cardinal; SizeType: Longint; { SIZE_MAXIMIZED, SIZE_MINIMIZED, SIZE_RESTORED, SIZE_MAXHIDE, SIZE_MAXSHOW } Width: Word; Height: Word; Result: Longint; end; TWMTimer = packed record Msg: Cardinal; TimerID: Longint; TimerProc: TFarProc; Result: Longint; end;
但是看了一遍Messages.pas定义的消息结构,几乎全都是16字节大小,没有找到例外,这是为什么呢?
甚至即使明明不使用那么多空间,还要加一个Unused:
TWMSystemError = packed record Msg: Cardinal; ErrSpec: Word; Unused: Longint; Result: Longint; end;
终于懂了:Delphi重定义消息结构随心所欲,只需要前4个字节是消息编号就行了,跟Windows消息虽然尽量保持一致,但其实相互没有特别大的关系。有了这个,就有了主动,带不带句柄完全看需要。
标签:
原文地址:http://www.cnblogs.com/findumars/p/5183647.html