SetWindowPos (coredll)
Last changed: -90.187.255.169

.
Summary
This function changes the size, position, and z-order of a child, pop-up, or top-level window. Child, pop-up, and top-level windows are ordered according to their appearance on the screen. The topmost window receives the highest rank and is the first window in the z-order.

C# Signature:

[DllImport("coredll.dll", SetLastError=true)]
private static extern bool SetWindowPos(IntPtr hwnd, int hwnd2, int x, int y, int cx, int cy, int uFlags);

VB.Net Signature:

Declare Auto Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, _
                      ByVal hWndInsertAfter As IntPtr, _
                      ByVal X As Integer, _
                      ByVal Y As Integer, _
                      ByVal cx As Integer, _
                      ByVal cy As Integer, _
                      ByVal uFlags As UInteger) As Boolean

User-Defined Types:

C# Signature:

    public const int SWP_ASYNCWINDOWPOS = 0x4000;
    public const int SWP_DEFERERASE = 0x2000;
    public const int SWP_DRAWFRAME = 0x0020;
    public const int SWP_FRAMECHANGED = 0x0020;
    public const int SWP_HIDEWINDOW = 0x0080;
    public const int SWP_NOACTIVATE = 0x0010;
    public const int SWP_NOCOPYBITS = 0x0100;
    public const int SWP_NOMOVE = 0x0002;
    public const int SWP_NOOWNERZORDER = 0x0200;
    public const int SWP_NOREDRAW = 0x0008;
    public const int SWP_NOREPOSITION = 0x0200;
    public const int SWP_NOSENDCHANGING = 0x0400;
    public const int SWP_NOSIZE = 0x0001;
    public const int SWP_NOZORDER = 0x0004;
    public const int SWP_SHOWWINDOW = 0x0040;

VB.Net Signature:

TODO

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Use this to hide the start menu and start bar.

Sample Code:

    public void HideStartBar()
    {
        IntPtr handle;

        try
        {
        // Find the handle to the Start Bar
        handle = FindWindowW("HHTaskBar", null);

        // If the handle is found then hide the start bar
        if (handle != IntPtr.Zero)
        {
            // Hide the start bar
            SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
        }
        }
        catch
        {
        MessageBox.Show("Could not hide Start Bar.");
        }
    }

    public void ShowStartBar()
    {
        IntPtr handle;

        try
        {
        // Find the handle to the Start Bar
        handle = FindWindowW("HHTaskBar", null);

        // If the handle is found then show the start bar
        if (handle != IntPtr.Zero)
        {
            // Show the start bar
            SetWindowPos(handle, 0, 0, 0, 240, 26, SWP_SHOWWINDOW);
        }
        }
        catch
        {
        MessageBox.Show("Could not show Start Bar.");
        }
    }

Documentation