Skip to content

Commit

Permalink
Added WM_CLOSE handling back.
Browse files Browse the repository at this point in the history
  • Loading branch information
valyard committed Sep 20, 2015
1 parent 1f6fb89 commit 0cc4f07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -154,6 +154,12 @@ private IntPtr wndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
case WM_TOUCH:
decodeTouches(wParam, lParam);
return IntPtr.Zero;
case WM_CLOSE:
// Not having this crashes app on quit
UnregisterTouchWindow(hWnd);
SetWindowLongPtr(hWnd, -4, oldWndProcPtr);
SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
return IntPtr.Zero;
default:
return CallWindowProc(oldWndProcPtr, hWnd, msg, wParam, lParam);
}
Expand Down Expand Up @@ -214,6 +220,7 @@ private void decodeTouches(IntPtr wParam, IntPtr lParam)
#region p/invoke

// Touch event window message constants [winuser.h]
private const int WM_CLOSE = 0x0010;
private const int WM_TOUCH = 0x0240;

// Touch API defined structures [winuser.h]
Expand Down Expand Up @@ -245,6 +252,9 @@ private IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
}

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

Expand Down
Expand Up @@ -145,6 +145,11 @@ private IntPtr wndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
case WM_POINTERUPDATE:
decodeTouches(msg, wParam, lParam);
return IntPtr.Zero;
case WM_CLOSE:
// Not having this crashes app on quit
SetWindowLongPtr(hWnd, -4, oldWndProcPtr);
SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
return IntPtr.Zero;
default:
return CallWindowProc(oldWndProcPtr, hWnd, msg, wParam, lParam);
}
Expand Down Expand Up @@ -206,6 +211,7 @@ private void decodeTouches(uint msg, IntPtr wParam, IntPtr lParam)
#region p/invoke

// Touch event window message constants [winuser.h]
private const int WM_CLOSE = 0x0010;
private const int WM_TOUCH = 0x0240;
private const int WM_POINTERDOWN = 0x0246;
private const int WM_POINTERUP = 0x0247;
Expand Down Expand Up @@ -270,6 +276,9 @@ private IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
}

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

Expand Down

0 comments on commit 0cc4f07

Please sign in to comment.