Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Differences between WM_USER and WM_APP

200 views
Skip to first unread message

Olivier Pons

unread,
Dec 30, 2007, 11:33:04 AM12/30/07
to
After reading the thread named "Sync thread with main thread"
I'm wondering what is the main problem with WM_USER and WM_APP.
I don't see why, if we just make sure that (WM_USER + XX) is not used in another pascal unit we use, we should avoid it.
And why we should prefer WM_APP to WM_USER.

Thanks for you answers.

--
Olivier Pons
http://olivier.pons.free.fr/

OBones

unread,
Dec 31, 2007, 2:33:59 AM12/31/07
to
Olivier Pons wrote:
> After reading the thread named "Sync thread with main thread"
> I'm wondering what is the main problem with WM_USER and WM_APP.
> I don't see why, if we just make sure that (WM_USER + XX) is not used in
> another pascal unit we use, we should avoid it.
> And why we should prefer WM_APP to WM_USER.

This is all explained on the MSDN. Here is an excerpt:

"Message numbers in the second range (WM_USER through 0x7FFF) 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."

http://msdn2.microsoft.com/en-us/library/ms644931.aspx

Basically, if you stick to the same window and do not let the message
propagate to child windows, you should be fine. So as it is, you should
use WM_APP as a base.

Hope this helps.

Krisztian Pinter

unread,
Jan 2, 2008, 4:46:02 AM1/2/08
to
On Sun, 30 Dec 2007 17:33:04 +0100, Olivier Pons
<olivier.dot.pons...@ignore.this.fr> wrote:

> And why we should prefer WM_APP to WM_USER.

WM_APP belongs to the application.

WM_USER belongs to the window class.

if you are writing a new control for example, you can simply
use WM_USER + 0, 1, ... message numbers as command interface or
internally. WM_USER + 2 can mean different things for different
types of windows. but beware, as if you inherit from another
control (which is likely in delphi), you need to know if the
ancestor used a message number already.

WM_APP belongs to the program as a whole. theoretically, you
can start from WM_APP+0,1 ..., but again, we work in a
predefined environment, so some of them might be taken already.

alas, the documentation is completely lacking to mention any of
the above. if you want to find out if a TEdit uses a certain
message number, you need to go deep into the VCL.

if you send the messages to a dedicated message receiver
window (created with AllocateHWnd) you can save yourself
all this trouble.

0 new messages