Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using RegisterWindowMessage Defined Variable within Switch Statement

Posted on 2004-08-30
3
Medium Priority
?
546 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

597 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