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

文章出处: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();
 }


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值