c# 不可访问 因为它受保护级别限制
本人新手```
using System.Runtime.InteropServices;
RECT rect = new RECT();
Random random = new Random();
IntPtr[]ptrtemp= new IntPtr;
int i = 0;
IntPtr x = GetForegroundWindow();
while (Array.IndexOf(ptrtemp, x) == -1)
{
ptrtemp = 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();
}
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
static extern IntPtr GetForegroundWindow();
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;
}
```
https://s3.bmp.ovh/imgs/2022/04/08/24686b59ad5d25ae.png
求大佬帮忙 RECT 内部的字段要加public修饰 把函数写开来你就全明白了,跨函数调用资源 struct不用new就可以实例化,RECT rect; public struct RECT
{
publicint left;……
} ok了 谢谢大佬们 public 公开
页:
[1]