RegisterWindowMessage() on Vista returns different values?

  • Thread starter Thread starter David In NH
  • Start date Start date
D

David In NH

I have an application that runs in the system tray under XP and may be
active for more than one user through the fast-user-switching mode. (The
application is concerned with monitor calibration and is activated out of
the Startup group automagically.)

RegisterWindowMessage("some long string...") is used to allow all of the
tray applications to get notification that they are to close down.

On XP, this function returned the same number for all instances but no
longer does so under Vista. In some cases, the number is the same, with two
instances getting the same value and a third instance getting a different
value.

The on-line MSDN documentation says that the unique number should be the
same. Is this supposed to be different in Vista or am I seeing a bug?

- David
 
David In NH said:
I have an application that runs in the system tray under XP and may be
active for more than one user through the fast-user-switching mode. (The
application is concerned with monitor calibration and is activated out of
the Startup group automagically.)

RegisterWindowMessage("some long string...") is used to allow all of the
tray applications to get notification that they are to close down.

On XP, this function returned the same number for all instances but no
longer does so under Vista. In some cases, the number is the same, with
two instances getting the same value and a third instance getting a
different value.

The on-line MSDN documentation says that the unique number should be the
same. Is this supposed to be different in Vista or am I seeing a bug?

This is probably better answered in a programming newsgroup ... However,
I'll make a stab at it here:

RegisterWindowMessage() allows you to register a unique message as you said,
however, I'm pretty sure its only guaranteed to be unique on the desktop
from whence its called.

Each user logging in gets his/her own desktop. You cannot use the
SendMessage() API to send messages to other windows on another user's
desktop. As always, there are exceptions, but generally this is the case.
If you're running as the LocalSystem user in a service you could
theoretically enumerate the desktops, open each one, and send a message --
but it would be wise to call RegisterWindowMessage() after each desktop
switch.

So for normal applications running in the context of the currently-logged-on
user, you cannot send messages to other windows in other desktops. If you
need to communicate with another instance of your application on another
desktop/user, I recommend using a named pipe, or opening up a named shared
memory map or something.

Robert Simpson
Programmer at Large
 
RegisterWindowMessage() allows you to register a unique message as you
said, however, I'm pretty sure its only guaranteed to be unique on the
desktop from whence its called.

This is not true. The MSDN documentation reads as follows:

The RegisterWindowMessage function defines a new window message that is
guaranteed to be unique throughout the system. The message value can be used
when sending or posting messages.
 
I know what the documentation says ... what I'm telling you is that it may
be out of date ... or, I could be completely wrong. However, it makes sense
to me that there's no reason for RegisterWindowMessage() to be unique across
all desktops, since you can't send messages to windows on other desktops.
 
Robert Simpson said:
I know what the documentation says ... what I'm telling you is that it may
be out of date ... or, I could be completely wrong. However, it makes
sense to me that there's no reason for RegisterWindowMessage() to be unique
across all desktops, since you can't send messages to windows on other
desktops.

Once again, I understand what you are saying. My question to this group was
whether the function had in fact changed or whether I could count on it
working in the same way that it did in XP.

The major issue is that I have a program that takes advantage of the fact
that it was unique across all desktops and wanted it to work that way. I
just want to find out if there is a reason this should no longer be working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top