c/c 控制台应用程序——画三角形、圆、直线、矩形 -凯发k8官方网
凯发k8官方网
收集整理的这篇文章主要介绍了
c/c 控制台应用程序——画三角形、圆、直线、矩形
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
graphics.h
#pragma once#includegraphics.cpp
#include"graphics.h" #define my_bufsize 100 hwnd getconsolehwnd(void) { char psznewwindowtitle[my_bufsize]; // contains fabricated char pszoldwindowtitle[my_bufsize]; // contains original getconsoletitle(pszoldwindowtitle, my_bufsize); wsprintf(psznewwindowtitle,"%d/%d", gettickcount(), getcurrentprocessid()); setconsoletitle(psznewwindowtitle); sleep(40); hwnd hconsole=findwindow(null, psznewwindowtitle); setconsoletitle(pszoldwindowtitle); return hconsole; } void circle(hdc hdc, hpen hpen,int cx, int cy, int r) {selectobject(hdc, hpen);arc(hdc,cx-r,cy-r,cx r,cy r,cx-r,cy,cx r,cy);arc(hdc,cx-r,cy-r,cx r,cy r,cx r,cy,cx-r,cy); } void point(hdc hdc, hbrush hbrush,int cx, int cy) {hpen hpen = createpen(0, 5, rgb(0, 0, 0));selectobject(hdc, hpen);(hpen)selectobject(hdc,hbrush);ellipse(hdc,cx,cy,cx 50,cy 50); } void line(hdc hdc, hpen hpen, int sx, int sy, int ex, int ey) {selectobject(hdc, hpen);(hpen)selectobject(hdc,hpen);movetoex(hdc,sx,sy,null); lineto(hdc,ex,ey); } void rect(hdc hdc, hpen hpen, int left, int top, int right, int bottom) {selectobject(hdc, hpen);(hpen)selectobject(hdc,hpen);rectangle(hdc,left,top,right,bottom); }figure.h
#includelocation.cpp
#include "figure.h"location::location(int x, int y) {x_pos = x;y_pos = y; }int location::get_x() {return x_pos; }int location::get_y() {return y_pos; }point.cpp
#include "figure.h" #include"graphics.h" #includecircle.cpp
#include "figure.h" #include"graphics.h" #includerect.cpp
#include"figure.h" #include"graphics.h" rect::rect(int lx,int ly, int rx, int ry):lx(lx),ly(ly),rx(rx),ry(ry){ } void rect::show(hdc hdc){hpen hpen = createpen(0, 5, rgb(200, 256,256));hbrush hbrush = createsolidbrush(rgb(0, 0, 0)); (hpen)selectobject(hdc,hbrush);rect(hdc,hpen,lx, ly, rx, ry); }tria.cpp
#include"figure.h" #include"graphics.h" tria::tria(int lx,int ly, int rx, int ry,int tx, int ty):lx(lx),ly(ly),rx(rx),ry(ry),tx(tx),ty(ty){ } void tria::show(hdc hdc){hpen hpen = createpen(0, 5, rgb(200, 256,256));hbrush hbrush = createsolidbrush(rgb(0, 0, 0));(hpen)selectobject(hdc,hbrush);line(hdc,hpen,lx, ly, rx, ry);line(hdc,hpen,lx, ly, tx, ty);line(hdc,hpen,tx, ty, rx, ry); }
gramdemo.cpp
#include "figure.h" #include"graphics.h" #include
总结
以上是凯发k8官方网为你收集整理的c/c 控制台应用程序——画三角形、圆、直线、矩形的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: ccpc2019-湖南全国邀请赛(湘潭大