Sail丶Man
Sail丶Man
只有回忆将化作为丶永恒丨
关注数: 8
粉丝数: 21
发帖数: 568
关注贴吧数: 17
还有一个 教程 小问题~ 范例程序 -> 彩色图片转换为底片效果-> for(int i = pimg->getwidth() * pimg->getheight(); i >= 0; i--) 其中pimg->getwidth() * pimg->getheight()会越界,忘记了-1
教程中的一个报错。 技术文章-> 学习保存应用程序的配置信息-> if (sqrt((msg.x - x) * (msg.x - x) + (msg.y - y) * (msg.y - y)) < R) 其中的sqrt 有报错:对重载函数的调用不明确。
一个关于TransparentBlt的问题. 同样是获得绘图窗口的HDC 为什么以下这种获得的,就可以不用加FlushBatchDraw();就能把图片显示出来。 # include <graphics.h> # include <conio.h> #pragma comment(lib, "msimg32.lib") #pragma comment(lib, "Winmm.lib") int main(void) { initgraph(200, 200); IMAGE img; loadimage(&img, _T("dunpai.bmp"));//自己修改以下 HWND hwnd = GetHWnd(); HDC hdc = GetDC(hwnd); //GetWorkingImage(); //HDC hdc = GetImageHDC(); HDCsrcDC = GetImageHDC(&img); TransparentBlt(hdc,0,0, 28, 28, srcDC, 0, 0, 28, 28, RGB(100,100,100)); // 使显存生效(注:操作指向 IMAGE 的显存不需要这条语句) //FlushBatchDraw(); getch(); return 0; }
yangw80求助啊~~~帮我调试一下这个。。。 就是以下地址:pan.baidu.com/s/19UZyy (坦克2)———— pan.baidu.com/s/1GaDnB (坦克1) 的这两个坦克 (坦克1的dsw文件运行后按A玩不起。 坦克2的dsw文件运行后按A玩得起),你是不是也是这样 ,你看看问题出在哪了?我整了 很久了 实在没办法了。。谢谢你了
如何 传递 二维数组呢??? 这样 不行~~~~~~~~~~~~~~~~! 我希望在子函数仍然可以p[][]这样的使用数组 # include <stdio.h> void b(int * p) { for (int i=0; i<5; i++) for (int j=0; j<5; j++) printf("%d", p[i][j]); } int main(void) { int a[5][5] = {1, 2, 3, 4, 5,1, 2, 3, 4, 5,1, 2, 3, 4, 5}; b(a); return 0; }
找色 第三个问题~~~~~~~~~~~~~~ 这次仅仅 限制了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 ;}
找色 第二个问题~~~~~~~~~~~~~~~~~~~~~~~ 这次仅仅去掉了saveimage(_T("f:\\testq1.bmp"), &img);loadimage(&img, "f:\\testq1.bmp");程序就识别不了这个img 就找不到色 ,就是 按Y 后 没反应了。 —————————————————————————— # 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();} while (true) {IMAGE img; CaptureDesktop(&img); /*initgraph(640, 480);putimage(0, 0, &img);*/ 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 ;}
找色 第一个问题~~~~~~~~~~~~~~~~~~~~ while(true){IMAGE img; 去掉后 只找一次色 按逻辑看应该可以 但实验证明 这一次的桌面截图是全黑的。为什么?截图是黑的就无法找色了。当然按Y之前程序正常运行,因为程序还没跑到这里来。 这次代码 我已经去掉while() 去掉DeleteFile("f:\\testq1.bmp");在f盘 你就能找到这一次的截图效果 是全黑的。又加上了initgraph(640, 480);putimage(0, 0, &img);多了while(!(GetAsyncKeyState(VK_ESCAPE) & 0x8000))你也会看到这一次的截图 是全黑的。 ———————————————————————————————— # 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();} 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;};Quit();while(!(GetAsyncKeyState(VK_ESCAPE) & 0x8000))Sleep(20); 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 ;} ——————————————————————————————
自动跳舞 外 挂~~!!!! 主要通过 找色实现,程序很简单可自己看懂。 ———————————————————————— 大家可以先玩一下这个小游戏:http://tieba.baidu.com/mo/q/checkurl?url=http%3A%2F%2Fzy.anjian.com%2Flab%2Fcontent_01.html&urlrefer=44a5f28aa92fd49be72afe121aa0f729 ———————————————————————— 以下是我为这个程序写的一个外挂: (按Esc可退出)若一次不成功可多试几次。 ———————————————————————— # include <graphics.h> POINT ZhaoSe(COLORREF c); void CaptureDesktop(IMAGE *); void Quit(void); int DianJi(int,int,int,int,int,int,int,int); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {while (true) {DianJi(324,117, 322,74 , 335,88, 293,86); DianJi(223,117 , 221,74, 234,88, 192,86); DianJi(122,117, 120,74, 133,88, 91,86 ); if (!(DianJi(21 ,117, 19 , 74, 32 ,88, (-9) ,86))) {keybd_event(32,0,0,0);keybd_event(32,0,KEYEVENTF_KEYUP,0);//Spacebar }Sleep(1350); Quit(); /*while(GetAsyncKeyState(VK_ESCAPE)){Sleep(20);exit(0);}*/} return 0;} 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);} POINT ZhaoSe(COLORREF c) {POINT point;IMAGE img; int w = GetSystemMetrics(SM_CXSCREEN) ; int h = GetSystemMetrics(SM_CYSCREEN) ; while(true) {CaptureDesktop(&img);saveimage(_T("f:\\testq1.bmp"), &img); loadimage(&img, "f:\\testq1.bmp"); DWORD* p = GetImageBuffer(&img); for(int i = 0; i < w * h; i++)if (p[i] == BGR(c) ) {point.y = i / (w * 1.0); point.x = i - point.y * w ; break;}DeleteFile("f:\\testq1.bmp"); if (point.x>=0 && point.y>=0)break;}return point;} int DianJi(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {POINT point;point = ZhaoSe(0xa57836); HDC hdc = GetDC(NULL); COLORREF c;COLORREF c1; COLORREF c2;COLORREF c3; c = GetPixel(hdc, point.x - x1, point.y - y1); c1 = GetPixel(hdc, point.x - x2, point.y - y2); c2 = GetPixel(hdc, point.x - x3, point.y - y3); c3 = GetPixel(hdc, point.x - x4, point.y - y4); if (0x3399ff == c) {keybd_event(40,0,0,0);keybd_event(40,0,KEYEVENTF_KEYUP,0);//下 }if (0x3399ff == c1){keybd_event(38,0,0,0);keybd_event(38,0,KEYEVENTF_KEYUP,0);//上 }if (0x3399ff == c2){keybd_event(39,0,0,0);keybd_event(39,0,KEYEVENTF_KEYUP,0);//右 }if (0x3399ff == c3){keybd_event(37,0,0,0);keybd_event(37,0,KEYEVENTF_KEYUP,0);//左 }return 0;} void Quit(void) {if(GetAsyncKeyState(VK_ESCAPE)){if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES)exit(0);} return ;} ——————————————————————————————————
自动找点 外 挂~~!!!! 找色这个工具真的太强大了,用这个可变相的实现一个网页游戏的自动打怪。 ———————————————————————— 大家先玩一下这个小游戏:http://tieba.baidu.com/mo/q/checkurl?url=http%3A%2F%2Fzy.anjian.com%2Flab%2Fcontent_07.html&urlrefer=0499b908bb339559142b14095159475e 看你能打到第几关。 以下是这个小游戏的 外挂。按Esc 可退出程序。程序很简单可自己看懂。 ———————————————————————— # include <graphics.h> POINT ZhaoSe(COLORREF c);//找色 void CaptureDesktop(IMAGE *);//配合上面那个函数构成找色工具。 void dianji(COLORREF ); void Quit(void); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { while (true) { dianji(0x2b2bc4);//红 dianji(0xc6c66a);//天蓝色 dianji(0x319ce4);//黄色 dianji(0x8327c0);//紫色 dianji(0xcf4f4f);//蓝色 dianji(0x1db6b6);//柠檬色 Quit(); } return 0;} 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); } POINT ZhaoSe(COLORREF c) { POINT point; int w = GetSystemMetrics(SM_CXSCREEN) ; int h = GetSystemMetrics(SM_CYSCREEN) ; IMAGE img;CaptureDesktop(&img); saveimage(_T("f:\\testq1.bmp"), &img); loadimage(&img, "f:\\testq1.bmp"); DWORD* p = GetImageBuffer(&img); for(int i = 0; i < w * h; i++) if (p[i] == BGR(c) ) { point.y = i / (w * 1.0); point.x = i - point.y * w ; break; } DeleteFile("f:\\testq1.bmp"); return point; } void dianji(COLORREF c) { POINT point;point = ZhaoSe(c); if (point.x >= 0 && point.y >= 0) { SetCursorPos(point.x, point.y); mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 ); }} void Quit(void) { if(GetAsyncKeyState(VK_ESCAPE)) { if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES) exit(0); } return ;} ——————————————————————————————————
自动补血 外 挂~~!!!! 呵呵, 自从上回写出了找色 这个程序 真的发现它是越来越强大了。 —————————————————————— 大家先玩玩这个小游戏。手速要快的补血小游戏。 http://tieba.baidu.com/mo/q/checkurl?url=http%3A%2F%2Fzy.anjian.com%2Flab%2Fcontent_02.html&urlrefer=37021b4662eddfa5ea0441566530c8b9 —————————————————————— 以下是我为这个小游戏写的一个外挂。Esc可退出程序。 # include <graphics.h> # include <stdio.h> POINT ZhaoSe(COLORREF c);//找色要配合下面那个函数 void CaptureDesktop(IMAGE *);//找色工具配合这个一起用 构成 找色工具 void Quit(void);//退出程序 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)//主函数 { POINT point; COLORREF c; COLORREF c1; COLORREF c2; COLORREF c3; COLORREF c4; COLORREF c5; HDC hdc = GetDC(NULL);//获取桌面hdc while (true) { point = ZhaoSe(0x81511f); c = GetPixel(hdc, point.x - 312, point.y - 335);//血低于这个点时 按q c1 = GetPixel(hdc, point.x - 312, point.y - 291); c2 = GetPixel(hdc, point.x - 353, point.y - 108); c3 = GetPixel(hdc, point.x - 265, point.y - 108); c4 = GetPixel(hdc, point.x - 100, point.y - 126); c5 = GetPixel(hdc, point.x - 15, point.y - 120);//以上同理 if (0xaeaeae == c)//空血条的背景颜色 ,血低于这个点时 按q 以下同理。 { keybd_event(81,0,0,0); keybd_event(81,0,KEYEVENTF_KEYUP,0); } if (0xaeaeae == c1) { keybd_event(87,0,0,0); keybd_event(87,0,KEYEVENTF_KEYUP,0); } if (0xffffff == c2) { keybd_event(65,0,0,0); keybd_event(65,0,KEYEVENTF_KEYUP,0); } if (0xffffff == c3) { keybd_event(83,0,0,0); keybd_event(83,0,KEYEVENTF_KEYUP,0); } if (0xe6e6e6 == c4) { keybd_event(68,0,0,0); keybd_event(68,0,KEYEVENTF_KEYUP,0); } if (0xe6e6e6 == c5) { keybd_event(70,0,0,0); keybd_event(70,0,KEYEVENTF_KEYUP,0); }Quit(); /*while(GetAsyncKeyState(VK_ESCAPE)){Sleep(20);exit(0);}*/} return 0;} 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);} POINT ZhaoSe(COLORREF c) {POINT point; int w = GetSystemMetrics(SM_CXSCREEN) ; int h = GetSystemMetrics(SM_CYSCREEN) ; IMAGE img; CaptureDesktop(&img); saveimage(_T("f:\\testq1.bmp"), &img); //这部不是多余的,不要会出莫名其妙的问题。 loadimage(&img, "f:\\testq1.bmp");//这部不是多余的,不要会出莫名其妙的问题。 DWORD* p = GetImageBuffer(&img); for(int i = 0; i < w; i++) { for(int j = 0; j < h; j++)if (p[j * w + i] == BGR(c) ) { point.x = i; point.y = j; break; } if (point.x>=0 && point.y>=0) break; } DeleteFile("f:\\testq1.bmp"); return point; } void Quit(void) { if(GetAsyncKeyState(VK_ESCAPE)) { if(MessageBox(NULL, "你确定要退出吗?","提示", MB_YESNO) == IDYES) exit(0); } return ;} ————————————————————————————- 补血 自动 按键非常好写,但最大的问题就是 每个人打开的窗口位置不同, 依然要找准每罐血要到底时就非常难了,找色就很好地解决了这个问题, 因为 它用的不是绝对位置,而是相对位置,例如这个游戏中我找的参考点就是 按键精灵这几个字。 我先用找色工具找到 “按”字 的左上角坐标 再相对于这个坐标来决定某个(血快要完点)点位置比如point.x - 312这样无论你窗口怎么动 都可以找准这个点了。 我也不知道你们听懂没,程序很简单可以自己看懂。 呵呵,我觉得EasyX完全可以考虑把这个找色工具列入教程了~~。 说真心话这个工具用处真的太大了。
简单的 侵蚀病毒~~~~ 慎!!!!把 while()里改成 true或1 死循环 就ok了~!!!! ———————————————————————— 电脑配置不行的最好别运行这个程序~~ 我i7电脑 都卡的要死~ # include <graphics.h> # include <conio.h> # include <stdio.h> int main(void) {int i = 0; int w = GetSystemMetrics(SM_CXSCREEN) ; int h = GetSystemMetrics(SM_CYSCREEN) ; Sleep(2000); HDC hDC=GetDC(NULL); while (i < 50000) {SetPixel(hDC,rand() % w, rand() % h,GREEN);i++;}ReleaseDC(NULL,hDC); return 0;}
功能软件 连点器~~ # include <windows.h> # include <conio.h> # include <stdio.h> int j = 0; void Quit(void); void start(void); int main(void){ int i = 0;while (true) {printf("按一下B点击鼠标左键1000次"); start(); while (i < 1000) {mouse_event (MOUSEEVENTF_LEFTDOWN |MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 ); i++;}i = 0; printf("已点完1000次,继续");} return 0;} void start(void) {printf("\n按B开始,已完成%d次\n\n",j++); while (true){if (getch() == 'b'||getch() == 'B')break; }return ;}
模仿按键精灵 找色~! 用这个 程序 用来 启动某个 游戏很好~ —————————————————— 程序是:在窗口内找到随机出现的红点并把鼠标移过去。 在程序运行的瞬间请不要移动鼠标否则会破坏效果。 红点只有一个像素,要仔细看。 —————————————————— # include <graphics.h> # include <conio.h> # include <time.h> int main(void) {int cx = GetSystemMetrics(SM_CXFIXEDFRAME); int cy = GetSystemMetrics(SM_CYFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION); initgraph(640,480); HWND hwnd = GetHWnd(); DWORD* p = GetImageBuffer(); POINT point;srand( (unsigned)time( NULL ) ); putpixel(rand() % 640, rand() % 480 ,RED); RECT rect;for(int i = 0; i < 640 * 480; i++) if (p[i] == BGR(RED) ) {point.y = i / (640 * 1.0); point.x = i - point.y * 640 ; GetWindowRect(hwnd,&rect); SetCursorPos(cx + rect.left + point.x, cy + rect.top + point.y); } getch(); return 0;} 可以多运行几次试试效果。
一个 300个小球 弹动 屏保~~ ~~~~~~~~按ESC可退出程序~~~~~~~~ # include <graphics.h> # include <conio.h> # include <time.h> # include <math.h> int Quit(void); int huadian(float * ,float * , int * , int *); int main(void) { float box[2][300]; int a[300]={0}; int b[300]={0}; initgraph(640,480); srand((unsigned)time(NULL)); for(int i=0; i<300; i++) box[0][i] = 10 + ((rand() % 31 + 1) - 1) * 20 ; for(int j=0; j<300; j++) box[1][j] = 10 + ((rand() % 23 + 1) - 1) * 20 ; while(true) {for(int l=0; l<300 ; l++) huadian(&box[0][l], &box[1][l], &a[l], &b[l]); Quit();}return 0;} int Quit(void) {if(kbhit()) if(27 == getch()) {HWND wnd = GetHWnd(); if(MessageBox(wnd, "你确定要退出吗?","提示", MB_YESNO) == IDYES) exit(0);}return 0;} int huadian(float * x, float * y, int * a,int * b) {setfillcolor(BLACK); solidcircle(*x,*y,10); *x = *x + 3 * pow((-1),(*a)) ; *y = *y + 3 * pow((-1),(*b)) ; if(*y >= 470) {*b = 1;} if(*x >= 630) {*a = 1;} if(*y <= 10) {*b = 0;} if(*x <= 10) {*a = 0;} setfillcolor(GREEN); solidcircle(*x,*y,10); return 0;}
无聊的,来看看这个加速球,速度很快时会有很多奇怪事发生。。… ———比较喜欢这一类——— # include <stdio.h> # include <graphics.h> # include <conio.h> # include <math.h> int main(void) {initgraph(640,480); float a = 0,c=20; int x, y; char b;char z[30]="按任意键可加速,按ESC退出"; setwritemode(R2_XORPEN); BeginBatchDraw(); setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 5); setcolor(GREEN); outtextxy(430,3,z); while(1) {setcolor(GREEN); x = 320 + 100 * cos( a / 300 ); y = 240 + 100 * sin( a / 300 ); line(320,240,x,y);setcolor(BLACK); x = 320 + 100 * cos( a / 300 ); y = 240 + 100 * sin( a / 300 ); line(320,240,x,y);setcolor(RED); x = 320 + 200 * cos( a / 300 ); y = 240 + 200 * sin( a / 300 ); line(320,240,x,y);FlushBatchDraw(); setcolor(BLACK); x = 320 + 200 * cos( a / 300 ); y = 240 + 200 * sin( a / 300 ); line(320,240,x,y); a=a+c; if(kbhit()) {c+=62.141592; if((b = getch())==27)return 0; }}}
点灯游戏,核心代码、精简。 ~献给初学者一点启发~ #include<graphics.h> #include<conio.h> void main() { int i,j;char a; MOUSEMSG m; initgraph(640,480); setwritemode(R2_XORPEN);//设置XOR 绘图模式 HRGN rgn =CreateRectRgn(240, 160, 401, 321);//裁剪区 setcliprgn(rgn);//裁剪 for(i=0;i<=160;i+=40) for(j=0;j<=160;j+=40) {setcolor(GREEN); line(240,160+j,400,160+j); line(240+i,160,240+i,320);}//画格子 while(1) { m=GetMouseMsg(); if(m.uMsg==WM_LBUTTONDOWN) {setfillcolor(RED); floodfill(m.x,m.y,GREEN); floodfill(m.x+40,m.y,GREEN); floodfill(m.x-40,m.y,GREEN); floodfill(m.x,m.y+40,GREEN); floodfill(m.x,m.y-40,GREEN);}//涂十字 if(kbhit()) if((a=getch())==27) return;//退出 } }
花了3小时,编了一个非常简单的贪吃蛇。 在暑假以前都玩别人的游戏于是自学了6天的c语言和easyx,自己做了第一个小贪吃蛇游戏。
1
下一页