您的位置:首页 > 其它

MFC如何使用GDI+,button加载png

2014-05-09 10:11 375 查看
文章出处:http://blog.sina.com.cn/s/blog_5d3402010100nnep.html

参照下面3篇文章就能完成想要的功能。

1,Starting with GDI+
http://www.codeproject.com/KB/GDI-plus/startinggdiplus.aspx

2,Loading JPG & PNG resources using GDI+
http://www.codeproject.com/KB/GDI-plus/cgdiplusbitmap.aspx

3,A user draw button that supports PNG files with transparency, for Visual C++ 6.0 and VS2005
http://www.codeproject.com/KB/buttons/GdipButton.aspx

前两篇主要是添加对应代码来启动GDI+,因为我想要的功能是第三个中才有的,但是他使用了前两篇中的.CPP和.H,所以必须遵循前两篇的规则来加代码。

其实上述文章并不难看懂(连我这个四级都没过的人都能看懂),耐心点看就好了。

其实第一篇和第二篇要加的地方是一样的,但是要完成的demo有区别罢了。
就按第二篇来配置
对于第二篇中说要添加的地方:

GDI+ needs to be initialized before any GDI+ calls are made. I suggest adding the following data member to the class derived from
CWinApp
:
而不是CTest00Dlg中
而是在Test00.h中
class CTest00App : public CWinApp
{
public:
CTest00App();
ULONG_PTR m_gdiplusToken;////******** here

...............

}


Test00.cpp中
BOOL CTest00App::InitInstance()
{
AfxEnableControlContainer();

Gdiplus::GdiplusStartupInput gdiplusStartupInput;////******** here
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);////******** here

................

}


重载这个的时候,因为看到头晕了,所以用向导找到对应添加的地方,就手动添加的 - =;
int CTest00App::ExitInstance()
{
Gdiplus::GdiplusShutdown(m_gdiplusToken);

return CWinApp::ExitInstance();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: