Win32 控制台绘图2

之前已经了解在控制台可以调用Win32 api绘图;下面继续加深一下此概念;

#include  
#include  
#include 
 
HWND WINAPI GetConsoleWindow();
 
int main(int argc, char *argv[])
{
 
    HWND hwnd; 
    HDC hdc; 
    HPEN hpen;
	int dist;
 
    hwnd = GetConsoleWindow(); 
    hdc = GetDC(hwnd); 
    system("color A3"); 
    system("cls"); 

    hpen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0)); 
    SelectObject(hdc, hpen); 

    MoveToEx(hdc, 350, 20, NULL); 
    LineTo(hdc, 650, 20); 

	Rectangle(hdc, 100, 150, 200, 250);
	RoundRect(hdc, 100, 300, 400, 400, 30, 30);

	scanf("%d", &dist);
    MoveToEx(hdc, 350, 20+dist, NULL); 
    LineTo(hdc, 650, 20+dist);

    DeleteObject(hpen); 
    ReleaseDC(hwnd, hdc); 
    getchar();
 
    return 0; 
}

Win32 控制台绘图2_第1张图片

Rectangle(hdc, 100, 150, 200, 250);    绘制矩形;
RoundRect(hdc, 100, 300, 400, 400, 30, 30);     绘制圆角矩形,最后2个参数是圆角度;

获取的是整个控制台窗口的DC;

绘了图以后控制台光标还是有;也可以接收输入;

先是绘了一条直线;

接收一个数值之后,根据此数值绘制一条平行线;

你可能感兴趣的:(VC++,图形学和3D,控制台,Rectangle,RoundRect)