1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| private void button1_Click(object sender, EventArgs e) { Form1.ActiveForm.BackColor = Color.FromArgb(255, 0, 0, 0); Application.DoEvents(); hWnd = GetDesktopWindow(); Bitmap lBitmap = CreateScreenshot(hWnd); vi = 0; Thread s = new Thread(Thread1); s.Start(); Thread.Sleep(1000); Form1.ActiveForm.BackColor = Color.FromArgb(255, 254, 255, 255); Application.DoEvents(); s.Join(); } private void Thread1() { lBitmap = new Bitmap(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height); IntPtr hWnd = GetDesktopWindow(); IntPtr hSourceDC = GetWindowDC(hWnd); IntPtr hDestDC = CreateCompatibleDC(hSourceDC); IntPtr hBitmap = CreateCompatibleBitmap(hSourceDC, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height); IntPtr hObject = SelectObject(hDestDC, hBitmap); BitBlt(hDestDC, 0, 0, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height, hSourceDC, 0, 0, SRCCOPY); lBitmap = Image.FromHbitmap(hBitmap);
while (!((lBitmap.GetPixel(640, 400) == lBitmap.GetPixel(640, 401))&&(lBitmap.GetPixel(640, 400) == Color.FromArgb(255, 254, 255, 255)))) { hObject = SelectObject(hDestDC, hBitmap); BitBlt(hDestDC, 0, 0, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height, hSourceDC, 0, 0, SRCCOPY); lBitmap = Image.FromHbitmap(hBitmap); vi++; } } |