public struct RECT
{
public int left;
public int Top;
public int Right;
public int Bottom;
}
public static bool CenterMouseOn(int hwnd)
{
int x=0;
int y=0;
int maxX=0;
int maxY=0;
RECT crect=new RECT();
int gFound=0;
GetDisplayResolution(ref maxX,ref maxY);
gFound=GetWindowRect(hwnd,ref crect);
x=crect.Left+((crect.Right-crect.Left)/2);
y=crect.Top+((crect.Bottom-crect.Top)/2);
if((x>=0&&x<=maxX)&&(y>=0&&y<=maxY))
{
MoveMouse(hwnd,x,y);
return true;
}
return false;
}
public static void GetDisplayResolution(ref int pixelX,ref int pixelY)
{
pixelX=GetSystemMetrics(SM_CXSCREEN);
pixelY=GetSystemMetrics(SM_CYSCREEN);
}