• 将JPG图片绘制在对话框背景上:(这段代码绝对可以执行)


    JPG图片绘制在对话框背景上:  
       
      显示JPG图片的函数  
      void   CMyDlg::ShowPicture(CDC   *pDC,   CString   m_strBRoute,   int   x,   int   y,   int   width,   int   height)  
      {  
      HANDLE   hFile   =   CreateFile(m_strBRoute,   GENERIC_READ,   0,   NULL,   OPEN_EXISTING,   0,   NULL);  
      _ASSERTE(INVALID_HANDLE_VALUE   !=   hFile);  
       
      //   取得文件大小  
      DWORD   dwFileSize   =   GetFileSize(hFile,   NULL);  
      _ASSERTE(-1   !=   dwFileSize);  
      LPVOID   pvData   =   NULL;  
      //根据文件大小分配内存  
      HGLOBAL   hGlobal   =   GlobalAlloc(GMEM_MOVEABLE,   dwFileSize);  
      _ASSERTE(NULL   !=   hGlobal);  
      pvData   =   GlobalLock(hGlobal);  
      _ASSERTE(NULL   !=   pvData);  
      DWORD   dwBytesRead   =   0;  
      //读取文件并存入全局内存  
      BOOL   bRead   =   ReadFile(hFile,   pvData,   dwFileSize,   &dwBytesRead,   NULL);  
      _ASSERTE(FALSE   !=   bRead);  
      GlobalUnlock(hGlobal);  
      CloseHandle(hFile);  
      LPSTREAM   pstm   =   NULL;  
      //   通过全局内存创建   IStream*   的指针  
      HRESULT   hr   =   CreateStreamOnHGlobal(hGlobal,   TRUE,   &pstm);  
      _ASSERTE(SUCCEEDED(hr)   &&   pstm);  
      //通过图形文件创建IPicture   对象  
      if   (gpPicture)  
      gpPicture->Release();  
      hr   =   OleLoadPicture(pstm,   dwFileSize,   FALSE,   IID_IPicture,   (LPVOID   *)&gpPicture);  
      _ASSERTE(SUCCEEDED(hr)   &&   gpPicture);  
      pstm->Release();  
      HDC   hdc;  
      hdc=pDC->GetSafeHdc();  
      if   (gpPicture)  
      {  
      //   取得图片的宽和高  
      long   hmWidth;  
      long   hmHeight;  
      gpPicture->get_Width(&hmWidth);  
      gpPicture->get_Height(&hmHeight);  
      //宽高转换为象素  
      int   nWidth =   MulDiv(hmWidth,   GetDeviceCaps(hdc,   LOGPIXELSX),   HIMETRIC_INCH);  
      int   nHeight =   MulDiv(hmHeight,   GetDeviceCaps(hdc,   LOGPIXELSY),   HIMETRIC_INCH);  
      RECT   rc;  
      GetClientRect(&rc);/*取得客户区*/  
      gpPicture->Render(hdc,   x,y,   (int)height*hmWidth/hmHeight,height,   0,   hmHeight,   hmWidth,   -hmHeight,   &rc);  
      /*显示图片*/  
      }  
      GlobalFree(hGlobal);  
       
      }  
       
      //在OnEraseBkgnd中  
      CRect   rc;  
      GetClientRect(&rc);  
      ShowPicture(pDC,strJpgPath,rc.left,rc.top,rc.Width(),   rc.Height());  

  • 相关阅读:
    poj 1634
    poj 2153
    POJ 1693
    poj 1789
    POJ 2676
    vue 路由
    用 node.js 创建第一个Hello World
    js原生Ajax 的封装和原理
    BFC原理
    怎么理解js的面向对象编程
  • 原文地址:https://www.cnblogs.com/8586/p/1335194.html
Copyright © 2020-2023  润新知