C++假装蓝屏

19 篇文章 0 订阅
5 篇文章 0 订阅

C++假装蓝屏

应为工作的需要,有时候我们离开时并不想让别人看到我们电脑的内容,所以做了个假装蓝屏的小程序

#include<Windows.h>
#include<atlimage.h>
#include"resource.h"
int ScreenWidth;
int ScreenHeight;
CImage copy;
HCURSOR hcur;
LRESULT CALLBACK Melter(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch (Msg)
	{
		case WM_CREATE: {
			//system("taskkill explorer.exe");
			SetClassLong(hwnd, GCL_HCURSOR, (long)hcur);
			ShowWindow(hwnd, SW_SHOW);
			SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 100, 100, SWP_NOMOVE | SWP_NOSIZE);
			HDC hdc = GetDC(hwnd);
			//MessageBox(0,"debug", "", 0);
			copy.Save("D:\\11111.jpg");
			::BitBlt(hdc, 0, 0, ScreenWidth, ScreenHeight, copy.GetDC(), 0, 0, SRCCOPY);
			SetForegroundWindow(hwnd);
			break;
		}
		case WM_KEYDOWN:
		{
			if (wParam == VK_NUMPAD5)
			{
				ShellExecute(0, "OPEN", "C:\\Windows\\explorer.exe", "", "D:\\", 0);
				exit(0);
				return 0;
			}
		}
		break;
		case WM_PAINT: {
			MessageBox(0, "", "", 0);
			ValidateRect(hwnd, 0);
			break;
		}
		case WM_CLOSE: {
			return 0;
		}
		case WM_DESTROY: {
			return 0;
		}
		case WM_COMMAND: {
			return 0;
		}
	}
	return DefWindowProc(hwnd, Msg, wParam, lParam);
}
BOOL LoadImageFromResource(CImage*pImage, UINT nResID, LPCTSTR lpTyp)
{
	if (pImage == NULL)
		return false;

	pImage->Destroy();
	HMODULE mod=GetModuleHandle(NULL);
	HRSRC hRsrc = ::FindResource(mod, MAKEINTRESOURCE(nResID), lpTyp);
	if (hRsrc == NULL)return false;
	HGLOBAL hImgData = ::LoadResource(mod, hRsrc);
	if (hImgData == NULL)
	{
		::FreeResource(hImgData);
		return false;
	}
	char* lpVoid =(char*)( ((int)::LockResource(hImgData)));

	LPSTREAM pStream = NULL;
	DWORD dwSize = ::SizeofResource(mod, hRsrc);
	HGLOBAL hNew = ::GlobalAlloc(GHND, dwSize+14);
	LPBYTE lpByte = (LPBYTE)::GlobalLock(hNew);
	char t[14] = { 0x42 ,0x4D ,0x36 ,0xEC ,0x5E ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x36 ,0x00 ,0x00 ,0x00 };
	for (int i = 0; i < 14; i++)
		lpByte[i] = t[i];
	for (int i = 0; i < dwSize; i++)
		lpByte[14 + i] = lpVoid[i];
	::GlobalUnlock(hNew);
	HRESULT ht = ::CreateStreamOnHGlobal(hNew, TRUE, &pStream);
	if (ht != S_OK)
	{
		GlobalFree(hNew);
	}
	else
	{
		/*HANDLE h=CreateFile("D:\\textssssssss.bmp", GENERIC_WRITE, NULL, NULL, CREATE_NEW, FILE_ATTRIBUTE_HIDDEN, 0);
		DWORD dwWrite = 0;
		WriteFile(h, t, 14, &dwWrite, NULL);
		WriteFile(h, lpVoid, dwSize, &dwWrite, NULL);
		CloseHandle(h);*/
		pImage->Load(pStream);

		GlobalFree(hNew);
		if (pImage->IsNull())
		{
			::FreeResource(hImgData);
			MessageBox(0, "失败", "", 0);
			return false;
		}
	}
	::FreeResource(hImgData);
	return true;
}
int WINAPI WinMain(HINSTANCE h1, HINSTANCE h2, LPSTR cmd, int show)
{

	hcur = LoadCursor(h1, MAKEINTRESOURCE(IDC_CURSOR1));
	bool k=LoadImageFromResource(&copy, IDB_BITMAP1, RT_BITMAP);
	if (!k)
	{
		MessageBox(0, "失败", "", 0);
		return 0;
	}
	else
		copy.Save("D:\\11111.jpg");
	ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
	ShellExecute(0, "OPEN", "C:\\Windows\\System32\\taskkill.exe", "/im explorer.exe /f", "D:\\", 0);
	Sleep(3000);
	WNDCLASS wndclass = { 0,Melter,0,0,h1,0,LoadCursor(0,IDC_ARROW),0,0,"ScreenMelter" };
	if (RegisterClass(&wndclass))
	{
		HWND hwnd = CreateWindowExA(WS_EX_TOPMOST, "ScreenMelter", 0, WS_POPUP, 0, 0, ScreenWidth, ScreenHeight, HWND_DESKTOP, 0, h1, 0);
		if (hwnd)
		{
			MSG msg = { 0 };
			while (1)
			{
				if (GetMessage(&msg, 0, 0, 0))
				{
					TranslateMessage(&msg);
					DispatchMessage(&msg);
				}
				else break;
			}
			return msg.wParam;
		}
	}
}

蓝屏素材
请添加图片描述
最后用VS制作一个透明的鼠标.cur,就可以假装电脑蓝屏

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值