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. Device Context

Device Context

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
9 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.
  • P Offline
    P Offline
    Pazzuzu
    wrote on last edited by
    #1

    Hi Guys, Iam working on a project on MFC & came across this problem. Wanted to use the devicecontext function "DrawEdge" with the following set properties.It worked fine ,but the colour of the drawnEdge was always "black",eventhough I tried to set a brush(with a colour). Any idea ,How I can use the "DrawEdge" function so that I can draw with a particular colour instead of "black"..... Don't want to use the "DrawFame" function of the deviceContext,as I want the "Edge_BUMP" effect.(See code:) Or Is there anyother function in the "DeviceContext" which performs such an action. CRect rect; rect3.SetRect(10,10,300,100); CBrush brushBlue(RGB(255,112,0)); pDC->SelectObject(&brushBlue); pDC->DrawEdge(rect,EDGE_BUMP,BF_RECT); Thanks....

    B 1 Reply Last reply
    0
    • P Pazzuzu

      Hi Guys, Iam working on a project on MFC & came across this problem. Wanted to use the devicecontext function "DrawEdge" with the following set properties.It worked fine ,but the colour of the drawnEdge was always "black",eventhough I tried to set a brush(with a colour). Any idea ,How I can use the "DrawEdge" function so that I can draw with a particular colour instead of "black"..... Don't want to use the "DrawFame" function of the deviceContext,as I want the "Edge_BUMP" effect.(See code:) Or Is there anyother function in the "DeviceContext" which performs such an action. CRect rect; rect3.SetRect(10,10,300,100); CBrush brushBlue(RGB(255,112,0)); pDC->SelectObject(&brushBlue); pDC->DrawEdge(rect,EDGE_BUMP,BF_RECT); Thanks....

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      Try changing the pen color too. Many times, the edges of objects are drawn using the pen instead of the brush.

      P 1 Reply Last reply
      0
      • B Blake Miller

        Try changing the pen color too. Many times, the edges of objects are drawn using the pen instead of the brush.

        P Offline
        P Offline
        Pazzuzu
        wrote on last edited by
        #3

        Yes,I tried as follows,selecting a pen first.But still It is drawing "black" CRect rect3; rect3.SetRect(10,10,300,100); CPen newPen(PS_SOLID,1,RGB(255,0,0)); CPen *pOldPen = pDC->SelectObject(&newPen); pDC->DrawEdge(rect3,EDGE_BUMP,BF_RECT);

        B 1 Reply Last reply
        0
        • P Pazzuzu

          Yes,I tried as follows,selecting a pen first.But still It is drawing "black" CRect rect3; rect3.SetRect(10,10,300,100); CPen newPen(PS_SOLID,1,RGB(255,0,0)); CPen *pOldPen = pDC->SelectObject(&newPen); pDC->DrawEdge(rect3,EDGE_BUMP,BF_RECT);

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          The function is probably setting element colors itself using GetSysColor(), so you might not be able to override the colors, even though you have set them into the DC. You will have to make your own 'DrawEdge' function.

          P 1 Reply Last reply
          0
          • B Blake Miller

            The function is probably setting element colors itself using GetSysColor(), so you might not be able to override the colors, even though you have set them into the DC. You will have to make your own 'DrawEdge' function.

            P Offline
            P Offline
            Pazzuzu
            wrote on last edited by
            #5

            Do you have any ideas or suggestions....

            B 1 Reply Last reply
            0
            • P Pazzuzu

              Do you have any ideas or suggestions....

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #6

              Since you want to control the colors yourself, I suggest setting a pen and making a series of MoveTo and LineTo calls on your own - just do all the drawing the DrawEdge would have done for you on your own.

              P 1 Reply Last reply
              0
              • B Blake Miller

                Since you want to control the colors yourself, I suggest setting a pen and making a series of MoveTo and LineTo calls on your own - just do all the drawing the DrawEdge would have done for you on your own.

                P Offline
                P Offline
                Pazzuzu
                wrote on last edited by
                #7

                I choosed "DrawEdge" co's, with that, I can set the edges to bumped,etched or raised,which I can't do with "LineTo" or "MoveTo" functions.

                B 1 Reply Last reply
                0
                • P Pazzuzu

                  I choosed "DrawEdge" co's, with that, I can set the edges to bumped,etched or raised,which I can't do with "LineTo" or "MoveTo" functions.

                  B Offline
                  B Offline
                  Blake Miller
                  wrote on last edited by
                  #8

                  Yes you can. You might need to change the pen color a couple times and draw more than one line next to each other, but BUMPED, ETCHED and RAISED are just combinations of shading using pens of different colors drawn next to each other. Long before 'DrawEdge' existed (back in Windows 3.1 days) we used to do this all the time before '3-D controls' ever existed. Now MS has just added it in as part of the GDI to make it easier for people to achieve the same effect with a single function call. The DrawEdge will also use the current user's selected colors so it obtains the correct shading effect. Since you want to override the colors, you will have to provide the effects yourself. As an example, here is some MFC source code: void CDC::FillSolidRect(int x, int y, int cx, int cy, COLORREF clr) { ASSERT_VALID(this); ASSERT(m_hDC != NULL); ::SetBkColor(m_hDC, clr); CRect rect(x, y, x + cx, y + cy); ::ExtTextOut(m_hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); } void CDC::Draw3dRect(LPCRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight) { Draw3dRect(lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight); } void CDC::Draw3dRect(int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight) { FillSolidRect(x, y, cx - 1, 1, clrTopLeft); FillSolidRect(x, y, 1, cy - 1, clrTopLeft); FillSolidRect(x + cx, y, -1, cy, clrBottomRight); FillSolidRect(x, y + cy, cx, -1, clrBottomRight); } You could create something similar to get the other two effects this one does not draw.

                  P 1 Reply Last reply
                  0
                  • B Blake Miller

                    Yes you can. You might need to change the pen color a couple times and draw more than one line next to each other, but BUMPED, ETCHED and RAISED are just combinations of shading using pens of different colors drawn next to each other. Long before 'DrawEdge' existed (back in Windows 3.1 days) we used to do this all the time before '3-D controls' ever existed. Now MS has just added it in as part of the GDI to make it easier for people to achieve the same effect with a single function call. The DrawEdge will also use the current user's selected colors so it obtains the correct shading effect. Since you want to override the colors, you will have to provide the effects yourself. As an example, here is some MFC source code: void CDC::FillSolidRect(int x, int y, int cx, int cy, COLORREF clr) { ASSERT_VALID(this); ASSERT(m_hDC != NULL); ::SetBkColor(m_hDC, clr); CRect rect(x, y, x + cx, y + cy); ::ExtTextOut(m_hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); } void CDC::Draw3dRect(LPCRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight) { Draw3dRect(lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight); } void CDC::Draw3dRect(int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight) { FillSolidRect(x, y, cx - 1, 1, clrTopLeft); FillSolidRect(x, y, 1, cy - 1, clrTopLeft); FillSolidRect(x + cx, y, -1, cy, clrBottomRight); FillSolidRect(x, y + cy, cx, -1, clrBottomRight); } You could create something similar to get the other two effects this one does not draw.

                    P Offline
                    P Offline
                    Pazzuzu
                    wrote on last edited by
                    #9

                    Hi Blake, Appreciate your reply.But should admit that althought I understood what u have written,have no idea how to achieve that. Just to make my side clear, I don't want to fill the rectangle with a partiular colour,would just want to draw the 4 lines with bumped effect. In the following sample code,Iam trying to draw a rectangle with redcolour. Would appreciate it if you could show it this code segment how I could achieve the bumped effect as well. void CEx03aView::OnDraw(CDC* pDC) { CPen newPen(PS_SOLID,2,RGB(255,0,0)); CPen *pOldPen = pDC->SelectObject(&newPen); //Top Line pDC->MoveTo(10,100); pDC->LineTo(150,100); //Right Line pDC->MoveTo(150,100); pDC->LineTo(150,250); //Bottom Line pDC->MoveTo(150,250); pDC->LineTo(10,250); //Left Line pDC->MoveTo(10,250); pDC->LineTo(10,100); } Thanks..

                    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