VS2010 Single Document MFC by loading bitmap files as client area background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.