抓“連連看”窗口之圖,分析后存入文本文件screen.txt中。
存入格式:
{0xA8, 0x88, 0x7E, 0x00, ...}
一個像素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 * fpTxt = fopen("screen.txt","wt");
if( fpTxt == NULL)
{
printf("Txt文件創建失敗!/n");
return;
}
fprintf(fpTxt, "{");
//獲取像素
for(y = 0 ; y <= 600; y++)
{
for(x = 0 ; x <= 800; x++)
{
bit = GetPixel(hdc, x, y);
//藍 - 綠 - 紅 字節
fprintf(fpTxt, "%02X, ", (bit & 0x00ff0000)>>16);
fprintf(fpTxt, "%02X, ", (bit & 0x0000ff00)>>8);
fprintf(fpTxt, "%02X, ", bit & 0x000000ff);
/*printf("0x%02x,", (bit & 0x00ff0000)>>16);
printf("0x%02x,", (bit & 0x0000ff00)>>8);
printf("0x%02x,", bit & 0x000000ff);*/
}
}
ReleaseDC(hwndGame, hdc);
fprintf(fpTxt, "}/r/n");
fclose(fpTxt);
printf("/n完成!/n");
}
eof