level 8
Sail丶Man
楼主
这次仅仅 限制了while(l<3)只循环3次 发现按Y后 鼠标并不会移过去。
但改成while(l<5)只循环5次 按Y后鼠标就会移过去。也就是说找之前找3遍都没找到色
必须找5遍以上才行。为什么?
# include <graphics.h>
# include <stdio.h>
int start(void);
void Quit(void);
void CaptureDesktop(IMAGE *pimg)
{int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
Resize(pimg, w, h);HDC aa = GetDC(NULL);
HDC dstDC = GetImageHDC(pimg);
BitBlt(dstDC, 0, 0, w, h, aa, 0, 0, SRCCOPY);}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{COLORREF cr;cr = start();
initgraph(200,60);
TCHAR s2[20];
sprintf(s2, _T("%#x"), cr);
TCHAR s1[30]="已确定你要找的颜色值为:";
outtextxy(0, 0, s1);
outtextxy(0, 20, s2);
TCHAR s[30]="按Y键开始找色,按B键退出";
outtextxy(0, 40, s);
int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
while (true){if (GetAsyncKeyState('Y'))
{closegraph();break;}Quit();}
int l=0;
while (l<3)
{
l++;
IMAGE img;
CaptureDesktop(&img);
saveimage(_T("f:\\testq1.bmp"), &img);
/*initgraph(640, 480);putimage(0, 0, &img);*/
loadimage(&img, "f:\\testq1.bmp");
DWORD* p = GetImageBuffer(&img);
POINT point;for(int i = 0; i < w * h; i++)
if (p[i] == BGR(cr) ){point.y = i / (w * 1.0);
point.x = i - point.y * w ;Sleep(100);
SetCursorPos(point.x, point.y);break;}
DeleteFile("f:\\testq1.bmp");Quit();}return 0;}
int start(void){initgraph(150,80);
HDC hdc = GetDC(NULL);COLORREF cr;
POINT point;TCHAR s[20];TCHAR s1[20]="横坐标:";TCHAR s2[20]="纵坐标:";
TCHAR s3[20]="颜色值:";
TCHAR s4[30]="按A键确定,按B键退出";
while(true){GetCursorPos(&point);
sprintf(s, _T("%05d"), point.x);
outtextxy(0, 0, s1);outtextxy(55, 0, s);
sprintf(s, _T("%05d"), point.y);outtextxy(0, 20, s2);
outtextxy(55, 20, s);Sleep(10);
cr = GetPixel(hdc, point.x, point.y);
sprintf(s, _T("%#x"), cr);outtextxy(0, 40, s3);
outtextxy(55, 40, s);outtextxy(0, 60, s4);
if (GetAsyncKeyState('A')){closegraph();ReleaseDC(NULL,hdc);return cr;}Quit();}}
void Quit(void){if(GetAsyncKeyState('B'))
{if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES)
exit(0);}return ;}
2013年09月27日 01点09分
1
但改成while(l<5)只循环5次 按Y后鼠标就会移过去。也就是说找之前找3遍都没找到色
必须找5遍以上才行。为什么?
# include <graphics.h>
# include <stdio.h>
int start(void);
void Quit(void);
void CaptureDesktop(IMAGE *pimg)
{int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
Resize(pimg, w, h);HDC aa = GetDC(NULL);
HDC dstDC = GetImageHDC(pimg);
BitBlt(dstDC, 0, 0, w, h, aa, 0, 0, SRCCOPY);}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{COLORREF cr;cr = start();
initgraph(200,60);
TCHAR s2[20];
sprintf(s2, _T("%#x"), cr);
TCHAR s1[30]="已确定你要找的颜色值为:";
outtextxy(0, 0, s1);
outtextxy(0, 20, s2);
TCHAR s[30]="按Y键开始找色,按B键退出";
outtextxy(0, 40, s);
int w = GetSystemMetrics(SM_CXSCREEN) ;
int h = GetSystemMetrics(SM_CYSCREEN) ;
while (true){if (GetAsyncKeyState('Y'))
{closegraph();break;}Quit();}
int l=0;
while (l<3)
{
l++;
IMAGE img;
CaptureDesktop(&img);
saveimage(_T("f:\\testq1.bmp"), &img);
/*initgraph(640, 480);putimage(0, 0, &img);*/
loadimage(&img, "f:\\testq1.bmp");
DWORD* p = GetImageBuffer(&img);
POINT point;for(int i = 0; i < w * h; i++)
if (p[i] == BGR(cr) ){point.y = i / (w * 1.0);
point.x = i - point.y * w ;Sleep(100);
SetCursorPos(point.x, point.y);break;}
DeleteFile("f:\\testq1.bmp");Quit();}return 0;}
int start(void){initgraph(150,80);
HDC hdc = GetDC(NULL);COLORREF cr;
POINT point;TCHAR s[20];TCHAR s1[20]="横坐标:";TCHAR s2[20]="纵坐标:";
TCHAR s3[20]="颜色值:";
TCHAR s4[30]="按A键确定,按B键退出";
while(true){GetCursorPos(&point);
sprintf(s, _T("%05d"), point.x);
outtextxy(0, 0, s1);outtextxy(55, 0, s);
sprintf(s, _T("%05d"), point.y);outtextxy(0, 20, s2);
outtextxy(55, 20, s);Sleep(10);
cr = GetPixel(hdc, point.x, point.y);
sprintf(s, _T("%#x"), cr);outtextxy(0, 40, s3);
outtextxy(55, 40, s);outtextxy(0, 60, s4);
if (GetAsyncKeyState('A')){closegraph();ReleaseDC(NULL,hdc);return cr;}Quit();}}
void Quit(void){if(GetAsyncKeyState('B'))
{if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES)
exit(0);}return ;}