Exemplo n.º 1
0
int main()
{

	//hwnd - дескриптор окна, в котором будем рисовать
	HWND hwnd = GetConsoleWindow();//получение консольного окна
								   //hdc - дескриптор контекста устройства
	HDC hdc = GetDC(hwnd); //получаем дискриптор,свзянный с окном, в котором будем рисовать

	if (hdc) {
		int width = 800, height = 500;
		int n = Paint(hdc, width, height);//вызываем функцию рисования звезд
		double count = Rate(n, width, height);// количество звезд
		PText(hdc, count);
		ReleaseDC(hwnd, hdc); //освобождаем контекст
	}

	_getch();
	return 0;
}
Exemplo n.º 2
0
int Paint(HDC &hdc, int width, int height) {

	int x[BN], y[BN];
	bool stop = false;
	int n = 0;
	while (stop == false) {

		if (GetAsyncKeyState(VK_ESCAPE)) {
			_getch();
			stop = true;
		}

		// Cоздаем контекст
		HDC hmemDC = CreateCompatibleDC(hdc);
		// Cоздаем битмап
		HBITMAP hbmpTarget = CreateCompatibleBitmap(hdc, width, height);
		// Выбираем битмап в контекст
		::SelectObject(hmemDC, hbmpTarget);
		//Записывает наш bmb в память
		BitBlt(hmemDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY);

		for (int i = 0; i<BN; i++) {
			x[i] = rand() % width;
			y[i] = rand() % height;

			if (GetPixel(hmemDC, x[i], y[i]) == RGB(0, 0, 0)) {
				SetPixel(hdc, x[i], y[i], RGB(randColor(), randColor(), randColor()));
				n++;
			}
			else {
				SetPixel(hdc, x[i], y[i], RGB(0, 0, 0));
				n--;
			}
		}

		PText(hdc, Rate(n, width, height));
		DeleteDC(hmemDC); // контекст отжирает уйму ресурсов, поэтому не забудем его грохнуть
		DeleteObject(hbmpTarget);
		hmemDC = NULL;
		Sleep(12);
	}
	return n;
};
Exemplo n.º 3
0
void qtext_( float *x , float *y , char *s )

{
	PText( *x , *y , s );
}