Jump to content
  • Advertisement
Sign in to follow this  
Dzogchener

[.net] Subclassing a window in a different process

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!