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. Gradients

Gradients

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
8 Posts 5 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.
  • A Offline
    A Offline
    Archer282
    wrote on last edited by
    #1

    Can someone point me to an artical that shows you how to draw gradients on a DC?

    F T S R 5 Replies Last reply
    0
    • A Archer282

      Can someone point me to an artical that shows you how to draw gradients on a DC?

      F Offline
      F Offline
      f64
      wrote on last edited by
      #2

      Hi Check GradientFill() on the Win32 API documentation. Fabian

      1 Reply Last reply
      0
      • A Archer282

        Can someone point me to an artical that shows you how to draw gradients on a DC?

        T Offline
        T Offline
        TrungHuynh
        wrote on last edited by
        #3

        you can do follow: void CBMSButton::GradientFillRect(HDC hDC, RECT& rc, COLORREF crLight, COLORREF crDark) { TRIVERTEX vert[2]; GRADIENT_RECT gRect; vert [0].x = rc.left; vert [0].y = rc.top; vert [0].Red = GetRValue(crLight) << 8; vert [0].Green = GetGValue(crLight) << 8; vert [0].Blue = GetBValue(crLight) << 8; vert [0].Alpha = 0x0000; // It's no use for GradientFill vert [1].x = rc.right; vert [1].y = rc.bottom; vert [1].Red = GetRValue(crDark) << 8; vert [1].Green = GetGValue(crDark) << 8; vert [1].Blue = GetBValue(crDark) << 8; vert [1].Alpha = 0x0000; gRect.UpperLeft = 0; gRect.LowerRight = 1; GradientFill(hDC, vert, 2 , &gRect, 1, GRADIENT_FILL_RECT_V); } You must import library: #pragma message(" Automatically linking with MSIMG32.LIB library") #pragma comment(lib, "MSIMG32.LIB")

        1 Reply Last reply
        0
        • A Archer282

          Can someone point me to an artical that shows you how to draw gradients on a DC?

          S Offline
          S Offline
          Sumit Kapoor
          wrote on last edited by
          #4

          Hi Dear...Try this.. ---------------------------------------- CRect rect,rcClient; GetClientRect(rcClient); rect = rcClient; int r1=32,g1=108,b1=244; //Any start color int r2=5,g2=55,b2=165; //Any stop color for(int i=0;iFillSolidRect(i,0,1,rect.Height(),RGB(r,g,b)); } ------------------------------------------- This is not mine code, I'm also user of this code...but work nice... OK! Good Bye ---Sumit Kapoor--- sumit_kapoor1980@hotmail.com

          A 1 Reply Last reply
          0
          • S Sumit Kapoor

            Hi Dear...Try this.. ---------------------------------------- CRect rect,rcClient; GetClientRect(rcClient); rect = rcClient; int r1=32,g1=108,b1=244; //Any start color int r2=5,g2=55,b2=165; //Any stop color for(int i=0;iFillSolidRect(i,0,1,rect.Height(),RGB(r,g,b)); } ------------------------------------------- This is not mine code, I'm also user of this code...but work nice... OK! Good Bye ---Sumit Kapoor--- sumit_kapoor1980@hotmail.com

            A Offline
            A Offline
            Archer282
            wrote on last edited by
            #5

            yes, i found that artical earlier today, and i got it to work, but i had to put the code in the OnPaint overide but there is one thing i dont get about this formula r1 + (i * (r2-r1) / rect.Width()); i know what it does, and why its needed, but i dont understand how the writer came up with it.

            S 1 Reply Last reply
            0
            • A Archer282

              Can someone point me to an artical that shows you how to draw gradients on a DC?

              S Offline
              S Offline
              Sumit Kapoor
              wrote on last edited by
              #6

              hi.. for loop in above code consider < as HTML TAG so replace that with: for(int i=0;i

              1 Reply Last reply
              0
              • A Archer282

                yes, i found that artical earlier today, and i got it to work, but i had to put the code in the OnPaint overide but there is one thing i dont get about this formula r1 + (i * (r2-r1) / rect.Width()); i know what it does, and why its needed, but i dont understand how the writer came up with it.

                S Offline
                S Offline
                Sumit Kapoor
                wrote on last edited by
                #7

                Actually... The writer do very nice thing in this code.. as u can see.. we ca make shading from any color to other in fix area.. this is only possible if we change color according to side of area..that is what he is doing.. change color but with eyes on area.. OK bye... Never consider anything Impossible before trying to solve that..---Sumit Kapoor---

                1 Reply Last reply
                0
                • A Archer282

                  Can someone point me to an artical that shows you how to draw gradients on a DC?

                  R Offline
                  R Offline
                  Rick York
                  wrote on last edited by
                  #8

                  This article shows one method : http://www.codeproject.com/samples/fortune.asp[^] __________________________________________ a two cent stamp short of going postal.

                  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