<p>This is my code:</p>

<pre><code>internal enum WindowsMessagesFlags {
    WM_EXITSIZEMOVE      = 0x00000232,
    WM_DISPLAYCHANGE     = 0x0000007e,
    WM_MOVING            = 0x00000216,
}

protected override void WndProc(ref Message m) {
    switch(m.Msg) {
        case (int)WindowsMessagesFlags.WM_DISPLAYCHANGE:
            FixWindowSnapping();
            break;
        case (int)WindowsMessagesFlags.WM_EXITSIZEMOVE:
            SaveWindowProperties();
            break;
        case (int)WindowsMessagesFlags.WM_MOVING:
            KeepProperLocation(ref m);
            break;
    }
}
</code></pre>

<p>Is there anyway to prevent the casting?</p>

Sort of - cast m.Msg instead:
```
```
protected override void WndProc(ref Message m) {
    switch((WindowsMessagesFlags) m.Msg) {
        case WindowsMessagesFlags.WM_DISPLAYCHANGE:
                FixWindowSnapping();
                break;
        case WindowsMessagesFlags.WM_EXITSIZEMOVE:
                SaveWindowProperties();
                break;
        case WindowsMessagesFlags.WM_MOVING:
                KeepProperLocation(ref m);
                break;
    }
}
```
```
The reason you need the cast at all is because in C# enums aren't just numbers - they're numbers associated with the type. This prevents you from doing (without casting):
```
```
HttpStatusCode status = someWindowsMessageFlag;
```
```
This is clearly a good thing :) When you need to, however, you can always go "via" the underlying type (int in this case).