|
下面是在dialog 的onPaint 中添加的加载背景图片的函数,怎么加载不上啊
void CLoadPicDlg::OnPaint()
{
if (IsIconic())
{
//CPaintDC dc(this); // device context for painting
//SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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);
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);//得到窗体的大小
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BK);//加载背景图片
BITMAP bitMap;
bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,
bitMap.bmHeight,SRCCOPY);//该函数给对话框贴上位图
////------------下面的代码给对话框添上文字
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(0, 0, 255));
CString str;
BYTE *pIP = (BYTE*)&m_dwIP;
str.Format("%d.%d.%d.%d:%d -- %s", pIP[3], pIP[2], pIP[1], pIP[0], m_dwPort, m_strName);
dc.DrawText(_T(str), &CRect(50, 50, 450, 100), DT_SINGLELINE | DT_CENTER );
}
else
{
CDialog::OnPaint();
}
} |
|