2

Is it possible to run a windows application (that opens a top-level window), inside of another window? Or set up an alternate 'desktop' / fake desktop, that owns the window?

I am using UI Automation to automate an application for testing. I want to put the application under test in a kind of sandbox: an artifical parent window between Desktop and app, or pseudo-desktop, second destop, etc. This desktop (and the app under test) does not need to be visible.

Different instances of the application under test (on the normal desktop, or in sandboxes) should not conflict with each other (window name/class wise) -- the app under test is safe to have multiple instances...

I realize this seems hackish, so win32 hacks would be welcome. :)

Craig Celeste
  • 12,207
  • 10
  • 42
  • 49
  • It is supported, you can call SetParent() to glue the window inside one of yours. Doesn't actually help at all, you still need the window handle to do anything meaningful. Calling GetWindowRect() accomplishes the same thing. – Hans Passant Mar 10 '12 at 13:50

2 Answers2

4

You could try using CreateDesktop to create a desktop, and pass its name in the STARTUPINFO when starting the target application.

Neil
  • 54,642
  • 8
  • 60
  • 72
  • 2
    Note that there are some limitations to this: much of UIAutomation functionality that manipulates the app (as opposed to just returning information) requires that the target UI has input focus, but an app can only receive input focus if it's on the currently active desktop. So you can create a desktop and put an app on it, but if that desktop is not the current (visible) one, some automation may fail in unexpected ways. – BrendanMcK Mar 13 '12 at 08:25
  • For some more details on issues with automation on a non-active desktop, see my answer to a related question [here](http://stackoverflow.com/questions/9563549/what-happens-behind-the-windows-lock-screen/9565714#9565714). – BrendanMcK Mar 13 '12 at 09:07
0

If you're automating an application for testing, then I guess you're trying to create a SandBox for the applications to be tested. There is a very good library by Liu Yu for this Also see this: Create Sandbox C# and this: How to create a lightweight C code sandbox?

Community
  • 1
  • 1
Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65