locked
Snap window to desktop RRS feed

  • Question

  • Hi guys,
    i'm looking for a solution of a big problem.
    i create normal window. this window should snap to a desktop-edge, when the user drags the window to the edge of it. i didn't found any solution for that.

    regarding applications like miranda or icq: the do it like the same way. when the window is snapped to the edge, other applications only use the remaining desktop-size for the viewport.

    thx for any hint.

    juergen
    Friday, June 29, 2007 7:51 AM

Answers

  • In the assembly System.Windows.Forms, there's a class called Screen. It makes available a list of AllScreens which you can iterate through to determine the dimensions of the displays that are available to the user.

    Once you've done that, you'll need to attach to the LocationChanged event. The bad news is that it's not easy to detect the window's position changing -- only the 'changed' event is exposed. Without the 'changing' event, you won't get an easy 'snap to' style application.

    I don't have any handy code on or links on how to do the harder steps of getting access to the actual HWND hosting the window and getting access to the Windows messages you'll need (WM_MOVING).

    If you want to go the full route of creating a toolbar for Windows -- you'll need to look for examples on how to create a Toolbar for the Windows shell -- there are lots of examples available. You'll need to use an ElementHost though then to host your WPF content. (And if you go this route, you can use the Overrideable WndProc method to get access to the WM_MOVING message quite easily).
    Friday, June 29, 2007 12:50 PM