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. Drawing Colored Rectangles

Drawing Colored Rectangles

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicstestingbeta-testingarchitecture
3 Posts 3 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.
  • X Offline
    X Offline
    Xavier Shay
    wrote on last edited by
    #1

    I'm currently testing my project on Windows ME and have found the following problem: I'm using a SDI project using the Doc/View architecture. Using the code at the bottom of this post i'm drawing rectangles on to the screen. When redrawing the screen (Most often when I've got an Invalidate() command in the MouseMove Handler), after a certain number of redraws (A different number each time), suddenly lose the color from my blocks and just get a black outline. I have absolutely no idea why this happens, could somebody help me? Thanks in advance, - X The Code (This is placed in a function and called for each block I need to draw): CBrush br; CRect rect; rect.left = point.x - BLOCKWIDTH/2; rect.top = point.y - BLOCKHEIGHT/2; rect.right = point.x + BLOCKWIDTH/2; rect.bottom = point.y + BLOCKHEIGHT/2 - NODELENGTH; // I'm writing a Flow Chart application, so the following line draw // little 'nodes' at the top and bottom of each block pDC->MoveTo(point.x, point.y + BLOCKHEIGHT/2 - NODELENGTH); pDC->LineTo(point.x, point.y + BLOCKHEIGHT/2); br.CreateSolidBrush(RGB(0,200,0)); pDC->SelectObject(&br); pDC->Rectangle(rect); br.DeleteObject();

    M C 2 Replies Last reply
    0
    • X Xavier Shay

      I'm currently testing my project on Windows ME and have found the following problem: I'm using a SDI project using the Doc/View architecture. Using the code at the bottom of this post i'm drawing rectangles on to the screen. When redrawing the screen (Most often when I've got an Invalidate() command in the MouseMove Handler), after a certain number of redraws (A different number each time), suddenly lose the color from my blocks and just get a black outline. I have absolutely no idea why this happens, could somebody help me? Thanks in advance, - X The Code (This is placed in a function and called for each block I need to draw): CBrush br; CRect rect; rect.left = point.x - BLOCKWIDTH/2; rect.top = point.y - BLOCKHEIGHT/2; rect.right = point.x + BLOCKWIDTH/2; rect.bottom = point.y + BLOCKHEIGHT/2 - NODELENGTH; // I'm writing a Flow Chart application, so the following line draw // little 'nodes' at the top and bottom of each block pDC->MoveTo(point.x, point.y + BLOCKHEIGHT/2 - NODELENGTH); pDC->LineTo(point.x, point.y + BLOCKHEIGHT/2); br.CreateSolidBrush(RGB(0,200,0)); pDC->SelectObject(&br); pDC->Rectangle(rect); br.DeleteObject();

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Select the brush out of the device context before destroying the brush.

      CBrush* pOldBrush = pDC->SelectObject(&br);

      pDC->Rectangle(rect);
      pDC->SelectObject ( pOldBrush );
      br.DeleteObject();

      --Mike-- http://home.inreach.com/mdunn/ :love: your :bob: with :vegemite: and :beer:

      1 Reply Last reply
      0
      • X Xavier Shay

        I'm currently testing my project on Windows ME and have found the following problem: I'm using a SDI project using the Doc/View architecture. Using the code at the bottom of this post i'm drawing rectangles on to the screen. When redrawing the screen (Most often when I've got an Invalidate() command in the MouseMove Handler), after a certain number of redraws (A different number each time), suddenly lose the color from my blocks and just get a black outline. I have absolutely no idea why this happens, could somebody help me? Thanks in advance, - X The Code (This is placed in a function and called for each block I need to draw): CBrush br; CRect rect; rect.left = point.x - BLOCKWIDTH/2; rect.top = point.y - BLOCKHEIGHT/2; rect.right = point.x + BLOCKWIDTH/2; rect.bottom = point.y + BLOCKHEIGHT/2 - NODELENGTH; // I'm writing a Flow Chart application, so the following line draw // little 'nodes' at the top and bottom of each block pDC->MoveTo(point.x, point.y + BLOCKHEIGHT/2 - NODELENGTH); pDC->LineTo(point.x, point.y + BLOCKHEIGHT/2); br.CreateSolidBrush(RGB(0,200,0)); pDC->SelectObject(&br); pDC->Rectangle(rect); br.DeleteObject();

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        FillSolidRect is better because you pass in the brush as a parameter, instead of having to select it in and out. pDC->FillSolidRect(&rect, RGB(255,0,255)); Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

        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