Движение окружности

Модераторы: Hawk, Romeo, Absurd, DeeJayC, WinMain

Ответить
vadim_77
Сообщения: 3
Зарегистрирован: 01 авг 2017, 15:17

01 авг 2017, 15:40

Здравствуйте. Когда использую координаты мышки у меня получается рисование а движение только в верхнем левом углу в квадрате. А как мне сделать так чтобы было движение и как мне убрать квадрат в левом верхнем углу?

#include <windows.h>
#include <iostream>

int InputInteger(const char * str, int min, int max) {
int x;
std::cout << str;
bool ErrorFlag;
do {
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cin >> x;
ErrorFlag = !std::cin.good() || x< min || x>max;
if (ErrorFlag) {
std::cout << "Error. " << str;
}
} while (ErrorFlag);
std::cin.ignore(std::cin.rdbuf()->in_avail());
return x;
}

HWND GetConsoleHwnd(void) {
#define MY_BUFSIZE 1024
HWND hwndFound;
char pszNewWindowTitle[MY_BUFSIZE];
char pszOldWindowTitle[MY_BUFSIZE];
GetConsoleTitle(LPWSTR(pszOldWindowTitle), MY_BUFSIZE);
wsprintf(LPWSTR(pszNewWindowTitle), LPCWSTR("%d/%d"),
GetTickCount(),
GetCurrentProcessId());
SetConsoleTitle(LPCWSTR(pszNewWindowTitle));
Sleep(1);
hwndFound = FindWindow(NULL, LPCWSTR(pszNewWindowTitle));
SetConsoleTitle(LPCWSTR(pszOldWindowTitle));
return(hwndFound);
}

int main() {
RECT o;
POINT p;
HWND wh = GetConsoleHwnd();
/* COORD c = { 50,10 }; */

HWND hWnd = GetConsoleWindow();
HDC hDC = GetDC(hWnd);
RECT temp;
GetClientRect(hWnd, &temp);
HDC hBufferDC = CreateCompatibleDC(hDC);
HBITMAP hBufferBmp = CreateBitmap(temp.right, temp.bottom, 1, 32, NULL);
HBITMAP hBufferBmpOld = (HBITMAP)SelectObject(hBufferDC, hBufferBmp);
FillRect(hBufferDC, &temp, (HBRUSH)GetStockObject(WHITE_BRUSH));
std::cout << "Enter color:\n";
int r, g, b;
r = InputInteger("Enter R value[0,255]:", 0, 255);
g = InputInteger("Enter G value[0,255]:", 0, 255);
b = InputInteger("Enter B value[0,255]:", 0, 255);
system("cls");
HBRUSH hBrush = CreateSolidBrush(RGB(r, g, b));
HPEN hPen = CreatePen(PS_SOLID, 1, RGB(r, g, b));
HBRUSH hOldBrush = (HBRUSH)SelectObject(hBufferDC, hBrush);
HPEN hOldPen = (HPEN)SelectObject(hBufferDC, hPen);
RECT circle = { 0, 0, 100, 100 };
size_t step_h = 1, step_v = 1;
while (!GetAsyncKeyState(VK_ESCAPE)) {

GetWindowRect(wh, &o);
GetCursorPos(&p);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), { 0,0 });

FillRect(hBufferDC, &circle, (HBRUSH)GetStockObject(WHITE_BRUSH));
/* if (GetAsyncKeyState(VK_LEFT)) {
circle.left -= step_h;
circle.right -= step_h;
}
if (GetAsyncKeyState(VK_RIGHT)) {
circle.left += step_h;
circle.right += step_h;
}
if (GetAsyncKeyState(VK_DOWN)) {
circle.top += step_v;
circle.bottom += step_v;
}
if (GetAsyncKeyState(VK_UP)) {
circle.top -= step_v;
circle.bottom -= step_v;
} */

Ellipse(hBufferDC, p.x, p.y, p.x + 50, p.y + 50);
/* Ellipse(hBufferDC, circle.left, circle.top, circle.right, circle.bottom); */
BitBlt(hDC, 0, 0, temp.right, temp.bottom, hBufferDC, 0, 0, SRCCOPY);
/* std::cout << circle.left << ":" << circle.top << ":" << circle.right << ":" << circle.bottom << std::endl; */
std::cout << p.x << ":" << p.y << ":" << p.x + 50 << ":" << p.y + 50 << std::endl;
Sleep(10);
}
SelectObject(hBufferDC, hOldBrush);
SelectObject(hBufferDC, hOldPen);
SelectObject(hBufferDC, hBufferBmpOld);
DeleteObject(hBrush);
DeleteObject(hPen);
DeleteObject(hBufferBmp);
DeleteDC(hBufferDC);
ReleaseDC(hWnd, hDC);
return 0;
}

Изображение
Ответить