You can't use switch on a value which is not known at compile time.
instead, do a compare in default:
default:
if (message == WM_MYMESSAGE)
{
/* Do some stuff */
}
else
{
return DefWindowProc (hwnd, message, wParam,
lParam);
}
The other part of the story is that you shouldn't assign the value of a
variable in the header file, but do this in the implementation file.
> -----Original Message-----
> From: Marc Heiligers [mailto:ma...@e-...]
> Sent: Monday, December 02, 2002 02:32 PM
> To: dev-cpp-users-list
> Subject: [Dev-C++] Problem with RegisterWindowMessage()
>
>
> I have a little problem. I have a header file which I include
> in my main
> file (surprise surprise). In the header I have the following:
>
> const UINT WM_MYMESSAGE = RegisterWindowMessage(_T("some message"));
>
> Right, now in my main WindowProc I have a switch statement like so:
>
> LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM
> wParam, LPARAM
> lParam)
> {
> switch (message) /* handle the messages */
> {
> case WM_DESTROY:
> PostQuitMessage (0); /* send a WM_QUIT to
> the message
> queue */
> break;
> /*
> And some more message handlers here
> more
> more
> */
> case WM_MYMESSAGE:
> /*Do some stuff*/
> default:
> return DefWindowProc (hwnd, message, wParam, lParam);
> }
> return 0;
> }
>
> So far so good. Now when I compile I get the following little message:
>
> "case label `WM_MYMESSAGE' does not reduce to an integer constant"
>
> Now, personally, I thought that a "const UINT" was an integer
> constant, but
> clearly g++ disagrees. The funny thing is I have used similar
> code with VC++
> v6 and not had the same problem. Any ideas of how I can
> convince g++ that
> this is the case would be appreciated.
>
> _____________________________
> Marc Heiligers
>
> PS. I've had coffee before I wrote this, so I'm pretty sure
> I'm thinking
> straight (for a change).
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|