[Win] Do not unregister class twice

Only the parent window would register a class, but both the parent and
the child window would unregister it. This is now fixed.
This commit is contained in:
Stefanos A. 2014-01-08 19:21:29 +01:00
parent 51baed7286
commit 7363cfee7b

View file

@ -326,25 +326,31 @@ namespace OpenTK.Platform.Windows
void HandleStyleChanged(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) void HandleStyleChanged(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
{ {
WindowBorder new_border = windowBorder;
unsafe unsafe
{ {
Debug.WriteLine(wParam.ToString());
if (wParam == new IntPtr((int)GWL.STYLE)) if (wParam == new IntPtr((int)GWL.STYLE))
{ {
WindowStyle style = ((StyleStruct*)lParam)->New; WindowStyle style = ((StyleStruct*)lParam)->New;
Debug.WriteLine(style.ToString());
if ((style & WindowStyle.Popup) != 0) if ((style & WindowStyle.Popup) != 0)
windowBorder = WindowBorder.Hidden; new_border = WindowBorder.Hidden;
else if ((style & WindowStyle.ThickFrame) != 0) else if ((style & WindowStyle.ThickFrame) != 0)
windowBorder = WindowBorder.Resizable; new_border = WindowBorder.Resizable;
else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0) else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0)
windowBorder = WindowBorder.Fixed; new_border = WindowBorder.Fixed;
} }
} }
// Ensure cursor remains grabbed if (new_border != windowBorder)
if (!CursorVisible) {
GrabCursor(); // Ensure cursor remains grabbed
if (!CursorVisible)
GrabCursor();
windowBorder = new_border;
WindowBorderChanged(this, EventArgs.Empty);
}
} }
void HandleSize(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) void HandleSize(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
@ -353,11 +359,18 @@ namespace OpenTK.Platform.Windows
WindowState new_state = windowState; WindowState new_state = windowState;
switch (state) switch (state)
{ {
case SizeMessage.RESTORED: new_state = borderless_maximized_window_state ? case SizeMessage.RESTORED:
WindowState.Maximized : WindowState.Normal; break; new_state = borderless_maximized_window_state ?
case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break; WindowState.Maximized : WindowState.Normal;
case SizeMessage.MAXIMIZED: new_state = WindowBorder == WindowBorder.Hidden ? break;
WindowState.Fullscreen : WindowState.Maximized;
case SizeMessage.MINIMIZED:
new_state = WindowState.Minimized;
break;
case SizeMessage.MAXIMIZED:
new_state = WindowBorder == WindowBorder.Hidden ?
WindowState.Fullscreen : WindowState.Maximized;
break; break;
} }
@ -374,7 +387,6 @@ namespace OpenTK.Platform.Windows
void HandleChar(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) void HandleChar(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
{ {
if (IntPtr.Size == 4) if (IntPtr.Size == 4)
key_press.KeyChar = (char)wParam.ToInt32(); key_press.KeyChar = (char)wParam.ToInt32();
else else
@ -541,7 +553,10 @@ namespace OpenTK.Platform.Windows
{ {
exists = false; exists = false;
Functions.UnregisterClass(ClassName, Instance); if (handle == window.Handle)
{
Functions.UnregisterClass(ClassName, Instance);
}
window.Dispose(); window.Dispose();
child_window.Dispose(); child_window.Dispose();
@ -554,6 +569,8 @@ namespace OpenTK.Platform.Windows
IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
{ {
Debug.WriteLine(message.ToString());
switch (message) switch (message)
{ {
#region Size / Move / Style events #region Size / Move / Style events
@ -1271,8 +1288,6 @@ namespace OpenTK.Platform.Windows
Visible = true; Visible = true;
WindowState = state; WindowState = state;
WindowBorderChanged(this, EventArgs.Empty);
} }
} }