新人 长见识了 谢谢提问者 谢谢版主
程序代码:
#include <Windows.h>
#include <ctime>
#include <conio.h>
const int MaxValue(100);
const RECT Border = { 10, 10, 620, 350 };
const POINT Origin = { 20, 170 };
void CreateData(int* pData, const size_t Count);
void wmain(void)
{
int Data[50];
CreateData(Data, _countof(Data)); // 你修改Data[]的数据就可以了
HDC hDC(GetDC(GetConsoleWindow()));
HPEN hPen(CreatePen(PS_SOLID, 1, RGB(0, 255, 0)));
HBRUSH hBrush(CreateSolidBrush(RGB(0, 0, 0)));
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
Rectangle(hDC, Border.left, Border.top, Border.right, Border.bottom);
hPen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
SelectObject(hDC, hPen);
MoveToEx(hDC, Origin.x, Origin.y, NULL);
LineTo(hDC, Border.right - 10, Origin.y);
hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 0));
SelectObject(hDC, hPen);
MoveToEx(hDC, Origin.x, Origin.y - Data[0], NULL);
for (size_t i = 1; i != _countof(Data); ++i)
{
LineTo(hDC, Origin.x + i * 10, Origin.y - Data[i]);
}
_getwch();
DeleteObject(hBrush);
DeleteObject(hPen);
ReleaseDC(NULL, hDC);
}
void CreateData(int* pData, const size_t Count)
{
srand(static_cast<unsigned int>(_time32(NULL)));
rand();
for (size_t i = 0; i < Count; ++i)
{
*pData++ = static_cast<int>(MaxValue * static_cast<double>(rand()) / (RAND_MAX + 1));
}
}
这个没有使用自编的库,你可以编译的。Windows API GDI的图形库,而且是对控制台输出的,相当于TC的Graphics模式。
下面是运行效果:
请参考:https://bbs.bccn.net/thread-364436-1-1.html
[ 本帖最后由 TonyDeng 于 2012-3-27 02:16 编辑 ]












