c++整蛊程序--无限弹窗

一、完成版简介     

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

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

二、基本代码

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

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

三、应用

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

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

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

#include<Windows.h>
using namespace std;
int main()
{
    HWND hDesktop = GetDesktopWindow();//获取桌面句柄
    HDC hdc = GetWindowDC(hDesktop);//获取桌面hdc
    int x = GetSystemMetrics(SM_CXSCREEN);//获取屏幕边界x
    int y = GetSystemMetrics(SM_CYSCREEN);//获取屏幕边界y
    while(1)
    {
        for ( int tx = 0 ; tx < x ; tx++ )
        {
            for ( int ty = 0 ; ty < y ; ty++ ) 
			    DrawIcon(hdc, tx,  ty, LoadIcon(NULL, IDI_WARNING));
        }
    }
    return 0;
} 

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

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

然后在DrawIcon中调用

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

调用一下MEMZ的随机函数

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

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

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

四、最终成果

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

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

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

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

函数内容则如下

//绘制错误图标
void PlayloadIcon(int position,int fen)
{       
position--;
int tmpp=position%fen;
int startx = x/fen*tmpp;
int endx = startx + x/fen;
tmpp=(position-tmpp)/fen;
int starty = y/fen*tmpp;
int endy = starty + y/fen;
//反向康托展开,取出编号对应的开始与结束x,y坐标

	for(int d=7;d<=20;d+=5)
	{
		int d2=random()%(d-5)+5;//随机产生每块的图标内距
			for(int tx=startx;tx<endx;tx+=d2)
			{
				for(int ty=starty;ty<endy;ty+=d2) 
				    DrawIcon(hdc, tx,  ty, LoadIcon(hShell32,MAKEINTRESOURCE(random()%28+100)));
			 }	      
		
	}
}

全部源码如下,拿去

#include <Windows.h>
#include<iostream>
using namespace std;//使用标准名字空间
HCRYPTPROV prov;
HINSTANCE hShell32 = LoadLibrary("1.dll");
//生成随机数
int random() 
{    
if (prov == NULL) if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) ExitProcess(1);
    int out;
	CryptGenRandom(prov, sizeof(out), (BYTE *)(&out));
    return out & 0x7fffffff;
}
    int x=GetSystemMetrics(SM_CXSCREEN);//获取屏幕边界x
    int y=GetSystemMetrics(SM_CYSCREEN);//获取屏幕边界y
	HWND hDesktop = GetDesktopWindow();    //获取窗口句柄  
  	HDC hdc = GetWindowDC(hDesktop);    //获取窗口dc  
//绘制错误图标
void PlayloadIcon(int position,int fen)
{       
position--;
int tmpp=position%fen;
int startx = x/fen*tmpp;
int endx = startx + x/fen;
tmpp=(position-tmpp)/fen;
int starty = y/fen*tmpp;
int endy = starty + y/fen;
//反向康托展开,取出编号对应的开始与结束x,y坐标

	for(int d=7;d<=20;d+=5)
	{
		int d2=random()%(d-5)+5;//随机产生每块的图标内距
			for(int tx=startx;tx<endx;tx+=d2)
			{
				for(int ty=starty;ty<endy;ty+=d2) 
				    DrawIcon(hdc, tx,  ty, LoadIcon(hShell32,MAKEINTRESOURCE(random()%28+100)));
			 }	      
		
	}
}
int main()
{
	ShowWindow(GetForegroundWindow(),0);//获取最前端窗口的句柄,然后通过ShowWindow隐藏 
	int hasb[130];//存储各自分块是否已经弹出图标过
    int fen;//存储分块数量(平方)
    while(1)
    {
     	fen=random()%10+2;//随机分成1至121块
 	    memset(hasb, 0, sizeof(hasb));//重置记录
 	    for(int thnum=1;thnum<fen*fen;)//遍历分块次
 	    {
 		    int position=random()%(fen*fen)+1;//每次随机选择一个未被弹出的分块
 		    if(hasb[position] == 0) 
		     {
		 	    hasb[position] = 1;
 			    PlayloadIcon(position,fen);//把分块编号发给函数
 			    thnum++;
		     }
	     }
    }
    return 0;
}

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

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lmx20xx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值