Debug.Print("Entering the matrix"); HookWindowMessage(p.MainWindowHandle, SCWinProc); .... .... public delegate IntPtr WndProcDelegate(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", EntryPoint = "SetWindowLong")] private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, [MarshalAs(UnmanagedType.FunctionPtr)] WndProcDelegate windowCallback); [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, [MarshalAs(UnmanagedType.FunctionPtr)] WndProcDelegate windowCallback); public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, WndProcDelegate windowCallback) { if (IntPtr.Size == 8) return SetWindowLongPtr64(hWnd, nIndex, windowCallback); else return new IntPtr(SetWindowLong32(hWnd, nIndex, windowCallback)); } private const int GWL_WNDPROC = -4; public static IntPtr HookWindowMessage(IntPtr window, WndProcDelegate callback) { return SetWindowLongPtr(window, GWL_WNDPROC, callback); } public static IntPtr SCWinProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam) { Debug.Print("SCWinProc Called"); return (IntPtr)0; }