Implementation results:
This is actually a very common function, everyone will consider to their own simple project to do a background interface. In fact, just overload the OnEraseBkgnd () function in the view class.
The code is as follows:
BOOL Cdddview:: OnEraseBkgnd(CDC*PDC) {//TODO: Add the Message Handler code and/or call the default value hereCStringstring("B.bmp"); Hbitmap Hbitmap=(HBITMAP):: LoadImage(AfxGetInstanceHandle (),string, Image_bitmap,1024x768,768, lr_createdibsection|Lr_loadfromfile);//very Important:not Call the SUPER CLASS FUNCTIONCPAINTDC DC (this);if(Hbitmap==NULL)return FALSE; CBitmap bitmap; Bitmap.Attach (HBITMAP); BITMAP bmp; Bitmap.Getbitmap (&BMP); CDC MEMDC; Memdc.CreateCompatibleDC (PDC); CBitmap*Poldbitmap=Memdc.SelectObject (&Bitmap); CRect rect; GetClientRect (&RECT); Pdc -Setstretchbltmode (Coloroncolor);//This mode does not set the words can cause serious distortion of the picturePdc -STRETCHBLT (0,0, rect.Width (), rect.Height (),&MEMDC,0,0Bmp.Bmwidth,bmp.Bmheight,srccopy); Memdc.SelectObject (POLDBITMAP); Memdc.DeleteDC ();//Remove DC return TRUE; }
By the way, change the title bar of the project:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs){ if!CFrameWndEx::PreCreateWindow(cs) ) returnFALSE; // TODO: 在此处通过修改 // CREATESTRUCT cs 来修改窗口类或样式 cs.&=~FWS_ADDTOTITLE; cs.= _T("XXX系统"); returnTRUE;}
There may be some formatting problems when loading bitmaps, here are the discussion stickers:
http://bbs.csdn.net/topics/391027250?page=1#post-399164597
VS2010 Single Document MFC by loading a bitmap file as a client area background