Solved

Using RegisterWindowMessage Defined Variable within Switch Statement

Posted on 2004-08-30
3
527 Views
Last Modified: 2013-12-03
I have been trying to use a RegisterWindowMessage defined variable within a switch statement expression, but my compiler keeps producing an error (i.e., case expression not  constant).  Can anyone tell me what I am doing wrong?  Here are my declarations for everything:

const UINT WM_WGMSG = RegisterWindowMessage (TEXT ("WG_Message"));

Within WndProc procedure:

switch (message) {
                        
  case WM_WGMSG:
  return 1;

}

Finally, I am programming in C under Microsoft Visual Studio .net 2003.  
0
Comment
Question by:jtrades
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Assisted Solution

by:cookre
cookre earned 50 total points
ID: 11938438
Switch requires a compile time constants for its cases.  The value of your WM_WGMSG is not known until runtime.

Do you really need a system wide unique message code?

If it's just for use within your progrm(s), make up your own message code - some value above WM_USER (0x0400), say WM_USER+123.

If you must have system wide uniqueness, just add an explicit check for your message in the switch's 'default'.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 11938866
Agree with coorke about constant unknown at compile time.
However, RegisterWindowMessage is much better than constant messages. Just replace swithch with if - else if - ... else. If you want to use constant messages, use WM_APP and not WM_USER to prevent conflicts (Microsoft is already using some messages with values WM_USER + n).
0
 
LVL 22

Expert Comment

by:cookre
ID: 11938893
The nerve of them!  I've always taken that as sacrosanct.

Guess that's what I get for being lazxy.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question