Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define own WM message for Message Pump in C++

How do I define my own WM (like WM_CLOSE, etc) message that can be handled by the message pump in C++?

If that is even possible.

like image 591
Tony The Lion Avatar asked May 20 '10 14:05

Tony The Lion


People also ask

What is pump message?

The "message pump" is a core part of any Windows program that is responsible for dispatching windowing messages to the various parts of the application. This is the core of Win32 UI programming.

What is a message loop C#?

The message loop is an obligatory section of code in every program that uses a graphical user interface under Microsoft Windows. Windows programs that have a GUI are event-driven. Windows maintains an individual message queue for each thread that has created a window. Usually only the first thread creates windows.

What is a windows message?

The operating system communicates with your application window by passing messages to it. A message is simply a numeric code that designates a particular event. For example, if the user presses the left mouse button, the window receives a message that has the following message code.

Which of the following function is invoked by Windows in order to process messages in an application?

After removing a message from its queue, an application can use the DispatchMessage function to direct the system to send the message to a window procedure for processing.


1 Answers

It depends on what you are using the message for. This link shows a breakdown of the "address space" for Win32 messages.

WM_USER is not the correct solution in the general case. WM_USER messages "can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range."

You are better off assigning a message ID that is in the WM_APP range.

RegisterWindowMessage is useful if you want to have the system assign you a message ID at runtime. "All applications that register the same string can use the associated message number for exchanging messages," so you can use RegisterWindowMessage when you need to use a custom message for simple inter-process communication.

like image 129
Aaron Klotz Avatar answered Sep 21 '22 01:09

Aaron Klotz