Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CPaintDC develish slow

CPaintDC develish slow

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphicsperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    S van Leent
    wrote on last edited by
    #1

    Hi all, I am currently doing a project where I need to be able to have a imaging framework. Although the framework itself runs pretty smooth, the CPaintDC of MFC kills me. The SetPixelV is extremely slow, so I want to use another way of doing this. I know it is possible to create a CDC in memory, but how can I put a bitmap created from this CDC put on the surface a CWnd subclassed control? Any suggestions? LPCTSTR Dutch = TEXT("Double Dutch :-)");

    B 1 Reply Last reply
    0
    • S S van Leent

      Hi all, I am currently doing a project where I need to be able to have a imaging framework. Although the framework itself runs pretty smooth, the CPaintDC of MFC kills me. The SetPixelV is extremely slow, so I want to use another way of doing this. I know it is possible to create a CDC in memory, but how can I put a bitmap created from this CDC put on the surface a CWnd subclassed control? Any suggestions? LPCTSTR Dutch = TEXT("Double Dutch :-)");

      B Offline
      B Offline
      basementman
      wrote on last edited by
      #2

      bitblt. Code snippet to help you (heavily edited and content deleted):

      BOOL DoChart(CallContextObj *pCallContextObj)
      {
      CDC oMemDC;
      CBitmap *pOldBmp;
      CBitmap oBmp;

      long lWidth = 300;
      long lHeight = 200;
      pCallContextObj->GetParameterValue("ChartWidth",&lWidth);
      pCallContextObj->GetParameterValue("ChartHeight",&lHeight);

      CRect oBmpSize(0,0,lWidth,lHeight);

      oMemDC.CreateCompatibleDC(NULL);
      int iOldMapMode = oMemDC.SetMapMode(MM_TEXT);

      CWindowDC dcScreen(NULL);

      oBmp.CreateCompatibleBitmap(&dcScreen,oBmpSize.Width(), oBmpSize.Height());

      pOldBmp = oMemDC.SelectObject(&oBmp);

      WORD wChartType = 88;
      pCallContextObj->GetParameterValue("ChartType",&wChartType);

      BOOL bRetval = FALSE;
      char caHeaders[512];
      strcpy(caHeaders,"Invalid Chart Type");

      switch (wChartType)
      {
      case 0:
      bRetval = DoLineChart(pCallContextObj,&oMemDC,caHeaders,oBmpSize);
      break;

        case 1:
          bRetval = DoBarChart(FALSE,pCallContextObj,&oMemDC,caHeaders,oBmpSize);
          break;
      
        case 2:
          bRetval = DoBarChart(TRUE,pCallContextObj,&oMemDC,caHeaders,oBmpSize);
          break;
      
        case 3:
          bRetval = DoOpenHiLowCloseChart(pCallContextObj,&oMemDC,caHeaders,oBmpSize);
          break;
      
        case 4:
          bRetval = DoPieChart(pCallContextObj,&oMemDC,caHeaders,oBmpSize);
          break;
      }
      

      if (bRetval)
      {
      LPSTR cpBuf = pCallContextObj->GetOutputBufferPtr();

        long lQuality = 75;
        pCallContextObj->GetParameterValue("ImageQuality",&lQuality);
      
        char caContentType\[256\];
      
        long lDataSize = WriteImage(oBmp,cpBuf,pCallContextObj->GetOutputBufferSize(),caHeaders,(DWORD)lQuality);
        if (lDataSize > 0)
          {
            pCallContextObj->SuppressHeaders();
            // pCallContextObj->GetMimeType("x.bmp",caContentType);
            pCallContextObj->GetMimeType("x.jpg",caContentType);
      
            sprintf(caHeaders,"Content-Type: %s%sContent-Length: %d%s%s",caContentType,cpCRLF,lDataSize,cpCRLF,cpCRLF);
      
            // write out our custom headers
            if (pCallContextObj->ServerSupportFunction(HSE\_REQ\_SEND\_RESPONSE\_HEADER,"200 OK",0,(LPDWORD)caHeaders) || ::GetLastError() == 10054)
              pCallContextObj->WriteClient((LPVOID)cpBuf,(LPDWORD)&lDataSize);
      
            \*cpBuf = 0;
          }
        else
          bRetval = FALSE;
      }
      

      oMemDC.SetMapMode(iOldMapMode);
      oMemDC.SelectObject(pOldBmp);

      oMemDC.DeleteDC();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups