[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppRegisterWindowMessage

(C++ Win32 API) RegisterWindowMessage

The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. When the message name is already registered, the message number of that existing name will be used.

The returned message value can be used when calling the SendMessage or PostMessage function.

Example

A class storing message values I use in a game called 'Amino Acid Fighter':

typedef unsigned int UINT;
struct AafMessages
{
  public:
  AafMessages() :
    titleStart(   RegisterWindowMessage("titleStart"   )),
    titleEnd(     RegisterWindowMessage("titleEnd"     )),
    mainMenuStart(RegisterWindowMessage("mainMenuStart")),
    mainMenuEnd(  RegisterWindowMessage("mainMenuEnd"  )),
    gameStart(    RegisterWindowMessage("gameStart"    )),
    gameEnd(      RegisterWindowMessage("gameEnd"      ))
  {
    //Nothing left to initialize...
  }
  const UINT titleStart;
  const UINT titleEnd;
  const UINT mainMenuStart;
  const UINT mainMenuEnd;
  const UINT gameStart;
  const UINT gameEnd;
};


Note #1: Although there may be multiple instances of AafMessages, the same message values will be registered! Due to this, I could make all member variables public and const without problem.

Note #2: I obtained the example with the TEXT macro around the message keys. If the example above does not work, perhaps you will have to use it, e.g.:

  titleStart(RegisterWindowMessage(TEXT([/b]"titleStart"))),


Code links



last edited (May 20, 2007) by bilderbikkel, Number of views: 1607, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.