Search code examples
c#windows-8

Windows 8 and C#: what technology is needed to move windows programatically, even in the z direction?


I'm interested in begin able to manipulate windows programmatically. Perhaps by clicking on a window so it has focus, then by using some key combination, I can move the windows. Also, I'd like to move the windows in the z-direction, which would mean that it would appear to get smaller as it went deeper into the screen and bigger as it was moved toward me.

I would like this to apply to any existing window, being a text editor window, a browser window, or even the calculator program window.

The problem is that I have no idea what technology would be needed to accomplish that.

Any ideas?


Solution

  • You'd need to use the Win32 API (using P/Invoke).

    "Manipulating" a window would need several different API functions depending on what you want to do... these are a few:

    • FindWindow (pinvoke.net link) will allow you to find the window handle so you feed it into the other functions (there are more ways to find a window handle depending on your needs, but this one is by far the easiest)
    • MoveWindow(pinvoke.net link) allows you to set position and size
    • SetWindowPos (pinvoke.net link) to set the z-order of top-level windows

    etc.

    Use http://pinvoke.net to find out how to call Win32 API functions from c#, and use the MSDN (this link: http://msdn.microsoft.com/en-us/library/windows/desktop/ff468919(v=vs.85).aspx in particular) for a reference of all functions to handle Windows.

    Update

    Rereading your question it looks like you want to "simulate" a 3D-like effect in your windows. This is not in the API and there's no standarized way to do it as far as I know (the modern accelerated DWM does it, but I don't think you can access any functions to do that via its API).

    You could research into capturing the window contents to a bitmap, and render that bitmap scaled into your own window. It's not impossible, but it's not precisely easy and would be WAY too long to explain how to do this here.

    Update 2

    There's actually a DWM API (link to MSDN), but even with it, I doubt you can do what you want in a practical manner with it