我的GetWindowRect怎么失灵了
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;using Microsoft.Win32;namespace 活动窗体震动{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } internal struct RECT //Win32汇编数据结构不用自己定义 { public int left; public int top; public int right; public int bottom; } [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] internal static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] internal static extern RECT GetWindowRect(IntPtr hwnd); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] internal static extern void MoveWindow(IntPtr hwnd,int X,int Y,int nWidth,int nHeight,bool bRepaint); IntPtr id; private void timer1_Tick(object sender, EventArgs e) { id = GetForegroundWindow(); Random myRandom = new Random(); RECT Rect = GetWindowRect(id); MoveWindow(id, myRandom.Next(1024), myRandom.Next(768), Rect.right-Rect.left, Rect.bottom-Rect.top, true); } }}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
[解决办法]
个人觉得你的程序稍带有一定的“有害”性,如果不小心,我们的机子会被你的代码搞的乱了套!