// 文件:popup.cpp // 编译(任选其一): // VC++: cl popup.cpp shell32.lib // MinGW: g++ popup.cpp -lshell32 -O2 -s #include <windows.h> #include <stdlib.h> #include <time.h>
// 随机整数 [0, n) static int irand(int n) { return rand() % n; }
// 打开一个网页(ANSI 接口,兼容旧编译器) static void popup_one(const char* url) { int sx = GetSystemMetrics(SM_CXSCREEN); int sy = GetSystemMetrics(SM_CYSCREEN); int x = irand(sx - 800); // 预留窗口宽度 int y = irand(sy - 600); // 预留窗口高度 SetCursorPos(x, y); // 光标落到目标位置(可选) ShellExecuteA(NULL, “open”, url, NULL, NULL, SW_SHOW); Sleep(irand(50) + 20); // 20~70ms,降低系统压力 }
int main() { srand((unsigned)time(NULL)); // 初始化随机种子 const char* url = “https://www.example.com/”; // <<< 在此修改目标网址
for (int i = 0; i < 300; ++i) {
popup_one(url);
}
// 可选:完成提示(可能被大量窗口覆盖)
MessageBoxA(NULL, "已完成 300 次弹窗。", "提示", MB_OK | MB_ICONINFORMATION);
return 0;
}