实现功能
1.实现点,线,矩形,三角形,圆形画法;
2.可以对图形的形状进行调整,主要通过其在运行窗口上的坐标来实现;
3.纯虚函数进行实现不同图形的同一接口;
代码实现
graphics.h
#pragma once
#ifdef DLL_IMPLEMENT
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
#include<Windows.h>
/*函数功能:获得控制台窗口句柄*/
HWND DLL_API getConsoleHwnd(void);
/*函数功能:在窗口上用创建的hpen画笔以(cx,cy)为圆心,r为半径画圆*/
void DLL_API circle(HDC, HPEN hpen,int cx, int cy, int r);
/*函数功能:在窗口上用创建的画刷画坐标为(lx,ly)点*/
void DLL_API point(HDC, HBRUSH hbrush,int lx, int ly);
/*函数功能:在窗口上用创建的画笔画出以(sx,sy)作为起点,(ex,ey)作为终点的一条直线*/
void DLL_API line(HDC hdc, HPEN hpen, int sx, int sy, int ex, int ey);
/*函数功能:在窗口上用创建的画笔画出以(left,top)为左上角坐标,(right,bottom)为右下角坐标的矩形*/
void DLL_API rect(HDC hdc, HPEN hpen, int left, int top, int right, int bottom);
graphics.cpp
//#define DLL_IMPLEMENT
#include"Graphics.h"
#define MY_BUFSIZE 100
HWND getConsoleHwnd(void)
{
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated