在客戶區(qū)顯示一個Logo位圖_第1頁
在客戶區(qū)顯示一個Logo位圖_第2頁
在客戶區(qū)顯示一個Logo位圖_第3頁
在客戶區(qū)顯示一個Logo位圖_第4頁
在客戶區(qū)顯示一個Logo位圖_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、在客戶區(qū)顯示一個Logo位圖 如果你想在客戶區(qū)繪圖 (如一個logo圖象或整個背景底圖), 該類很適合你所需.如果你想繪制一個logo, 它將只重繪無效矩形區(qū),因為我使用了內(nèi)存dc,它繪制時很平滑,無閃爍現(xiàn)象。在CMainFrame,重載OnCreateClient虛函數(shù): BOOL CMainFrame:OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) / TODO: Add your specialized code here and/or call the base classif(CMDIFrameWnd:OnC

2、reateClient(lpcs, pContext)m_ClientFrame.SubclassWindow(m_hWndMDIClient) ;return TRUE;else return FALSE; 頭文件:#if !defined(AFX_CLIENTFRAME_H_9F201E20_8B54_11D1_87E4_00AA00242F4F_INCLUDED_)#define AFX_CLIENTFRAME_H_9F201E20_8B54_11D1_87E4_00AA00242F4F_INCLUDED_#if _MSC_VER >= 1000#pragma once#endif

3、 / _MSC_VER >= 1000/ ClientFrame.h : header file/ CClientFrame frameclass CClientFrame : public CWndDECLARE_DYNCREATE(CClientFrame)protected:/ Attributespublic:CClientFrame(); / protected constructor used by dynamic creationvirtual CClientFrame();static WNDPROC pfnSuper;/ Operationspublic:CPalett

4、e m_palette;CBitmap m_bitmap;virtual WNDPROC* GetSuperWndProcAddr() ;/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CClientFrame)/AFX_VIRTUAL/ Implementationprotected:/ Generated message map functions/AFX_MSG(CClientFrame)afx_msg BOOL OnEraseBkgnd(CDC* pDC);afx_msg void On

5、Paint();/AFX_MSGDECLARE_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_INCLUDED_)實現(xiàn)框架:/ ClientFrame.cpp : implementation file/ #include &q

6、uot;stdafx.h"#include "ClientFrame.h"#include "helper.h" #ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif extern CRect oldrect; WNDPROC CClientFrame:pfnSuper = NULL; / CClientFrame IMPLEMENT_DYNCREATE(CClientFrame, CWnd) CClientFrame:CC

7、lientFrame()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_MAPEND_MESSAGE_MAP() / CClientFrame message handlers BOOL CClientFrame:OnEraseBkgnd(CDC* pDC) / TODO: Ad

8、d your message handler code here and/or call defaultreturn TRUE;WNDPROC* CClientFrame:GetSuperWndProcAddr()return &pfnSuper;void CClientFrame:OnPaint() / Do not call CWnd:OnPaint() for painting messages/ TODO: Add your message handler code hereInvalidateRect(&oldrect);CRect newrect;GetClient

9、Rect(&newrect);/CDC *dc=GetDC();/dc->DPtoLP(newrect);/ReleaseDC(dc);BITMAP bm;m_bitmap.GetBitmap(&bm);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(&

10、;newrect);CPaintDC dc(this); / device context for painting/dc.SelectClipRgn(NULL);DrawTheBackground(this,&dc,&m_palette,&m_bitmap,TRUE); #ifndef _HELPER_H_#define _HELPER_H_void DrawTheBackground(CWnd *view,CDC *pDC,CPalette *mp_palette,CBitmap *mp_bitmap,BOOL middle = FALSE);BOOL GetBit

11、mapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal);#endif Helper 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

12、 middle)if(pDC->IsPrinting()return;CRect rect;CPalette *old_palette=NULL;/ Select and realize the paletteif( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE && mp_palette->m_hObject != NULL )old_palette=pDC->SelectPalette( mp_palette, FALSE );pDC->RealizePalette();view->Get

13、ClientRect(rect);pDC->DPtoLP(rect);CMemDC DC(pDC,rect);CDC dcImage;if (!dcImage.CreateCompatibleDC(pDC)return;BITMAP bm;mp_bitmap->GetBitmap(&bm);/ Paint the image.CBitmap* pOldBitmap = dcImage.SelectObject(mp_bitmap);if(middle)CBrush* pOldBrush = (CBrush*)DC->SelectStockObject(GRAY_BRU

14、SH);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(&crect);DC->PatBlt( crect.left, crect.top, crect.Width(), crect.Height(),PATCOPY);DC->SelectObject(p

15、OldBrush);DC->BitBlt(oldrect.left, oldrect.top, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);elsefor(int i=(int)floor(double)rect.left/bm.bmWidth)*bm.bmWidth;i<=rect.right/*rect.Width()*/;i+=bm.bmWidth) for(int j="(int)floor(double)rect.top/bm.bmHeight)*bm.bmHeight;j<=rect.bot

16、tom/*rect.Height()*/;j+=bm.bmHeight)" DC->BitBlt(i, j, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);dcImage.SelectObject(pOldBitmap); pDC->SelectPalette(old_palette,FALSE);pDC->RealizePalette(); BOOL GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal)

17、LPCTSTR lpszResourceName = (LPCTSTR)nIDResource;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 bitmapDIBSECTION ds;BITMAPINFOHEADER &bmIn

18、fo = ds.dsBmih;bitmap.GetObject( sizeof(ds), &ds );int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << bmInfo.biBitCount; / Create a halftone palette if colors> 256. CClientDC dc(NULL); / Desktop DCif( nColors > 256 ) pal.CreateHalftonePalette( &dc );else/ Create the palette

19、RGBQUAD *pRGB = new RGBQUADnColors;CDC memDC;memDC.CreateCompatibleDC(&dc);memDC.SelectObject( &bitmap );:GetDIBColorTable( memDC, 0, nColors, pRGB );UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);LOGPALETTE *pLP = (LOGPALETTE *) new BYTEnSize;pLP->palVersion = 0x300;p

20、LP->palNumEntries = nColors;for( int i=0; i palPalEntryi.peRed = pRGBi.rgbRed;pLP->palPalEntryi.peGreen = pRGBi.rgbGreen;pLP->palPalEntryi.peBlue = pRGBi.rgbBlue;pLP->palPalEntryi.peFlags = 0;pal.CreatePalette( pLP );delete pLP;delete pRGB;return TRUE;CMemDC implementation (for those who

21、 don't have it yet): #ifndef _MEMDC_H_#define _MEMDC_H_/ CMemDC - memory DC/ Author: Keith Rule/ Email: keithr/ Copyright 1996-1997, Keith Rule/ You may freely use or modify this code provided this/ Copyright is included in all derived versions./ History - 10/3/97 Fixed scrolling bug./ Added pri

22、nt support./ 12/19/97 Adrian Roman - modified the constructor to take two parameters/ This class implements a memory Device Context class CMemDC : public CDC private:CBitmap m_bitmap; / Offscreen bitmapCBitmap* m_oldBitmap; / bitmap originally found in CMemDCCDC* m_pDC; / Saves CDC passed in constru

23、ctorBOOL m_bMemDC; / TRUE if CDC really is a Memory DC.public:CRect m_rect; / Rectangle of drawing area.CMemDC(CDC* pDC, CRect &rect) : CDC(), m_oldBitmap(NULL), m_pDC(pDC)ASSERT(m_pDC != NULL); / If you asserted here, you passed in a NULL CDC.m_bMemDC = !pDC->IsPrinting();m_rect=rect;if (m_bMemDC)/ Create a Memory DCCreateCompatibleDC(pDC);pDC->GetClipBox(&m_rect);m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height();m_oldBitmap = SelectObje

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論