资源描述:
《教你各种改变背景的方法》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、教你各种改变背景的方法TochangethebackgroundcolorforaCView,CFrameWnd,orCWndobject,processtheWM_ERASEBKGNDmessage.Thesamplecodebelowdemonstrateshow.SampleCode-----------BOOLCSampleView::OnEraseBkgnd(CDC*pDC){//SetbrushtodesiredbackgroundcolorCBrushbackBrush(RGB(255,128,128));//Saveo
2、ldbrushCBrush*pOldBrush=pDC->SelectObject(&backBrush);CRectrect;pDC->GetClipBox(&rect);//ErasetheareaneededpDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);pDC->SelectObject(pOldBrush);returnTRUE;}TochangethebackgroundcolorforaCMDIFrameWndyoumustsubcla
3、ssthemultipledocumentinterface(MDI)clientwindow(windowintheclientareaofCMDIFrameWnd)andprocesstheWM_ERASEBKGNDmessage.FormoreinformationabouttheMDIclientwindowinanMDIapplication,seechapter18in"ProgrammingWindows3.1-ThirdEdition"byCharlesPetzold.Foranexamplethatshowshowt
4、osubclasstheMDICLIENTwindow,pleaseseethearticleintheMicrosoftKnowledgeBase:ARTICLE-ID:Q129471TITLE:HowtosubclasstheMDICLIENTbyUsingMFCTochangethebackgroundcolorofanMDIclientwindow(clientareaofaCMDIFrameWnd),performthefollowingstepsusinganAppWizard-generatedapplication:1
5、.CreateagenericCWndclasswithClassWizard.2.Addamembervariable,usingthetypeoftheCWndclassfromstep1,totheCMainFrameclass.3.IntheCMainFrame'sOnCreatememberfunction,afterthecalltothebaseclassCMDIFrameWnd::OnCreate(),addacalltoSubclassWindow().Forexample:if(!m_wndNewClient.Su
6、bclassWindow(m_hWndMDIClient)){TRACE("FailedtosubclassMDIclientwindow");return-1;//failtocreate}m_hWndMDIClientisthemembervariableofCMDIFrameWndthatcontainsthehandletotheMDIclientwindow.Also,replace"m_wndNewClient"withthedatamemberthatyoucreatedinstep2.4.Wheneverawind
7、owissubclassed,theGetSuperWndProcAddr()memberfunctionfortheCWndneedstobeoverriddentoprovidestoragefortheoldwindowprocedure'saddress.Todothat,addthefollowingfunctiontotheimplementationoftheCWndclasscreatedinstep1:WNDPROC*CNewClientWnd::GetSuperWndProcAddr(){staticWNDPROC
8、NEARpfnSuper=NULL;return&pfnSuper;}NOTE:Replace"CNewClientWnd"abovewiththenameofyourclass.Formoreinformationon