GDI+使用方法步骤

http://www.huizhi123.com/view/f47b57b0ac9ffa2c4913b7158b14f1f4.html

一 、在stdafx.h文件中添加头文件,命名空间,库的引用,

#include <gdiplus.h>

using namespace Gdiplus;

#pragma comment( lib, "gdiplus.lib")

 

二、在GDIPlusTest.h文件中添加全局变量

ULONG_PTR gdiplusToken;

三、在应用程序初始化时进行GDI+的初始化

BOOL CGDIPlusTestApp::InitInstance()

{

……

GdiplusStartupInput gdiplusStartupInput;

GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,NULL);

 

……

return FALSE;

}

 

四、重写ExitInstance虚函数

//也可以写在InitInstance()的else if (nResponse == IDCANCEL)里面

int CGDIPlusTestApp::ExitInstance(void)

{

GdiplusShutdown(gdiplusToken);

return CWinApp::ExitInstance();

}

五、添加添加Picture控件

Type设为Owner Draw

六、添加图片加载函数

void ***()

{

Graphics graphics(GetDlgItem(IDC_PIC)->GetWindowDC()->m_hDC);

wchar_t sPicName[256];

char sChar[256]=".\\res\\ico_star.ico";

mbstowcs(sPicName,sChar,sizeof(sPicName)-1);

Image image(sPicName, TRUE);

graphics.DrawImage(&image,0,0,200,200);

}

posted @ 2017-03-25 21:00  $JackChen  阅读(470)  评论(0编辑  收藏  举报