资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
在客户区显示一个 Logo 位图如果你想在客户区绘图 (如一个 logo 图象或整个背景底图), 该类很适合 你所需.如果你想绘制一个 logo, 它将只重绘无效矩形区,因为我使用了内存 dc, 它绘制时很平滑,无闪烁现象。在 CMainFrame,重载 OnCreateClient 虚函数: BOOL CMainFrame:OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) / TODO: Add your specialized code here and/or call the base class if(CMDIFrameWnd:OnCreateClient(lpcs, pContext) m_ClientFrame.SubclassWindow(m_hWndMDIClient) ; return TRUE; else return FALSE; 头文件:#if !defined(AFX_CLIENTFRAME_H_9F201E20_8B54_11D1_87E4_00AA00242F4F_INC LUDED_) #define AFX_CLIENTFRAME_H_9F201E20_8B54_11D1_87E4_00AA00242F4F_INCLUDED_#if _MSC_VER = 1000 #pragma once #endif / _MSC_VER = 1000 / ClientFrame.h : header file / / / CClientFrame frameclass CClientFrame : public CWnd DECLARE_DYNCREATE(CClientFrame) protected:/ Attributes public:CClientFrame(); / protected constructor used by dynamic creation virtual CClientFrame(); static WNDPROC pfnSuper;/ Operations public: CPalette m_palette; CBitmap m_bitmap; virtual WNDPROC* GetSuperWndProcAddr() ;/ Overrides / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CClientFrame) /AFX_VIRTUAL/ Implementation protected:/ Generated message map functions /AFX_MSG(CClientFrame) afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); /AFX_MSG DECLARE_MESSAGE_MAP() ;/ /AFX_INSERT_LOCATION / Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif / !defined(AFX_CLIENTFRAME_H_9F201E20_8B54_11D1_87E4_00AA00242F4F_INC LUDED_) 实现框架:/ ClientFrame.cpp : implementation file /#include “stdafx.h“ #include “ClientFrame.h“#include “helper.h“#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE = _FILE_; #endifextern CRect oldrect;WNDPROC CClientFrame:pfnSuper = NULL;/ / / CClientFrameIMPLEMENT_DYNCREATE(CClientFrame, CWnd)CClientFrame:CClientFrame() GetBitmapAndPalette( IDB_LOGO, m_bitmap, m_palette ); CClientFrame:CClientFrame() BEGIN_MESSAGE_MAP(CClientFrame, CWnd) /AFX_MSG_MAP(CClientFrame) ON_WM_ERASEBKGND() ON_WM_PAINT() /AFX_MSG_MAP END_MESSAGE_MAP()/ / / CClientFrame message handlersBOOL CClientFrame:OnEraseBkgnd(CDC* pDC) / TODO: Add your message handler code here and/or call default return TRUE;WNDPROC* CClientFrame:GetSuperWndProcAddr() return void CClientFrame:OnPaint() / Do not call CWnd:OnPaint() for painting messages / TODO: Add your message handler code here InvalidateRect( CRect newrect; GetClientRect( /CDC *dc=GetDC(); /dc-DPtoLP(newrect); /ReleaseDC(dc); BITMAP bm; m_bitmap.GetBitmap( newrect=CRect(newrect.Width()/2- bm.bmWidth/2,newrect.Height()/2-bm.bmHeight/2,newrect.Width()/2- bm.bmWidth/2+ bm.bmWidth,newrect.Height()/2-bm.bmHeight/2+ bm.bmHeight); InvalidateRect( CPaintDC dc(this); / device context for painting /dc.SelectClipRgn(NULL); DrawTheBackground(this, #ifndef _HELPER_H_ #define _HELPER_H_ void DrawTheBackground(CWnd *view,CDC *pDC,CPalette *mp_palette,CBitmap *mp_bitmap,BOOL middle = FALSE);BOOL GetBitmapAndPalette(UINT nIDResource, CBitmap #endifHelper implementation:#include “stdafx.h“ #include “helper.h“ #include “memdc.h“CRect oldrect(0,0,0,0);void DrawTheBackground(CWnd *view,CDC *pDC,CPalette *mp_palette,CBitmap *mp_bitmap,BOOL middle) if(pDC-IsPrinting()return; CRect rect; CPalette *old_palette=NULL; / Select and realize the palette if( pDC-GetDeviceCaps(RASTERCAPS) pDC-RealizePalette(); view-GetClientRect(rect); pDC-DPtoLP(rect); CMemDC DC(pDC,rect); CDC dcImage; if (!dcImage.CreateCompatibleDC(pDC)return; BITMAP bm; mp_bitmap-GetBitmap( / Paint the image. CBitmap* pOldBitmap = dcImage.SelectObject(mp_bitmap); if(middle) CBrush* pOldBrush = (CBrush*)DC- SelectStockObject(GRAY_BRUSH); CRect crect; oldrect=CRect(rect.Width()- bm.bmWidth)/2,(rect.Height()-bm.bmHeight)/2,(rect.Width()- bm.bmWidth)/2+ bm.bmWidth,(rect.Height()-bm.bmHeight)/2+ bm.bmHeight); pDC-GetClipBox(DC-PatBlt( crect.left, crect.top, crect.Width(), crect.Height(),PATCOPY); DC-SelectObject(pOldBrush); DC-BitBlt(oldrect.left, oldrect.top, bm.bmWidth, bm.bmHeight, else for(int i=(int)floor(double)rect.left/bm.bmWidth)*bm.bmWidth;iBitBlt(i, j, bm.bmWidth, bm.bmHeight, dcImage.SelectObject(pOldBitmap); pDC-SelectPalette(old_palette,FALSE); pDC-RealizePalette(); BOOL GetBitmapAndPalette(UINT nIDResource, CBitmap HBITMAP hBmp = (HBITMAP):LoadImage( AfxGetInstanceHandle(), lpszResourceName, IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION ); if( hBmp = NULL )return FALSE; bitmap.Attach( hBmp ); / Create a logical palette for the bitmap DIBSECTION ds; BITMAPINFOHEADER bitmap.GetObject( sizeof(ds), int nColors = b
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号