• 图形绘制处理逻辑VC


    // 逻辑1:先从资源中读取背景资源,然后将绘图对象与DC绑定,通过绘图对象绘出背景
    // 逻辑2:先从资源中读取背景资源,新建一个MEMDC,将绘图对象与MEMDC绑定,并且
    // 通过绘图对象在内存中绘制图形, 最后将MEMDC中的数据复制给绘图DC绘图

    Gdiplus::Image* m_pPngBg;

     1 BOOL G_ImageFromIDResource( UINT nID, LPCTSTR sTR,Gdiplus::Image *&pImg )
     2 {
     3     HINSTANCE hInst = AfxGetResourceHandle();
     4     HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
     5     if (!hRsrc)
     6         return FALSE;
     7     // load resource into memory
     8     DWORD len = SizeofResource(hInst, hRsrc);
     9     BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
    10     if (!lpRsrc)
    11         return FALSE;
    12     // Allocate global memory on which to create stream
    13     HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
    14     BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
    15     memcpy(pmem,lpRsrc,len);
    16     GlobalUnlock(m_hMem);
    17     IStream* pstm;
    18     CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
    19     // load from stream
    20     pImg=Gdiplus::Image::FromStream(pstm);
    21     // free/release stuff
    22     pstm->Release();
    23     FreeResource(lpRsrc);
    24     GlobalFree(m_hMem);
    25     return TRUE;
    26 }

    方法一:方便
    G_ImageFromIDResource(IDB_PNG_MONEYSEL_SELECTED, _T("PNG"), m_pPngBg);
    Gdiplus::Graphics graphics(pDC->m_hDC);
    graphics.DrawImage(m_pPngBg, 0, 0,m_rcClient.Width(),m_rcClient.Height());

    方法二:推荐

    CRect rect;
    GetWindowRect(&rect);

    CDC memDC;
    memDC.CreateCompatibleDC(pDC);

    int nWidth=m_pPngBg->GetWidth();
    int nHeight=m_pPngBg->GetHeight();

    CBitmap bitMemMap;
    bitMemMap.CreateCompatibleBitmap(pDC,nWidth,nHeight);
    memDC.SelectObject(&bitMemMap);

    Gdiplus::Graphics graphics(memDC.m_hDC); // Create a GDI+ graphics object
    graphics.DrawImage(m_pPngBg, 0, 0,nWidth,nHeight);

    pDC->BitBlt(0,0, rect.Width(),rect.Height(),&memDC, 0, 0,SRCCOPY);

    bitMemMap.DeleteObject();
    memDC.DeleteDC();

  • 相关阅读:
    go标准库的学习-net/http
    go标准库的学习-sync互斥
    sqlplus命令大全
    Oracle 11g安装步骤详谈
    安装64位版Oracle11gR2后无法启动SQLDeveloper的解决方案(原创) (2016-10-29 下午01:56)
    Dos命令查看端口占用及关闭进程
    access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
    Hibernate的集合映射与sort、order-by属性
    Hibernate总结2 API和配置文件
    MyEclipse8.5启动无法选择工作空间的问题
  • 原文地址:https://www.cnblogs.com/liflying/p/4754159.html
Copyright © 2020-2023  润新知