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);				
    }


  • 相关阅读:
    拷贝数据库和VS项目
    Silverlight4-安装顺序(VS2010)
    Android开发笔记-签名
    Asp.net Core中使用Session
    Solr 排除查询
    Solr高级查询Facet
    vue.js初探
    Asp.net Core 初探(发布和部署Linux)
    Asp.net Core准备工作
    C# 生成验证码图片时消除锯齿
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106911.html
Copyright © 2011-2022 走看看