views:

53

answers:

1

Simple, i want to move a windows pressing ALT+MOUSE, like linux os (ALT+drag).

It's possible to pass a win32 api (move api) to the windows interested clicking on it?

I have a windows services that hook key pressed (ALT button in specific). When ALT key is pressed and a mouse down event is verified, i want to move window clicking anywhere, not only on the title bar!

Currently i move my form windows in this way:

using System.Runtime.InteropServices;

[DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = false )]
static extern IntPtr SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam );
[DllImportAttribute( "user32.dll", CharSet = CharSet.Auto, SetLastError = false )]
public static extern bool ReleaseCapture();

private void Form1_MouseDown( object sender, MouseEventArgs e )
{
  ReleaseCapture();
  SendMessage( this.Handle, 0xa1, 0x2, 0 );
}

How can I get windows handle of the specific windows by clicking and after call SendMessage() on it?

It's possible?

+1  A: 

You can do this by trapping the WM_NCHITTEST message that Windows sends to see what area of the window got clicked. You can fool it by returning HTCAPTION and it will dutifully perform the mouse actions you'd normally get when clicking the caption of a window. Including moving the window. Paste this code into your form:

    protected override void WndProc(ref Message m) {
        base.WndProc(ref m);
        // Trap WM_NCHITTEST when the ALT key is down
        if (m.Msg == 0x84 && (Control.ModifierKeys == Keys.Alt)) {
            // Translate HTCLIENT to HTCAPTION
            if (m.Result == (IntPtr)1) m.Result = (IntPtr)2;
        }
    }
Hans Passant
uhm... this is ok, but it moves only my form. I need to move the others windows...
pask
Put this code in a base form class. Inherit your other forms from that base class.
Hans Passant
no, sorry... but i want to move system windows like calc, notepad, browser, any windows... like this: http://www.howtogeek.com/howto/windows-vista/get-the-linux-altwindow-drag-functionality-in-windows/
pask