Friday, February 4, 2011

Move a Window

You can move a window at any place. All you have to do get the handle of that window which you want to move. There are two API functions that can be used to move a window.

To get the handle of the window.

public static extern int FindWindow(string lpClassName, string lpWindowName);

There are two parameter
lpClassName :- Name of the process.
lpWindowName :- Title of the Window

In case of a blank notepad window which has a title Untitle parameres

For example for a new unsaved notepad window

lpClassName :- Notepad
lpWindowName :- Untitle

To move the the window.

[DllImport("User32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool MoveWindow(IntPtr hWnd, int xPos, int yPos, int Width, int Height, bool repaint);

Parameters Detail.
hWnd :- Handle of the window
xPos :- xPosition where you have to move
yPos :- yPosition where you have to move
Width :- Width of the Window
Height :- Height of the window
repaint :- Do you want to repaint the window.

No comments: