Sign in to follow this  
Dzogchener

[.net] Subclassing a window in a different process

Recommended Posts

Hi, I am trying to subclass a window in a different process, and it doesnt seem to work. The other application in my test is a windows forms process. I wondered if anyone knows if there are issues with doing this in C#? I am surprised its not working. I manage to subclass (AFAIK), but I dont seem to get any callbacks coming through. Heres the class I use: class SubclassedWindow { public event EventHandler< EventArgs > MessageReceived; private const int GWL_WNDPROC = -4; private NativeAPI.WndProcDescriptor subclassedWndProc; private IntPtr originalWndProc; private IntPtr subclassedHandle; public SubclassedWindow() { subclassedWndProc = SubclassedWndProc; } public void AssignHandle(IntPtr handle) { subclassedHandle = handle; originalWndProc = NativeAPI.SetWindowLong(handle, GWL_WNDPROC, subclassedWndProc); } private int SubclassedWndProc( IntPtr hWnd, int Msg, int wParam, int lParam ) { if (MessageReceived != null) MessageReceived( this, EventArgs.Empty ); return NativeAPI.CallWindowProc(originalWndProc, subclassedHandle, Msg, wParam, lParam); } } This is in a simple NativeAPI class: public delegate int WndProcDescriptor(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImport("user32", SetLastError = true)] public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, WndProcDescriptor newProc); Anyone any clues? Thanks, D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this