C/C++屏幕恶搞程序

运行结果如下图:


原理:

第一步 禁止更新屏幕
第二步 用GetDCEx获取屏幕HDC,把他放进位图
第三步 算出屏幕分辨率,把截图的结果大小/10重新显示
第四步 把获取的图形显示并随机分配位置

第五步 重新开始,进行32767次循环!

#include <windows.h>

#define NUM 32767

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	PSTR szCmdLine, int iCmdShow)
{
	static int iKeep[NUM][4];
	HDC        hdcScr, hdcMem;
	int        cx, cy;
	HBITMAP    hBitmap;
	HWND       hwnd;
	int        i, j, x1, y1, x2, y2;

	if (LockWindowUpdate(hwnd = GetDesktopWindow()))
	{
		hdcScr = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);
		hdcMem = CreateCompatibleDC(hdcScr);
		cx = GetSystemMetrics(SM_CXSCREEN) / 10;
		cy = GetSystemMetrics(SM_CYSCREEN) / 10;
		hBitmap = CreateCompatibleBitmap(hdcScr, cx, cy);

		SelectObject(hdcMem, hBitmap);

		srand((int)GetCurrentTime());

		for (i = 0; i < 2; i++)
		for (j = 0; j < NUM; j++)
		{
			LockWindowUpdate(hwnd = GetDesktopWindow());
			if (i == 0)
			{
				iKeep[j][0] = x1 = cx * (rand() % 10);
				iKeep[j][1] = y1 = cy * (rand() % 10);
				iKeep[j][2] = x2 = cx * (rand() % 10);
				iKeep[j][3] = y2 = cy * (rand() % 10);
			}
			else
			{
				x1 = iKeep[NUM - 1 - j][0];
				y1 = iKeep[NUM - 1 - j][1];
				x2 = iKeep[NUM - 1 - j][2];
				y2 = iKeep[NUM - 1 - j][3];
			}
			BitBlt(hdcMem, 0, 0, cx, cy, hdcScr, x1, y1, SRCCOPY);
			BitBlt(hdcScr, x1, y1, cx, cy, hdcScr, x2, y2, SRCCOPY);
			BitBlt(hdcScr, x2, y2, cx, cy, hdcMem, 0, 0, SRCCOPY);
		}

		DeleteDC(hdcMem);
		ReleaseDC(hwnd, hdcScr);
		DeleteObject(hBitmap);
	}
	return 0;
}

©️2020 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值