(二)MFC学习之贴图

(二)MFC学习之贴图

环境:win10+vs2017+mfc

涉及到的内容:

1,位图的加载

CBitmap * m_Bitmap=new CBitmap;

m_BitMAP->m_hObject=LoadImage(NULL,"**.BMP",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

2,位图的运算

CClientDc dc(this);

dc.BitBlt(dc.BitBlt(x, 300, 63,154, m_Dc,63,0, SRCAND);//颜色按位与

***SRCPAINT;//颜色按位或

***SRCCOPY;//颜色覆盖

用到的类:

最基本肯定是少不了CMyApp和CMyWnd(上一篇博客已经说到)

其余的则是与位图操作相关,绘图相关的

主要是CDC和CBitmap

CDC:

MSDN说明:

The CDC object provides member functions for working with a device context, such as a display or printer, as well as members for working with a display context associated with the client area of a window.

大意是说CDC提供成员函数处理设备环境,比如显示和打印,也是处理窗口的客户区域显示,这里贴图主要是使用到后者,对客户区域的显示

CBitmap:大意是说,构建与位图相关联的对象,相当于java中的File对象,构建操作文件的对象

To use a CBitmap object, construct the object, attach a bitmap handle to it with one of the initialization member functions, and then call the object's member functions.

代码实现:

#include

class CMyWnd :public CFrameWnd {

private:

CDC * mdc;

CBitmap *mbmp,*mbmpBack;

public:

相关推荐