Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
MoveWindow (user32)
.
C# Signature:
[DllImport("user32.dll")]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth,
int nHeight, bool bRepaint);
C++ Signature:
[DllImport("User32.dll")]
static bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
VB.NET
<DllImport("user32.dll")>_
Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
End Function
User-Defined Types:
None.
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
C# Code:
class Program
{
internal struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
internal static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
static void Main(string[] args)
{
IntPtr id;
RECT Rect = new RECT();
Thread.Sleep(2000);
id = GetForegroundWindow();
Random myRandom = new Random();
GetWindowRect(id, ref Rect);
MoveWindow(id, myRandom.Next(1024), myRandom.Next(768), Rect.right - Rect.left, Rect.bottom - Rect.top, true);
}
}
VB code:
Public Declare Auto Function MoveWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal X As Int32, _
ByVal Y As Int32, _
ByVal nWidth As Int32, _
ByVal nHeight As Int32, _
ByVal bRepaint As Boolean _
) As Boolean
Private Sub ResizeMe_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ResizeMe.MouseMove
I always enjoyed how when you typed an incorrect password in mac the window shakes itself back and forth like it's saying no. Here's a simple piece of code you could use in a login form to do just that.
VB code:
Public Declare Auto Function MoveWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal X As Int32, _
ByVal Y As Int32, _
ByVal nWidth As Int32, _
ByVal nHeight As Int32, _
ByVal bRepaint As Boolean _
) As Boolean
Private InitX As Integer
Private LR As String = "L"
Private C As Integer = 0
Private X As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
InitX = Me.Location.X
X = InitX
C = 0
Timer1.Interval = 1
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
C += 1
If X = InitX - 6 Then
LR = "R"
ElseIf X = InitX + 6 Then
LR = "L"
End If
If LR = "L" Then
X = X - 2
Else
X = X + 2
End If
MoveWindow(Me.Handle, X, Me.Location.Y, Me.Width, Me.Height, True)
Me.Refresh()
System.Windows.Forms.Application.DoEvents()
If C = 30 Then
Timer1.Stop()
End If
End Sub
The MoveWindow API
3/28/2016 1:39:06 PM - -67.166.68.151
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).