Use UIntPtr instead of IntPtr to avoid overflow exceptions in x64 mode.

This commit is contained in:
the_fiddler 2008-11-09 11:43:02 +00:00
parent e6baa0a42f
commit 9bbef90088

View file

@ -62,6 +62,13 @@ namespace OpenTK.Platform.Windows
bool mouse_about_to_enter = false; bool mouse_about_to_enter = false;
protected override void WndProc(ref Message msg) protected override void WndProc(ref Message msg)
{ {
UIntPtr lparam, wparam;
unsafe
{
lparam = (UIntPtr)(void*)msg.LParam;
wparam = (UIntPtr)(void*)msg.WParam;
}
switch ((WindowMessage)msg.Msg) switch ((WindowMessage)msg.Msg)
{ {
// Mouse events: // Mouse events:
@ -70,8 +77,9 @@ namespace OpenTK.Platform.Windows
break; break;
case WindowMessage.MOUSEMOVE: case WindowMessage.MOUSEMOVE:
mouse.Position = new System.Drawing.Point(msg.LParam.ToInt32() & 0x0000FFFF, mouse.Position = new System.Drawing.Point(
(int)(msg.LParam.ToInt32() & 0xFFFF0000) >> 16); (int)(lparam.ToUInt32() & 0x0000FFFF),
(int)(lparam.ToUInt32() & 0xFFFF0000) >> 16);
if (mouse_about_to_enter) if (mouse_about_to_enter)
{ {
Cursor.Current = Cursors.Default; Cursor.Current = Cursors.Default;
@ -80,7 +88,7 @@ namespace OpenTK.Platform.Windows
return; return;
case WindowMessage.MOUSEWHEEL: case WindowMessage.MOUSEWHEEL:
mouse.Wheel += (msg.WParam.ToInt32() >> 16) / 120; mouse.Wheel += (int)(wparam.ToUInt32() >> 16) / 120;
return; return;
case WindowMessage.LBUTTONDOWN: case WindowMessage.LBUTTONDOWN:
@ -96,7 +104,7 @@ namespace OpenTK.Platform.Windows
return; return;
case WindowMessage.XBUTTONDOWN: case WindowMessage.XBUTTONDOWN:
mouse[((msg.WParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true; mouse[((wparam.ToUInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true;
return; return;
case WindowMessage.LBUTTONUP: case WindowMessage.LBUTTONUP:
@ -113,7 +121,7 @@ namespace OpenTK.Platform.Windows
case WindowMessage.XBUTTONUP: case WindowMessage.XBUTTONUP:
// TODO: Is this correct? // TODO: Is this correct?
mouse[((msg.WParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false; mouse[((wparam.ToUInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false;
return; return;
// Keyboard events: // Keyboard events:
@ -132,7 +140,7 @@ namespace OpenTK.Platform.Windows
// In this case, both keys will be reported as pressed. // In this case, both keys will be reported as pressed.
bool extended = (msg.LParam.ToInt64() & ExtendedBit) != 0; bool extended = (msg.LParam.ToInt64() & ExtendedBit) != 0;
switch ((VirtualKeys)msg.WParam) switch ((VirtualKeys)wparam)
{ {
case VirtualKeys.SHIFT: case VirtualKeys.SHIFT:
// The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit // The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit
@ -144,10 +152,13 @@ namespace OpenTK.Platform.Windows
// TODO: Not 100% reliable, when both keys are pressed at once. // TODO: Not 100% reliable, when both keys are pressed at once.
if (ShiftRightScanCode != 0) if (ShiftRightScanCode != 0)
{ {
if (((msg.LParam.ToInt32() >> 16) & 0xFF) == ShiftRightScanCode) unchecked
keyboard[Input.Key.ShiftRight] = pressed; {
else if (((lparam.ToUInt32() >> 16) & 0xFF) == ShiftRightScanCode)
keyboard[Input.Key.ShiftLeft] = pressed; keyboard[Input.Key.ShiftRight] = pressed;
else
keyboard[Input.Key.ShiftLeft] = pressed;
}
} }
else else
{ {