MFC picture control

The picture control can display pictures, and its essence is the CStatic class. It only needs to make the style SS_BITMAP in dwStyle when it is created.

The first step: define in the dialog box class:

CStatic m_picture;

Step 2: In the OnInitDialog function of the dialog box class:

m_picture.Create(L"XX",WS_CHILD|WS_VISIBLE|WS_BORDER|SS_BITMAP,
CRect(100,100,300,300),this,10000);//创建该图片控件
//参数1:随便写,不会显示的
//参数2:dwStyle制定样式SS_BITMAP
//参数3:图片显示区域 左上角坐标(100,100)  右下角(300,300)
//参数4:父窗口,this是指该对话框窗口

Step 3: Add a bitmap resource

Step 4: Load the bitmap for the image control

HBITMAP hBmp=LoadBitmap(AfxGetInstanceHandle(),//实例句柄
MAKEINTRESOURCE(IDB_BITMAP1_ONE));//通过资源加载位图
m_picture.SetBitmap(hBmp);

If the picture is too large, it cannot be displayed completely, you can use DC drawing to achieve the zoom of the picture.

Guess you like

Origin blog.csdn.net/qq_41363459/article/details/113873867