69,369
社区成员
发帖
与我相关
我的任务
分享
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <time.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
extern "C" HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void ShowTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
int main() {
HWND hwnd;
HDC hdc;
RECT r;
COLORREF c;
int i,v;
int x[20];
int y[20];
srand(time(NULL));
system("color 07");
system("cls");
HideTheCursor();
hwnd = GetConsoleWindow();
hdc = GetDC(hwnd);
GetClientRect(hwnd,&r);
for (i=0;i<20;i++) {
x[i]=rand()%r.right;
y[i]=rand()%r.bottom;
}
while (1) {
for (i=0;i<20;i++) {
v=40+20*(rand()%11);
c=(COLORREF)(v<<16|v<<8|v);
SetPixel(hdc,x[i],y[i],c);
}
Sleep(100+rand()%200);
if (kbhit()) {getch();break;}
}
ReleaseDC(hwnd,hdc);
system("color 07");
system("cls");
ShowTheCursor();
return 0;
}