February 14th, 2008
I’m working on switching from VS 2005 to VS 2008. I just tried running some unit tests and got the following dialog:

Hooray! I’ve been trying to figure out how to implement automatic test cleanup myself, but I (fortunately) hadn’t had time to devote serious effort to it. Up to this point, the TestResults directory would just continue to grow and grow until you either went in deleted the directory or ran an Ant target we have for ensuring any testing left-overs get mopped up.
1 Comment |
Uncategorized |
Visual Studio Tips |
Permalink
Posted by Eric
January 23rd, 2008
Sometimes you want the window handle of the host application when you’re writing an Office add-in. Excel includes that as a property of the Application object in newer versions of the object model, but Word and PowerPoint don’t. I seem to remember some sample code from Microsoft that suggests using FindWindow to get the handle, but that always seems problematic:
- You can search by class name (e.g. “OpusApp” for Word), but what if you somehow have multiple Word processes running? Which window do you get?
- You can search by window text, but it can be really hard to figure out what the window text is.
- You can set the Caption property on the Application object to some magic text and search for a window with the magic text, but Word throws all kinds of other stuff into the caption so this generally doesn’t work reliably.
Instead, if you’re using managed code, you can just do this:
IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle;
Underneath this uses EnumWindows and GetWindowThreadProcessId to find the right window.
No Comments » |
Uncategorized |
.NET, Office |
Permalink
Posted by Eric