Finally understand: Delphi message result is completely sporogenous out, not the Windows message comes with (Delphi on the Windows programming system, the larger the transformation, the greater the learning harvest)

Source: Internet
Author: User

In Windows, messages use a uniform structure body (MSG) to hold information, where message indicates the specific type of messages,

And Wparam,lparam is the most flexible of the two variables, for different message types, the meaning of storing data is not the same.

Time indicates when the message was generated, and PT indicates the position of the mouse at the time the message was generated.

There is no option for result. Then I measured the size of the MSG structure with VC2008:

#include <afx.h>void  Cxe111dlg::onbnclickedbutton1 () {    CString m_str;     int sizeof (MSG);    M_str.format (_t ("%d"), DDD);    AfxMessageBox (M_STR);}

Result equals 28

void Cxe111dlg::onbnclickedbutton1 () {    CString m_str;     int sizeof (wm_size);    M_str.format (_t ("%d"), DDD);    AfxMessageBox (M_STR);}

Result equals 4

void Cxe111dlg::onbnclickedbutton1 () {    CString m_str;     int sizeof (WM_CHAR);    M_str.format (_t ("%d"), DDD);    AfxMessageBox (M_STR);}

Result equals 4

-------------------------------------------------------------

Then look at the definition of Delphi, it also has the original model is defined, but generally not used:

  PMSG = ^tmsg;   packed Record     Hwnd:hwnd;     message : UINT;    Wparam:wparam;    Lparam:lparam;    Time:dword;    Pt:tpoint;   End ;   = tagmsg;   = Tagmsg;

After testing, its size is of course 28:

procedure Tform1.button3click (sender:tobject); begin   showmessage (inttostr (sizeof (TAGMSG))); End;

Then look at the message structure that Delphi really uses, and note that it includes the result:

  PMessage = ^tmessage;   packed Record     msg:cardinal;      Case  of      0 : (        wparam:longint;        Lparam:longint;        Result:longint);       1 : (        Wparamlo:word;        Wparamhi:word;        Lparamlo:word;        Lparamhi:word;        Resultlo:word;        Resulthi:word);   End;

To test its size:

procedure Tform1.button3click (sender:tobject); begin   showmessage (inttostr (sizeof (tmessage))); End;

Result equals 16

-------------------------------------------------------------

Re-test the size of the message itself:

procedure Tform1.button3click (sender:tobject); begin   showmessage (inttostr (sizeof (WM_CHAR))); End;

Result equals 2

procedure Tform1.button3click (sender:tobject); begin   showmessage (inttostr (sizeof (wm_size))); End;

Result equals 1

-------------------------------------------------------------

Then look at the message structure of Delphi definition:

Twmsize =packed Recordmsg:cardinal; Sizetype:longint; {size_maximized, size_minimized, size_restored, Size_maxhide, Size_maxshow}Width:word;    Height:word;  Result:longint; End; Twmkey=packed Recordmsg:cardinal;    Charcode:word;    Unused:word;    Keydata:longint;  Result:longint; End; Twmchar=Twmkey; Twmpaint=packed Recordmsg:cardinal;    DC:HDC;    Unused:longint;  Result:longint; End; Twmcommand=packed Recordmsg:cardinal;    Itemid:word;    Notifycode:word;    Ctl:hwnd;  Result:longint; End; Twmnotify=packed Recordmsg:cardinal;    Idctrl:longint;    NMHDR:PNMHDR;  Result:longint; End;

To test the size of the Delphi message structure:

procedure Tform1.button3click (sender:tobject); begin   showmessage (inttostr (sizeof (twmsize)));  ShowMessage (IntToStr (sizeof (Twmchar)));  ShowMessage (IntToStr (sizeof (twmpaint)));  ShowMessage (IntToStr (sizeof (Twmcommand)));  ShowMessage (IntToStr (sizeof (twmnotify))); End;

How to measure all is 16 bytes size ...

Finally understand: Delphi message result is completely sporogenous out, not the Windows message comes with (Delphi on the Windows programming system, the larger the transformation, the greater the learning harvest)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.