这是我的代码:
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; } }
反正有没有阻止铸造?
排序 - 铸造m.Msg代替:
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; } }
你需要演员的原因是因为在C#中枚举不只是数字 - 它们是与该类型相关的数字.这可以防止你做(没有强制转换):
HttpStatusCode status = someWindowsMessageFlag;
这显然是一件好事:)但是,当你需要时,你总是可以"通过"底层类型(在这种情况下为int).