![]() While(x1 < rect.Width() & y1 < rect.Height()) M_bitmap.CreateCompatibleBitmap(&dc,rect.Width(),ĬBitmap *oldbmap=dc2.SelectObject(&m_bitmap) Now all I needed to do in OnEraseBkgnd was to BitBlt this bitmap into the DC and voila, things were fast and smooth once again. During initialization I'll draw all my gradient stuff into this CBitmap. That's when I got this idea of keeping a CBitmap member. But there was too much looping in the painting code. But still there was a very noticeable flicker. Well, there was considerable improvement. Then I used BitBlt to blast it into the actual DC. ![]() So I used CreateCompatibleDC to create a memory DC and drew directly onto this DC. That's when some of the gurus here suggested that I use a memory DC. The painting was so slow that it almost seemed like an animation. Being a novice at this GDI stuff, I put all my code in OnEraseBkgnd. In fact we need to use MoveTo and LineTo in a rather heavy loop. So we will not be able to use FillSolidRect for our purpose. Unlike horizontal and vertical gradients we are not handling rectangles here. Just like those Installshield backgroundsĭiagonal gradients are slightly tricky. Int r1= 127,g1= 127,b1= 56 // Any start color int r2= 5,g2= 55,b2= 165 // Any stop color for( int i= 0 iFillSolidRect( 0,i,rect.Width(), 1,RGB(r,g,b)) Ī beautiful bluish gradient. If better mathematicians than me can give me an easier formula I'd be very happy about that. But it portrays how to get a gradient effect which is what I wanted. So the algorithm I have used might not be perfect and I apologize to you for that. It's basically mathematics and I am not really good at maths. We start with one color and slowly change the RGB values till we end up with the other color. Well, all you need to do is to override OnEraseBkgnd in your CWnd class. ![]() This one uses green and white as the two border colors and a gradient is filled smoothly between these colors This one uses two dark colors to create the gradient effect Well creating gradients is not a big deal as I found out. And recently while I have been making CP stats using PowerPoint, I use an Orange gradient as my presentation's background. Even during the Windows 3.11 days, they had Setup programs that typically used a Blue gradient as their background. I think the first time I remember seeing gradients was in the Setup programs generated by Install Shield. Well seriously speaking, there are times when it would be nice to have a gradient background for our windows. Oops! What am I doing here? I guess I got carried away a little. Gradients are beautiful, have always been so and will continue being beautiful. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |