Folks quite often ask how to get information about controls from outside the process.  In addition to active accessibility (the recommended solution for testing windows forms applications) there's also a handy window message which Control supports called WM_GETCONTROLNAME.  Calling SendMessage with WM_GETCONTROLNAME returns the Control.Name property.  Brian McMaster has talked about this special message here, and how to use it with VisualTest. 

The one giant caveat about using this method is that from outside the process, you need to use shared memory to make it work as the remarks for SendMessage point out:

The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another process, you must do custom marshalling.

Ben's Managed Spy sample has sample code for creating memory mapped files, which of course has even richer information returned back for Windows Forms 2.0 forms.


Comments (0)

Skip to main content