Solved

Using RegisterWindowMessage Defined Variable within Switch Statement

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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 shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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