Solved

Using RegisterWindowMessage Defined Variable within Switch Statement

Posted on 2004-08-30
3
519 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now