?
Solved

Using RegisterWindowMessage Defined Variable within Switch Statement

Posted on 2004-08-30
3
Medium Priority
?
539 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 200 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 800 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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 how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 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