zoukankan      html  css  js  c++  java
  • CView OnDraw中显示位图,并在 resize 时使位图始终显示在客户区左下角

    首先在 CMainFrame 中定义三个共有成员变量

    public:
    	HBITMAP m_hLogo;
    	int m_nBmpHeight;
    	int m_nBmpWidth;

    在构造函数、析构函数中

    CMainFrame::CMainFrame()
    {
    	m_hLogo = (HBITMAP)::LoadImage(NULL, "resource\\banner.bmp", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
    	if(m_hLogo)
    	{
    		BITMAP bitmap;
    		GetObject(m_hLogo,sizeof(BITMAP),&bitmap);
    		m_nBmpHeight = bitmap.bmHeight;
    		m_nBmpWidth = bitmap.bmWidth;
    	}
    	else
    	{
    		m_nBmpHeight = 380;
    		m_nBmpWidth = 658;
    	}
    }
    
    CMainFrame::~CMainFrame()
    {
    	if(m_hLogo)
    		::DeleteObject(m_hLogo);
    }

    在 CView OnDraw 中

    void CCGUIView::OnDraw(CDC* pDC)
    {
    	CCGUIDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	// TODO: add draw code for native data here
    
    	CRect rect;
    	GetWindowRect(&rect);
    
    	HDC hdcDest = ::GetDC(m_hWnd);
    	HDC hdcSrc = ::CreateCompatibleDC(hdcDest);
    	CMainFrame * pMainFrm = (CMainFrame *)::AfxGetApp()->m_pMainWnd;
    	::SelectObject(hdcSrc, pMainFrm->m_hLogo);
    	::StretchBlt(hdcDest,0, rect.Height()-pMainFrm->m_nBmpHeight, pMainFrm->m_nBmpWidth, pMainFrm->m_nBmpHeight, hdcSrc, 0, 0, pMainFrm->m_nBmpWidth, pMainFrm->m_nBmpHeight, SRCCOPY); 
    	::ReleaseDC(m_hWnd, hdcDest);	
    	::DeleteDC(hdcSrc);				
    }


  • 相关阅读:
    【转】教你爱上Blocks(闭包)
    【转】iOS Developer:真机测试
    bzoj1231 混乱的奶牛
    bzoj2064 分裂
    洛谷P2051 中国象棋
    洛谷P2607 骑士
    洛谷P1879 玉米田
    洛谷P3694 邦邦的大合唱
    openjudge dp水题记录
    bzoj1191 超级英雄
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106911.html
Copyright © 2011-2022 走看看