如何在MFC中插入图片?

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:22:18
有追分的

背景图像加载很简单,你只需要做以下几步即可(假设你的登陆界面对话框类名叫“CLoginDlg”):
(1)菜单“Insert”->"Resource",选择Bitmap,然后点“Import...”,选择你的背景图像,然后假设该资源ID为“IDB_BITMAP1”;
(2)在LoginDlg.h下声明一个CBitmap m_BKbitmap;
(3)在LoginDlg.cpp的构造函数中:m_BKbitmap.LoadBitmap(IDB_BITMAP1);
(4)在LoginDlg.cpp的OnPaint()函数中写上:
void CLoginDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
BITMAP bm;
CRect rect;
CDC dcMem;
m_BKbitmap.GetBitmap (&bm);
GetClientRect(&rect);
dcM