C++实现假装蓝屏整蛊小程序

来自:网络
时间:2023-07-24
阅读:

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;
		}
	}
}

蓝屏素材

C++实现假装蓝屏整蛊小程序

最后用VS制作一个透明的鼠标.cur,就可以假装电脑蓝屏

返回顶部
顶部