⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00000012.txt

📁 水木清华BBS站的讨论区精华集锦
💻 TXT
字号:
 
                       --===BBS水木清华站∶精华区===--
 
                        -===BBS水木清华站∶精华区===-
 教你各种改变背景的方法! 

*****************************************************************************
** 
  

*****************************************************************************
** 
  
 To change the background color for a CView, CFrameWnd, or CWnd object, 
 process the WM_ERASEBKGND message. The sample code below demonstrates 
 how. 
  
 Sample Code 
 ----------- 
  
 BOOL CSampleView::OnEraseBkgnd(CDC* pDC) 
 { 
 // Set brush to desired background color 
 CBrush backBrush(RGB(255, 128, 128)); 
  
 // Save old brush 
 CBrush* pOldBrush = pDC->SelectObject(&backBrush); 
  
 CRect rect; 
 pDC->GetClipBox(&rect); // Erase the area needed 
  
 pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), 
 PATCOPY); 
 pDC->SelectObject(pOldBrush); 
 return TRUE; 
 } 
  
 To change the background color for a CMDIFrameWnd you must subclass the 
 multiple document interface (MDI) client window (window in the client area 
 of CMDIFrameWnd) and process the WM_ERASEBKGND message. For more 
 information about the MDI client window in an MDI application, see chapter 
 18 in "Programming Windows 3.1 - Third Edition" by Charles Petzold. For an 
 example that shows how to subclass the MDICLIENT window, please see the 
 article in the Microsoft Knowledge Base: 
  
 ARTICLE-ID: Q129471 
 TITLE: How to subclass the MDICLIENT by Using MFC 
  
 To change the background color of an MDI client window (client area of a 
 CMDIFrameWnd), perform the following steps using an AppWizard-generated 
 application: 
  
 1. Create a generic CWnd class with ClassWizard. 
  
 2. Add a member variable, using the type of the CWnd class from step 
 1, to the CMainFrame class. 
  
 3. In the CMainFrame's OnCreate member function, after the call to the 
 base class CMDIFrameWnd::OnCreate(), add a call to SubclassWindow(). 
 For example: 
  
 if (!m_wndNewClient.SubclassWindow(m_hWndMDIClient)) 
 { 
 TRACE("Failed to subclass MDI client window\n"); 
 return -1; // fail to create 
 } 
  
 m_hWndMDIClient is the member variable of CMDIFrameWnd that 
 contains the handle to the MDI client window. Also, replace 
 "m_wndNewClient" with the data member that you created in step 2. 
  
 4. Whenever a window is subclassed, the GetSuperWndProcAddr() member 
 function for the CWnd needs to be overridden to provide storage for 
 the old window procedure's address. To do that, add the following 
 function to the implementation of the CWnd class created in step 1: 
  
 WNDPROC* CNewClientWnd::GetSuperWndProcAddr() 
 { 
 static WNDPROC NEAR pfnSuper = NULL; 
 return &pfnSuper; 
 } 
  
 NOTE: Replace "CNewClientWnd" above with the name of your class. 
  
 For more information on subclassing windows using the Microsoft 
 Foundation Classes, please see the following materials: 
  
 - "Class Library Reference" for functions CWnd::SubclassWindow(), 
 CWnd::GetSuperWndProcAddr(), and CWnd::SubclassDlgItem() 
  
 - Query on the following words in the Microsoft Knowledge Base: 
  
 subclass and sample and mfc 
  
 - See the CTRLTEST MFC sample application that is provided with 
 Visual C++ for Windows and Visual C++ 32-bit Edition. 
  
 - See the article titled "Subclassing Windows with the Microsoft 
 Foundation Class Library" on the Microsoft Developer Network 
 (MSDN) CD. 
  
 5. Override the WM_ERASEBKGND message for the generic CWnd class, 
 using the code listed above. 
  
 To change the background color of a CFormView object, either process 
 the WM_ERASEBKGND message and use the code above or process the 
 WM_CTLCOLOR message to change the background color. 
  
 For more information on changing the background color of a dialog box 
 by processing the WM_CTLCOLOR message, please query on the following 
 words in the Microsoft Knowledge Base: 
  
 changing and background and color and MFC 
  

*****************************************************************************
** 
  

*****************************************************************************
** 
  
  
 This article gives you two ways to make the CMiniFrameWnd miniframe window 
 paint its background area. 
  
 A miniframe window (CMiniFrameWnd) doesn't paint its background area even 
 though Windows sends a WM_ERASEBKGND message to prepare the invalidated 
 portion of the window for painting. The default window procedure for this 
 message erases the background by using the class background brush specified 
  
 by the hbrBackground member of the WNDCLASS structure. As this background 
 brush is NULL for a CMiniFrameWnd and MFC doesn't provide a handler for 
 WM_ERASEBKGND to erase the background of a CMiniFrameWnd, the client area 
 of a miniframe window is never erased. 
  
 MORE INFORMATION 
 ================ 
  
 A CMiniFrameWnd is a half-height/half-caption frame window typically 
 enclosing another child window that takes up the entire client area of the 
 window. The default window class for a CMiniFrameWnd is pre-registered by 
 MFC without a background brush; that is, the hbrBackground member of the 
 WNDCLASS structure is NULL. 
  
 The application sends a WM_ERASEBKGND message to prepare the invalidated 
 portion of a window for painting. The window procedure of MFC (AfxWndProc) 
 receives this message first and in turn calls the default window procedure 
 (DefWindowProc), which erases the background by using the class background 
 brush. Because there is no background brush for a CMiniFrameWnd, the 
 background area is never painted. 
  
 This default behavior is by design because there is no need for the 
 miniframe window to repaint its background, as the child window typically 
 enclosing the miniframe window will paint over its background area. 
  
 Following are two ways to make the CMiniFrameWnd paint its background area. 
  
  
 Method One 
 ---------- 
  
 This method registers a window class for CMiniFrameWnd with a background 
 brush. To implement this, derive a class from CMiniFrameWnd and override 
 the Create member function. The Create function would be similar to the 
 default implementation of CMiniFrameWnd::Create (in WINMINI.CPP of 
 ~/mfc/src directory), but with the addition of a background brush. The 
 following code demonstrates this: 
  
 // Header file of CMiniFrameWnd derived class (mymini.h) 
 class CMyMiniFrameWnd : public CMiniFrameWnd 
 { 
 DECLARE_DYNCREATE(CMyMiniFrameWnd) 
 public: 
 CMyMiniFrameWnd(); 
 // Add the declaration for the Create function 
 BOOL Create(LPCTSTR lpClassName, LPCTSTR lpszWindowName, 
 DWORD dwStyle, const RECT& rect, 
 CWnd *pParentWnd = NULL, UINT nID = 0); 
  
 // Rest of the class definition 
 ... 
 }; 
  
 // Implementation file of CMiniFrameWnd derived class (mymini.cpp) 
 BOOL CMyMiniFrameWnd::Create( 
 LPCTSTR lpszClassName, LPCTSTR lpszWindowName, 
 DWORD dwStyle, const RECT& rect, 
 CWnd* pParentWnd, UINT nID) 
 { 
 // Window title 
 
                        -===BBS水木清华站∶精华区===-

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -