在客户区显示一个Logo位图

上传人:lcm****20 文档编号:44448170 上传时间:2018-06-09 格式:DOCX 页数:9 大小:28.88KB
返回 下载 相关 举报
在客户区显示一个Logo位图_第1页
第1页 / 共9页
在客户区显示一个Logo位图_第2页
第2页 / 共9页
在客户区显示一个Logo位图_第3页
第3页 / 共9页
在客户区显示一个Logo位图_第4页
第4页 / 共9页
在客户区显示一个Logo位图_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《在客户区显示一个Logo位图》由会员分享,可在线阅读,更多相关《在客户区显示一个Logo位图(9页珍藏版)》请在金锄头文库上搜索。

1、在客户区显示一个 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(CMDIF

2、rameWnd: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 #prag

3、ma 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;/ Ope

4、rations 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 OnErase

5、Bkgnd(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_) 实现框架:/ ClientFram

6、e.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)CC

7、lientFrame: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:OnEraseBkgn

8、d(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; GetClient

9、Rect( /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); /

10、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:#i

11、nclude “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(RAS

12、TERCAPS) 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*)D

13、C- 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-Sel

14、ectObject(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 GetBitmapAnd

15、Palette(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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号