当前位置:   article > 正文

c++整蛊程序--无限弹窗_c++无限弹窗代码

c++无限弹窗代码

 

一、完成版简介     

       打开即见效,视觉效果炸裂杀毒软件扫不出~不多废话,开始教学

最终效果视频​​​​​​

二、基本代码

        本次用到的基本代码是windows.h库中的DrawIcon()函数,直接上用法 

DrawIcon(窗口hdc, x坐标,  y坐标, LoadIcon(图标);

三、应用

在屏幕中心绘制一个警告图标

  1. #include<Windows.h>
  2. using namespace std;
  3. int main()
  4. {
  5. HWND hDesktop = GetDesktopWindow();//获取屏幕窗口句柄
  6. HDC hdc = GetWindowDC(hDesktop);//获取屏幕hdc
  7. int x = GetSystemMetrics(SM_CXSCREEN);//获取屏幕边界x
  8. int y = GetSystemMetrics(SM_CYSCREEN);//获取屏幕边界y
  9. x /= 2;
  10. y /= 2;//x,y取一半
  11. while(1) DrawIcon(hdc, x, y, LoadIcon(NULL, IDI_WARNING));
  12. //在屏幕的中心位置绘制'警告'图标
  13. return 0;
  14. }

        简单写个循环,绘制图标覆盖全桌面

  1. #include<Windows.h>
  2. using namespace std;
  3. int main()
  4. {
  5. HWND hDesktop = GetDesktopWindow();//获取桌面句柄
  6. HDC hdc = GetWindowDC(hDesktop);//获取桌面hdc
  7. int x = GetSystemMetrics(SM_CXSCREEN);//获取屏幕边界x
  8. int y = GetSystemMetrics(SM_CYSCREEN);//获取屏幕边界y
  9. while(1)
  10. {
  11. for ( int tx = 0 ; tx < x ; tx++ )
  12. {
  13. for ( int ty = 0 ; ty < y ; ty++ )
  14. DrawIcon(hdc, tx, ty, LoadIcon(NULL, IDI_WARNING));
  15. }
  16. }
  17. return 0;
  18. }

只有warning图标太单调,链接一下系统自带的图标

HINSTANCE hShell32 = LoadLibrary("1.dll");

然后在DrawIcon中调用

DrawIcon(hdc, tx,  ty, LoadIcon(hShell32,MAKEINTRESOURCE(数字));

调用一下MEMZ的随机函数

  1. #include <Windows.h>
  2. using namespace std;//使用标准名字空间
  3. HCRYPTPROV prov;//随机函数中必要的全局变量
  4. //生成随机数
  5. int random()
  6. {
  7. if (prov == NULL) if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) ExitProcess(1);
  8. int out;
  9. CryptGenRandom(prov, sizeof(out), (BYTE *)(&out));
  10. return out & 0x7fffffff;
  11. }

有了随机函数之后,只需要把DrawIcon中的LoadIcon参数改为随机自带图标即可

  1. DrawIcon(hdc, tx, ty, LoadIcon(hShell32,MAKEINTRESOURCE(random()%28+100)));
  2. //意为取100~128的随机数,似乎只有这几个图标能用

 

四、最终成果

做了这么多准备工作,最后终于可以放大招了

全屏随机分块+随机铺图标

首先把绘制图标的部分写入函数,主函数改为生成分块

  1. int main()
  2. {
  3. int hasb[130];//存储各自分块是否已经弹出图标过
  4. int fen;//存储分块数量(平方)
  5. while(1)
  6. {
  7. fen=random()%10+2;//随机分成1至121块
  8. memset(hasb, 0, sizeof(hasb));//重置记录
  9. for(int thnum=1;thnum<fen*fen;)//遍历分块次
  10. {
  11. int position=random()%(fen*fen)+1;//每次随机选择一个未被弹出的分块
  12. if(hasb[position] == 0)
  13. {
  14. hasb[position] = 1;
  15. PlayloadIcon(position,fen);//把分块编号发给函数
  16. thnum++;
  17. }
  18. }
  19. }
  20. return 0;
  21. }

函数内容则如下

  1. //绘制错误图标
  2. void PlayloadIcon(int position,int fen)
  3. {
  4. position--;
  5. int tmpp=position%fen;
  6. int startx = x/fen*tmpp;
  7. int endx = startx + x/fen;
  8. tmpp=(position-tmpp)/fen;
  9. int starty = y/fen*tmpp;
  10. int endy = starty + y/fen;
  11. //反向康托展开,取出编号对应的开始与结束x,y坐标
  12. for(int d=7;d<=20;d+=5)
  13. {
  14. int d2=random()%(d-5)+5;//随机产生每块的图标内距
  15. for(int tx=startx;tx<endx;tx+=d2)
  16. {
  17. for(int ty=starty;ty<endy;ty+=d2)
  18. DrawIcon(hdc, tx, ty, LoadIcon(hShell32,MAKEINTRESOURCE(random()%28+100)));
  19. }
  20. }
  21. }

全部源码如下,拿去

  1. #include <Windows.h>
  2. #include<iostream>
  3. using namespace std;//使用标准名字空间
  4. HCRYPTPROV prov;
  5. HINSTANCE hShell32 = LoadLibrary("1.dll");
  6. //生成随机数
  7. int random()
  8. {
  9. if (prov == NULL) if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) ExitProcess(1);
  10. int out;
  11. CryptGenRandom(prov, sizeof(out), (BYTE *)(&out));
  12. return out & 0x7fffffff;
  13. }
  14. int x=GetSystemMetrics(SM_CXSCREEN);//获取屏幕边界x
  15. int y=GetSystemMetrics(SM_CYSCREEN);//获取屏幕边界y
  16. HWND hDesktop = GetDesktopWindow(); //获取窗口句柄
  17. HDC hdc = GetWindowDC(hDesktop); //获取窗口dc
  18. //绘制错误图标
  19. void PlayloadIcon(int position,int fen)
  20. {
  21. position--;
  22. int tmpp=position%fen;
  23. int startx = x/fen*tmpp;
  24. int endx = startx + x/fen;
  25. tmpp=(position-tmpp)/fen;
  26. int starty = y/fen*tmpp;
  27. int endy = starty + y/fen;
  28. //反向康托展开,取出编号对应的开始与结束x,y坐标
  29. for(int d=7;d<=20;d+=5)
  30. {
  31. int d2=random()%(d-5)+5;//随机产生每块的图标内距
  32. for(int tx=startx;tx<endx;tx+=d2)
  33. {
  34. for(int ty=starty;ty<endy;ty+=d2)
  35. DrawIcon(hdc, tx, ty, LoadIcon(hShell32,MAKEINTRESOURCE(random()%28+100)));
  36. }
  37. }
  38. }
  39. int main()
  40. {
  41. ShowWindow(GetForegroundWindow(),0);//获取最前端窗口的句柄,然后通过ShowWindow隐藏
  42. int hasb[130];//存储各自分块是否已经弹出图标过
  43. int fen;//存储分块数量(平方)
  44. while(1)
  45. {
  46. fen=random()%10+2;//随机分成1至121块
  47. memset(hasb, 0, sizeof(hasb));//重置记录
  48. for(int thnum=1;thnum<fen*fen;)//遍历分块次
  49. {
  50. int position=random()%(fen*fen)+1;//每次随机选择一个未被弹出的分块
  51. if(hasb[position] == 0)
  52. {
  53. hasb[position] = 1;
  54. PlayloadIcon(position,fen);//把分块编号发给函数
  55. thnum++;
  56. }
  57. }
  58. }
  59. return 0;
  60. }

就可以实现开头视频中的效果,本文所有代码在win10环境下的Dev-c++通过编译

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/301094
推荐阅读
相关标签
  

闽ICP备14008679号