抓“連連看”窗口之圖,分析后存入二進制文件screen.dat中。
存入格式(十六進制編輯器下觀察):
A8 88 7E 00 ...
一個像素3個字節,分別是藍色字節、綠色字節和紅色字節。
存儲為二進制。
//
/ main.cpp
#include "main.h"
#define CX 800
#define CY 600
#define SIZE (CX * CY * 5 -1 + 2 + 1)
void main(void)
{
printf("睡眠4秒鐘,請盡速最小化本窗口.../n");
Sleep(4000);
HWND hwndGame;
COLORREF bit;
HDC hdc;
unsigned short x, y;
//BYTE buf[SIZE + 4], * pcCurrent = buf;
BYTE pixel[3] = {0x00};
printf("%s","Start.../n");
//hwndGame = GetDesktopWindow();
hwndGame = FindWindow("#32770", (LPCTSTR)"QQ游戏 - 连连看角色版");
//hwndGame = FindWindow("Afx:e50000:8:10011:0:0", "QQ游戏");
//hwndGame = FindWindow("ConsoleWindowClass", NULL);
if(hwndGame == NULL)
{
printf("/"QQ游戏 - 连连看角色版/"窗口未能找到!/n");
return;
}
printf("hwndGame = 0x%X/n", hwndGame);
hdc = GetDC(hwndGame);
if(hdc == NULL)
{
printf("hdc未能得到!/n");
return;
}
printf("hdc = %u/n", hdc);
//創建文件
FILE * fpBin = fopen("screen.dat","wb");
if( fpBin == NULL)
{
printf("二進制文件創建失敗!/n");
return;
}
//fprintf(fpBin, "{");
//獲取像素
for(y = 0 ; y <= 600; y++)
{
for(x = 0 ; x <= 800; x++)
{
bit = GetPixel(hdc, x, y);
//藍 - 綠 - 紅 字節
/*fprintf(fpBin, "%02X", (bit & 0x00ff0000)>>16);
fprintf(fpBin, "%02X", (bit & 0x0000ff00)>>8);
fprintf(fpBin, "%02X", bit & 0x000000ff);*/
pixel[0] = (BYTE)(bit & 0x00ff0000) >> 16;
pixel[1] = (BYTE)(bit & 0x0000ff00) >> 8;
pixel[2] = (BYTE)bit & 0x000000ff;
fwrite(pixel, sizeof(BYTE), 3, fpBin);
/*printf("0x%02x,", (bit & 0x00ff0000)>>16);
printf("0x%02x,", (bit & 0x0000ff00)>>8);
printf("0x%02x,", bit & 0x000000ff);*/
}
}
ReleaseDC(hwndGame, hdc);
//fprintf(fpBin, "}/r/n");
fclose(fpBin);
printf("/n完成!/n");
}
eof