控制台用GDI画图出了点问题

xspace_time 2012-10-02 04:15:53
#include <windows.h>
#include <gdiplus.h>

using namespace Gdiplus;
#pragma comment(lib,"gdiplus.lib")
extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow();
int main()
{

GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;

// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

HWND hwnd=GetConsoleWindow();
HDC hdc=GetDC(hwnd);
Graphics graphics(hdc);
// Put the points of a polygon in an array.
Point points[] = {Point(75, 0), Point(100, 50),
Point(150, 50), Point(112, 75),
Point(150, 150), Point(75, 100),
Point(0, 150), Point(37, 75),
Point(0, 50), Point(50, 50)};

// Use the array of points to construct a path.
GraphicsPath path;
path.AddLines(points, 10);

// Use the path to construct a path gradient brush.
PathGradientBrush pthGrBrush(&path);

// Set the color at the center of the path to red.
pthGrBrush.SetCenterColor(Color(255, 255, 0, 0));

// Set the colors of the points in the array.
Color colors[] = {Color(255, 0, 0, 0), Color(255, 0, 255, 0),
Color(255, 0, 0, 255), Color(255, 255, 255, 255),
Color(255, 0, 0, 0), Color(255, 0, 255, 0),
Color(255, 0, 0, 255), Color(255, 255, 255, 255),
Color(255, 0, 0, 0), Color(255, 0, 255, 0)};

int count = 10;
pthGrBrush.SetSurroundColors(colors, &count);

// Fill the path with the path gradient brush.
graphics.FillPath(&pthGrBrush, &path);
pthGrBrush.SetGammaCorrection(TRUE);
graphics.TranslateTransform(200.0f, 0.0f);
graphics.FillPath(&pthGrBrush, &path);

GdiplusShutdown(gdiplusToken);

return 0;
}

vc6.0 单步跟踪显示在return 0处有问题 但找不到原因

...全文
227 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
蛋的猥琐人生 2012-10-03
  • 打赏
  • 举报
回复
con是控制台的缩写,io是输入、输出的缩写。
故,这个库函数是进行输入、输出的。
xspace_time 2012-10-03
  • 打赏
  • 举报
回复
放在函数里就没有问题 这个问题应该不难 但是自己不知道什么时候才想明白 希望高手来解答一下

#include<windows.h>
#include<gdiplus.h>
#include<conio.h>

using namespace Gdiplus;
#pragma comment(lib,"gdiplus.lib")
extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow();
void draw_start(HDC hdc);
int main()
{
HWND hwnd=GetConsoleWindow();
HDC hdc=GetDC(hwnd);

GdiplusStartupInput gdiplusStartupInput;
GdiplusStartupOutput gdiplusStartupOutput;
ULONG_PTR gdiplusToken;

// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, &gdiplusStartupOutput);
//GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
draw_start(hdc);
GdiplusShutdown(gdiplusToken);
ReleaseDC(hwnd,hdc);
//getch();
return 0;
}
void draw_start(HDC hdc)
{
Graphics graphics(hdc);
// Put the points of a polygon in an array.
Point points[] = {Point(75, 0), Point(100, 50),
Point(150, 50), Point(112, 75),
Point(150, 150), Point(75, 100),
Point(0, 150), Point(37, 75),
Point(0, 50), Point(50, 50)};

// Use the array of points to construct a path.
GraphicsPath path;
path.AddLines(points, 10);

// Use the path to construct a path gradient brush.
PathGradientBrush pthGrBrush(&path);

// Set the color at the center of the path to red.
pthGrBrush.SetCenterColor(Color(255, 255, 0, 0));

// Set the colors of the points in the array.
Color colors[] = {Color(255, 0, 0, 0), Color(255, 0, 255, 0),
Color(255, 0, 0, 255), Color(255, 255, 255, 255),
Color(255, 0, 0, 0), Color(255, 0, 255, 0),
Color(255, 0, 0, 255), Color(255, 255, 255, 255),
Color(255, 0, 0, 0), Color(255, 0, 255, 0)};

int count = 10;
pthGrBrush.SetSurroundColors(colors, &count);

// Fill the path with the path gradient brush.
graphics.FillPath(&pthGrBrush, &path);
pthGrBrush.SetGammaCorrection(TRUE);
graphics.TranslateTransform(200.0f, 0.0f);
graphics.FillPath(&pthGrBrush, &path);
return;
}
xspace_time 2012-10-03
  • 打赏
  • 举报
回复
有没人试一下 看下出什么问题了
xspace_time 2012-10-02
  • 打赏
  • 举报
回复
gdi中间那一块 全部去掉没问题 只留points[]数组有一个问题 再留path有两个问题 怀疑是不是gdi和main函数重复销毁数组所致
大熊猫侯佩 2012-10-02
  • 打赏
  • 举报
回复
不一定,看api文档,这个函数在什么情况下使用的
xspace_time 2012-10-02
  • 打赏
  • 举报
回复
注释掉 GdiplusShutdown(gdiplusToken);这一句就没有问题了 但是为什么呢
而且GDI有开始有关闭 不应该注释吧
大熊猫侯佩 2012-10-02
  • 打赏
  • 举报
回复
不会是return 0的问题吧?还是上面的问题。

你保证以上没有个gdi+ api 返回都成功吗?

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧