内容如题!谢谢
解决方案 »
- MFC 求助
- 计算网站主页的TTFB,TTLB值
- C++程序编译时的问题
- 请问怎样在任务栏显示子对话框窗口
- 连接数据里用(local)不出错,可改成127.0.0.1就出错了.说拒绝连接,是否是某个协议没有安
- 给appwizard的默认文件对话框添加能够打开的文件格式
- 如何学习网络编程?
- =======VC++,我终于入门拉,散分拉=======
- 请教一个win xp sp3 vc 里开启多核的方法
- 急急急,有谁知道 CRecordSet来写SQL语句时GROUP BY 应放在什么地方?
- 如何编程获得网页里面的内容
- 被难住了,如何使某个视成为主视或者是获得鼠标焦点,达到ActiveView效果?
1.从CView类派生一个类CBkgndView;
2.重载该类的OnPaint函数,使其加载位图;
3.在你的主窗口类加入一个CBkgndView类的成员变量 m_wndClient;
4.重载主窗口的OnCreateClient;加入 m_wndClient.SubClassWindow(m_hWndMDIClient)。
{
if (!m_bitmap.m_hObject)
return CFormView::OnEraseBkgnd(pDC);
CFormView::OnEraseBkgnd(pDC);
CRect rc;
GetClientRect (rc);
CDC dcImage;
dcImage.CreateCompatibleDC (pDC);
CBitmap *pOldBitmap =dcImage.SelectObject(&m_bitmap);
// Get bitmap width and height
BITMAP bm;
m_bitmap.GetBitmap( &bm );
// Use the minimum width and height
int width = min (bm.bmWidth, rc.Width());
int height = min (bm.bmHeight, rc.Height());
// Draw the bitmap as the window background
pDC->BitBlt (rc.Width()-width,0,width,height, &dcImage, 0, 0, SRCCOPY);
// Release
dcImage.SelectObject (pOldBitmap);
dcImage.DeleteDC ();
return true;
}
这是我搜索到的帖子。
void CTickDrawDoc::OnSelectBackpicture()
{
// TODO: Add your command handler code here
static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE,"bmp",m_systemfilename,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
if (dlg.DoModal() == IDOK)
{
m_systemfilename = dlg.GetFileName();
m_bSystem = TRUE;
UpdateAllViews(NULL);
}
}
视图的ONdraw函数
void CTickDrawView::OnDraw(CDC* pDC)
{
CTickDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CTickDrawApp *pApp = (CTickDrawApp*)AfxGetApp();
CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap=NULL; // only paint the rect that needs repainting
CRect client;
pDC->GetClipBox(client);
CRect rect = client;
DocToClient(rect);
int width, height;
width = pDoc->GetSize().cx;
height = pDoc->GetSize().cy;
if (width < rect.Width())
width = rect.Width();
if (height < rect.Height())
height = rect.Height();
if (!pDC->IsPrinting())
{ // draw to offscreen bitmap for fast looking repaints
if (dc.CreateCompatibleDC(pDC))
{ if (bitmap.CreateCompatibleBitmap(pDC, width, height))
//if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
OnPrepareDC(&dc, NULL);
pDrawDC = &dc;
// offset origin more because bitmap is just piece of the whole drawing
dc.OffsetViewportOrg(-rect.left, -rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
dc.SetBrushOrg(rect.left % 8, rect.top % 8);
// might as well clip to the same rectangle
dc.IntersectClipRect(client);
}
}
} // paint background
CBrush brush;
if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
return;
brush.UnrealizeObject();
if (!pDC->IsPrinting())
{
pDrawDC->FillRect(client, &brush);
}
DrawSystem(pDrawDC);
pDoc->Draw(pDrawDC, this);
if (pDrawDC != pDC)
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
pDrawDC, 0, 0, SRCCOPY);
if (pOldBitmap != NULL)
dc.SelectObject(pOldBitmap);
}
}
{
CBitmap bm;
bm.LoadBitmap(IDB_*****); //<-你的位图资源ID
CDC memDC;
memDC.CreateCompatibleDC(pDC);
memDC.SelectObject(&bm);
pDC->BitBlt(0,0,***,***,&memDC,0,0,SRCCOPY); //***处为<-你的位图的宽度和高度
memDC.DeleteDC();
}