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. Why my program cannot show colour?

Why my program cannot show colour?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 2 Posters 1 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.
  • R Offline
    R Offline
    Richard Cheng
    wrote on last edited by
    #1

    My code : CPen penObject; penObject.CreatePen(PS_SOLID, 4, RGB(255,0,0)); CDCPoint->SelectObject(&penObject); CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,200); Why the line is in colour BLACK instead of RED?????? Also, when i put: CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,100); It cannot print a dot. It prints nothing.....do you know why???? :eek:

    T 1 Reply Last reply
    0
    • R Richard Cheng

      My code : CPen penObject; penObject.CreatePen(PS_SOLID, 4, RGB(255,0,0)); CDCPoint->SelectObject(&penObject); CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,200); Why the line is in colour BLACK instead of RED?????? Also, when i put: CDCPoint->MoveTo(100,100); CDCPoint->LineTo(100,100); It cannot print a dot. It prints nothing.....do you know why???? :eek:

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Where does CDCPoint come from? If you're playing with memory device contexts, and your line is black instead of red, you've probably screwed calling CreateCompatibleBitmap. Does your code look like this? CDC CDCPoint; CDCPoint.CreateCompatibleDC(pSomeOtherDC); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&CDCPoint, cx, cy); CDCPoint.SelectObject(&bitmap); If yes, you need need to change first argument in CreateCompatibleBitmap from &CDCPoint to pSomeOtherDC. Currently, your bitmap is monochrome and red pen draws a black line. Use MoveTo(100, 100) and LineTo(100, 101) to display a pixel. Better yet, call SetPixel(100, 100, RGB(...)); Tomasz Sowinski -- http://www.shooltz.com.pl

      R 1 Reply Last reply
      0
      • T Tomasz Sowinski

        Where does CDCPoint come from? If you're playing with memory device contexts, and your line is black instead of red, you've probably screwed calling CreateCompatibleBitmap. Does your code look like this? CDC CDCPoint; CDCPoint.CreateCompatibleDC(pSomeOtherDC); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&CDCPoint, cx, cy); CDCPoint.SelectObject(&bitmap); If yes, you need need to change first argument in CreateCompatibleBitmap from &CDCPoint to pSomeOtherDC. Currently, your bitmap is monochrome and red pen draws a black line. Use MoveTo(100, 100) and LineTo(100, 101) to display a pixel. Better yet, call SetPixel(100, 100, RGB(...)); Tomasz Sowinski -- http://www.shooltz.com.pl

        R Offline
        R Offline
        Richard Cheng
        wrote on last edited by
        #3

        My program doesn't have CreatCompatibleBitmap...something liked that.....i just have in OnDraw(CDC* pDC): if(CDCPoint==NULL) { CDCPoint=new CDC; } CDCPoint->m_hDC=pDC->m_hDC; CDCPoint->m_hAttribDC=pDC->m_hAttribDC; //creating a global window handler to help with output Handler=m_hWnd; //setting background mode so there wouldn't be a border around text (just in case) pDC->SetBkMode(TRANSPARENT); //setting fixed width font CFont newFont; newFont.CreateFont(18, 9, 0, 0, FW_REGULAR, 0, 0, 0, ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "Courier New"); pDC->SelectObject(&newFont); Also, I found that there is another problem........normally the output font is Courier New....but suddently....all fonts change to another one....including all message box. Thanks for your help anyway... :) :)

        T 1 Reply Last reply
        0
        • R Richard Cheng

          My program doesn't have CreatCompatibleBitmap...something liked that.....i just have in OnDraw(CDC* pDC): if(CDCPoint==NULL) { CDCPoint=new CDC; } CDCPoint->m_hDC=pDC->m_hDC; CDCPoint->m_hAttribDC=pDC->m_hAttribDC; //creating a global window handler to help with output Handler=m_hWnd; //setting background mode so there wouldn't be a border around text (just in case) pDC->SetBkMode(TRANSPARENT); //setting fixed width font CFont newFont; newFont.CreateFont(18, 9, 0, 0, FW_REGULAR, 0, 0, 0, ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "Courier New"); pDC->SelectObject(&newFont); Also, I found that there is another problem........normally the output font is Courier New....but suddently....all fonts change to another one....including all message box. Thanks for your help anyway... :) :)

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          So what's the point of having CDCPoint variable? Isn't pDC enough? Tomasz Sowinski -- http://www.shooltz.com.pl

          R 1 Reply Last reply
          0
          • T Tomasz Sowinski

            So what's the point of having CDCPoint variable? Isn't pDC enough? Tomasz Sowinski -- http://www.shooltz.com.pl

            R Offline
            R Offline
            Richard Cheng
            wrote on last edited by
            #5

            CDC* CDCPoint is a global variable for another files in the project. But pDC is just using in OnDraw(). Therefore, CDCPoint and pDC are the same but used in different area.

            T 1 Reply Last reply
            0
            • R Richard Cheng

              CDC* CDCPoint is a global variable for another files in the project. But pDC is just using in OnDraw(). Therefore, CDCPoint and pDC are the same but used in different area.

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              You shouldn't to copy HDC handles from pDC passed OnDraw to your global variable. They'll become invalid soon after OnDraw returns, b/c pDC will be released and your CDCPoint will be useless. Just perform your drawing using pDC. If using pDC instead of CDCPoint doesn't produce expected results, post your OnDraw handler code. Tomasz Sowinski -- http://www.shooltz.com.pl

              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