本人新手
using System.Runtime.InteropServices;
RECT rect = new RECT();
Random random = new Random();
IntPtr[]ptrtemp= new IntPtr[100];
int i = 0;
IntPtr x = GetForegroundWindow();
while (Array.IndexOf(ptrtemp, x) == -1)
{
ptrtemp[i] = x;
i++;
Thread thread = new Thread(run);
void run()
{
while (true)
{
Thread.Sleep(4000);
GetWindowRect(x, out rect);
MoveWindow(x, rect.left + random.Next(-10, 11), rect.top + random.Next(-10, 11), rect.right - rect.left, rect.bottom - rect.top, false);
}
}
thread.Start();
}
[DllImport("user32.dll")]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern bool MoveWindow(IntPtr hWnd,int x,int y,int nWidth,int nHeight,bool bRepaint);
public struct RECT
{
int left;
int top;
int right;
int bottom;
}
|