The difference between perform () and SendMessage ()

Source: Internet
Author: User
Tags message queue

Just as Windows sends messages to an application, you can also send messages between Windows and controls. C + + Builder provides several ways to send messages within an application: Call Perform () (this way does not depend on the Windows API), and Invoke SendMessage (), PostMessage () API functions

Perform ()

The VCL perform () method applies to all Tcontrol derived objects. Perform () You can send a message to any window or control simply by knowing the instance of the form or control. Perform () needs to pass 3 parameters: Message identifiers, wparam, and lparam.

Perform () declares this:

int __fastcall Perform (unsigned Msg, int WParam, int LParam);

To send a message to a window or control, you can refer to the following code:

RetVal = Controlname->perform (Messagid, Wparam,lparam);

When perform () is invoked, it waits for the message to be processed before it returns. Perform () assembles 3 parameters into a tmessage record, and then calls the dispatch () method to pass the message to the message system of Windows.

SendMessage () and PostMessage ()

Sometimes you might want to send a message to a window without knowing the instance of the window. For example, you might want to send a message to a non-C + + Builder window, but only the handle to the window. Fortunately, Windows has two API functions to do this: SendMessage () and PostMessage (). The two functions are almost the same, and the difference is:

SendMessage () sends a message directly to the window and waits for the message to be processed before returning. Postmessage () simply sends the message to the message queue and returns after it completes.

SendMessage () and PostMessage () are declared as follows:

Lresult SendMessage (HWND hwnd,uint msg,wparam wparam,lparam LPARAM);

BOOL PostMessage (HWND hwnd,uint msg,wparam wparam,lparam LPARAM);

The hWnd is the handle to the window that receives the message

MSG is a message identifier

WParam is a 32-bit specific additional information.

LParam is 32-bit specific additional information

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.