Click here to Skip to main content
Click here to Skip to main content

Using color gradients as backgrounds in your dialogs and views

By , 9 Jun 2002
 

Gradients

Gradients are beautiful, have always been so and will continue being beautiful. Oops! What am I doing here? I guess I got carried away a little. Pardon me. Well seriously speaking, there are times when it would be nice to have a gradient background for our windows. I think the first time I remember seeing gradients was in the Setup programs generated by Install Shield. Even during the Windows 3.11 days, they had Setup programs that typically used a Blue gradient as their background. And recently while I have been making CP stats using PowerPoint, I use an Orange gradient as my presentation's background. Well creating gradients is not a big deal as I found out.

Horizontal gradients

This one uses two dark colors to create the gradient effect

This one uses green and white as the two border colors and a gradient is filled smoothly between these colors

Well, all you need to do is to override OnEraseBkgnd in your CWnd class. We start with one color and slowly change the RGB values till we end up with the other color. It's basically mathematics and I am not really good at maths. So the algorithm I have used might not be perfect and I apologize to you for that. But it portrays how to get a gradient effect which is what I wanted. If better mathematicians than me can give me an easier formula I'd be very happy about that.

CDialog::OnEraseBkgnd(pDC);

CRect rect;
GetClientRect(&rect);

int r1=127,g1=127,b1=56; //Any start color
int r2=5,g2=55,b2=165; //Any stop color

for(int i=0;i<rect.Width();i++)
{ 
    int r,g,b;
    r = r1 + (i * (r2-r1) / rect.Width());
    g = g1 + (i * (g2-g1) / rect.Width());
    b = b1 + (i * (b2-b1) / rect.Width());
    pDC->FillSolidRect(i,0,1,rect.Height(),RGB(r,g,b));
}


return true;

Vertical gradients

I use a black to red gradient here

This uses two fluorescent colors and I don't recommend this sort of combination as it hurts the eyes

Similar to the horizontal gradient we override OnEraseBkgnd

CDialog::OnEraseBkgnd(pDC);

CRect rect;
GetClientRect(&rect);

int r1=127,g1=127,b1=56; //Any start color
int r2=5,g2=55,b2=165; //Any stop color

for(int i=0;i<rect.Height();i++)
{ 
    int r,g,b;
    r = r1 + (i * (r2-r1) / rect.Height());
    g = g1 + (i * (g2-g1) / rect.Height());
    b = b1 + (i * (b2-b1) / rect.Height());
    pDC->FillSolidRect(0,i,rect.Width(),1,RGB(r,g,b));
}


return true;

Diagonal gradients

A beautiful bluish gradient. Just like those Installshield backgrounds

Pink, for the *ahem* ladies here :-)

Diagonal gradients are slightly tricky. Unlike horizontal and vertical gradients we are not handling rectangles here. So we will not be able to use FillSolidRect for our purpose. In fact we need to use MoveTo and LineTo in a rather heavy loop. Being a novice at this GDI stuff, I put all my code in OnEraseBkgnd. The painting was so slow that it almost seemed like an animation. I was disappointed to say the least. That's when some of the gurus here suggested that I use a memory DC. So I used CreateCompatibleDC to create a memory DC and drew directly onto this DC. Then I used BitBlt to blast it into the actual DC. Well, there was considerable improvement. Now the animation effect was gone. But still there was a very noticeable flicker. This was really bad. But there was too much looping in the painting code. That's when I got this idea of keeping a CBitmap member. During initialization I'll draw all my gradient stuff into this CBitmap. 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.

CDialog::OnEraseBkgnd(pDC);

CRect rect;
GetClientRect(&rect);

CDC dc2;
dc2.CreateCompatibleDC(pDC);
CBitmap *oldbmap=dc2.SelectObject(&m_bitmap);

/*We copy the bitmap into the DC*/ 
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc2,0,0,SRCCOPY);
dc2.SelectObject(oldbmap);

return true;

And I wrote a function called MakeBitmap which creates the gradient bitmap and puts it into our CBitmap member. In my dialog based application I called MakeBitmap inside OnInitDialog. In your SDI programs I guess you are supposed to call MakeBitmap inside OnInitialUpdate.

void CYourClassName::MakeBitmap()
{
    CPaintDC dc(this);
    CRect rect;
    GetClientRect(&rect);

    int r1=245,g1=190,b1=240;
    int r2=130,g2=0,b2=0;

    int x1=0,y1=0;
    int x2=0,y2=0;

    CDC dc2;
    dc2.CreateCompatibleDC(&dc);

    if(m_bitmap.m_hObject)
        m_bitmap.DeleteObject();
    m_bitmap.CreateCompatibleBitmap(&dc,rect.Width(),
        rect.Height());

    CBitmap *oldbmap=dc2.SelectObject(&m_bitmap);

    while(x1 < rect.Width() && y1 < rect.Height())
    {
        if(y1 < rect.Height()-1)
            y1++;
        else
            x1++;

        if(x2 < rect.Width()-1)
            x2++;
        else
            y2++;

        int r,g,b;
        int i = x1+y1;
        r = r1 + (i * (r2-r1) / (rect.Width()+rect.Height()));
        g = g1 + (i * (g2-g1) / (rect.Width()+rect.Height()));
        b = b1 + (i * (b2-b1) / (rect.Width()+rect.Height()));

        CPen p(PS_SOLID,1,RGB(r,g,b));
        CPen *oldpen = dc2.SelectObject(&p); 

        dc2.MoveTo(x1,y1);
        dc2.LineTo(x2,y2);

        dc2.SelectObject(oldpen);
    } 

    dc2.SelectObject(oldbmap);

}

Conclusion

All the screenshots in this article have been resized using Adobe Photoshop 6 and I'd like to thank Ravi Bhavnani for his image resizing tips.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Nish Sivakumar
United States United States
Member
Nish is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
 
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - www.voidnish.com where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff - blog.voidnish.com.
 
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.
 
Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.
 
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralWow!memberWong Shao Voon28 Jan '12 - 16:27 
This article is written before I joined CP in 2002! Kudos to Nish again.
 
Got my 5. Just what I needed (gradient formula)! Smile | :)
GeneralRe: Wow!mvpNishant Sivakumar29 Jan '12 - 4:34 
Well, I wrote it 10 years ago Smile | :)
 
I don't even remember this code anymore.
Regards,
Nish
My technology blog: voidnish.wordpress.com

QuestionDll ErrormemberNeeraj_ji23 Nov '06 - 21:21 
Hello Sir
I just want to discussed one problem that is: I created on Dll in VC++ 6.0 as well as in VC++.Net 2003.When i set the date of system like i set year 2075 then the application giving Error.
 
Plz can you Help me.
 

Thanks & Regards
 
hi!!

GeneralDiagonal GradientmemberTom Moore28 Sep '05 - 7:53 
I copied the code and ran the program to make a Diagonal Gradient,
I get these error messages Confused | :confused:
 
Please can someone tell me where im going wrong!
 
Tom
GeneralRe: Diagonal GradientmemberWes Aday28 Sep '05 - 9:06 
It would be more helpful if you posted the error messages you are getting.
 
If a wizard fails to cast an enchantment correctly, is that a mis-spelling?
 
Never argue with an idiot. They will drag you down to their level where they are an expert.
Generalfunny stuff manmemberTuPacMansur9 Sep '05 - 18:10 
hahahaha...
"I have only started on this GDI stuff. But it's truly an amazing field. I wish I had started on this area earlier. Now I'll always be behind times. And then I haven't started with GDI+ yet Frown | :-( "
 
thats funny..
 
Umer Mansoor
GeneralA small problemmemberrajani_sta17 Jul '05 - 23:17 
Hi,
I pasted your code in my application, it works nicely. But a small problem-
 
I have a start button in my dialog. If user clicks on it, a set of controls including buttons, icons will be visible. The problem is that, the contols flicker for a while before they display. This is really bad looking. Even while hiding these controls, the same problem occurs.
Pls help me in this matter.
Thanking you,
Rajani
GeneralThaank you...memberAlfonso Bastias7 Oct '04 - 12:15 
Just what I was looking for.... Smile | :)
GeneralGood but a small problem!membercheenu_200230 Jun '04 - 1:02 
Thanx for such a nice code.I have two querrie.
1.When I maximise the dialog box, there is a patch of color, of the size of the dialog box when it was opened.If I fully minimise & then maximise, this problem is not there. What to do?
2.When I used the diagonal shading code, I getting an error that m_bitmap is not declared, like that. Where should it be declared.
 
I am a beginner. So,help me out. Thanx.
 
Srini
Questionand OpenGL?sussh.gonzalez4 May '04 - 1:06 
How can I do this for OpenGL backgrounds? Confused | :confused:
 
I have an OpenGL view and I need to put the same background I have alredy used in GDI views. I need a similar way to draw a colored and filled rectangle in an OpenGL view...
 
Any help? Any sample code? Thanks.

AnswerRe: and OpenGL?memberSonny Aman25 Apr '07 - 20:13 
hey gonzalez,
 
you can use the following code to draw a radiant background:
//////////////
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);//bottom color
glVertex3f (-1.0, -1.0, 0.0);
glVertex3f (1.0, -1.0, 0.0);
glColor3f(0.0f,1.0f,0.0f);//top color
glVertex3f (1.0, 1.0, 0.0);
glVertex3f (-1.0, 1.0, 0.0);
glEnd();
///////////////////
 
this can be put in a function say drawBackground() and the color values can
be set from user input.
 
dont forget to use the following onsize:
glOrtho(-1.0f,1.0f,-1.0f,1.0f,1.0f,-1.0f);
 
hope it may help you.
 
Smile | :)
 
'life is like a ten speed bike,most of us having gears
we ne never use' ... i want
to try those.

GeneralRe: and OpenGL?memberHugo GC26 Jul '07 - 1:31 
Thank you, it helps...
 
h.gonzalez
GeneralVery good.But ...memberguosheng11 Mar '04 - 15:18 
Thank you very much.It is very useful for me.
But I meet a problem when I pasted your code into my project.
In the Diagonal gradients part,I wanted to make a resizable application.So I pasted the MakeBitmap function called inside OnInitDialog into my project and called it inside OnSize. But when I run it,there was nothing on the background unless I called Inverlitate.
Why?
 
----------------------
I am from a non-English country,so if you can mail me,i would be very thankful.
GeneralStatic control problemmemberrjo290914 Feb '04 - 7:10 
Hi ....
 
I tried to use your code to create a gradient dialog background, but I have problems when I put static controls. The background of these static controls cannot merge with the dialog background.
 
What can I do about it? thanks in advance
GeneralVery good !!.. but I have a problem....sussDevPark28 Oct '03 - 16:10 
Hi Nish,
I'm Park.
 
I pasted your code into OnEraseBkgnd(), and it works well.
But, I'm using OpenGL functions and libraries, So I have code following.
When I use them, they override gradient background of yours. So your beautiful background is disappearing.
What can I do for that problem??Confused | :confused: Confused | :confused:
Please answer me... vulcan31@hanmail.net
--------------------------------------------
PIXELFORMATDESCRIPTOR object,
SetPixelFormat(m_hDC,pixelformat,&pfd);
m_hRC = wglCreateContext(m_hDC);
wglMakeCurrent(m_hDC,m_hRC);
glClearColor(0.0f, 1.0f, 1.0f, 0.0f);
---------------------------------------------
GeneralExcelentsussDario Diament23 Jul '03 - 6:06 
Excelent! It gave an excelent idea to use a gradient animation affect with some borders of a control i was doing in c#.
 
congrats.
GeneralRe: ExcelenteditorNishant S23 Jul '03 - 15:26 
Hi Dario
 
Glad to be of help
 
Nish Smile | :)
 

"I'm a bit bored at the moment so I'm thinking about writing a new programming language" - Colin Davies
 
My book :- Summer Love and Some more Cricket [New Win]
Review by Shog9 Click here for review[NW]

GeneralBanded outputmemberthesentinel31 Mar '03 - 23:32 
A really nice effort Smile | :) . The only problem is that the gradient seems to have a banded appearance, which depending on the colours used can make it appear incorrect. If it can be smoother than great!
GeneralRe: Banded outputeditorNishant S23 Jul '03 - 15:29 
thesentinel wrote:
The only problem is that the gradient seems to have a banded appearance
 
Only in the screen shots. The actual gradient looks much much better.
 
Nish
 

"I'm a bit bored at the moment so I'm thinking about writing a new programming language" - Colin Davies
 
My book :- Summer Love and Some more Cricket [New Win]
Review by Shog9 Click here for review[NW]

GeneralFuture Endeavor . . . .memberZac Howland17 Jun '02 - 9:40 
Hey Nish
Great article. Here is something to get your juices flowing . . . . A few *cough* years ago, I wrote a Visual Basic application that solved a simple brain teaser (it was a Governor's School assignment when I was in high school). I got bored with doing just the basic assignment . . . so I added some flare (database access, gradient colored form, and a few other bells and whistles). I have since ported this to C++. Anyway, my idea for you is to extend this article to add a timer and change the gradient scheme based on some random number generator, etc. I still have my code for this somewhere . . . but it might be fun for you to fool around with Wink | ;)
 
Zac
 
"If I create everything new, why would I want to delete anything?"
GeneralLooks can be deceptive...memberMarc Clifton10 Jun '02 - 17:06 
but distinctions are clear (apologies to Peter Gabriel)
 
These gradients look great by themselves. I added the code to program I'm writing for a customer and the result was attrocious (sp?). Static controls showed their ugly backgrounds (and I meticulously set my statics to the same height everywhere), group boxes lost their nice 3D definition, and the affect was quite jarring when the spaces between listboxes and buttons got filled with color. The "smoothness" of the GUI was lost.
 
A long time ago, someone told me that space is a really important consideration when designing GUI's. Filling the space with a gradient takes away from the spatiousness of the interface.
 
Phooey. Gradients looks so beautiful by themselves.
 
PS - I really like your articles, Nish. Always thought provoking.
 
Marc
GeneralRe: Looks can be deceptive...memberNish - Native CPian10 Jun '02 - 17:25 
Hello Marc
 
Outside of a splash screen or an about box gradient backgrounds might not be a good idea. And as you said every othet control will have to be similarly subclassed and their backgrounds made a gradient Smile | :)
 
Not easy that, eh?
 
And thanks Smile | :)
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralgradientsmemberGoran Mitrovic10 Jun '02 - 13:22 
Do we really need more gradients in utilities/applications?
Frown | :( br />
 
- Goran.

GeneralRe: gradientsmemberChris Losinger10 Jun '02 - 13:44 
just wait... in 3 years, "solid" will be the cool UI design feature. people will look back on all those gradients and chuckle.
 
-c
 

Cheap oil. It's worth it!
GeneralRe: gradientsmemberNish - Native CPian10 Jun '02 - 15:17 
Chris Losinger wrote:
just wait... in 3 years, "solid" will be the cool UI design feature. people will look back on all those gradients and chuckle.
 
That's very probable situation Smile | :)
In the 16 bit windows days we had flat controls. Then with 32 bit windows we had all those 3d controls. What happens? Everyone starts sub-classing controls and gives them a flat look which is also sometimes referred to as the cool look. Flat == Cool!!!! Funny huh? Then MS themselves starts using flat menus and flat toolbars.
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: gradientsmemberNish - Native CPian10 Jun '02 - 15:13 
Goran Mitrovic wrote:
Do we really need more gradients in utilities/applications?
 
Well, perhaps in About boxes and Splash screens. Outside that gradients might only serve as an annoyance Smile | :)
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: gradientsmemberGoran Mitrovic11 Jun '02 - 7:56 
Cannot agree. Gradients were kind of fun back in late eighties when you had palettes with only 64 colors made out of 4 bits per component (I'm talking about Amigas, of course), not to mention that we all were some 15 years younger back then. Smile | :) Today, gradients only show bad taste and constant, sad deficiency of new ideas. Sorry...

 
- Goran.

GeneralRe: gradientsmemberNish - Native CPian11 Jun '02 - 14:48 
Oh well! They were fun when I was coding them first time. Smile | :)
 
Thanks anyway
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: gradientsmemberFranzKlein12 Jun '02 - 22:46 
Hey, I haven't used any gradients in any of my applications yet.
 
So please don't slam gradients until I have also gotten onto the bandwagon and also have used them.
 
I am sticking to 3d controls. In ten years time they will be cool again.
 
Big Grin | :-D
GeneralRe: gradientsmemberNish - Native CPian12 Jun '02 - 23:50 
FranzKlein wrote:
So please don't slam gradients until I have also gotten onto the bandwagon and also have used them
 
Heheh. Cool! Someone liked my gradients after all Smile | :)
 
FranzKlein wrote:
I am sticking to 3d controls. In ten years time they will be cool again.
 
Good luck man Big Grin | :-D
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: gradientsmemberMate7 Jun '03 - 14:00 
Does it exist a more boring color than a flat one? Gradient is the most pleasant background painting ever exist, if you can develop something better, go on budy!
Suspicious | :suss:
GeneralGDI+memberChristian Graus10 Jun '02 - 0:52 
GDI+ does all this and more for free - you should check it out.

 
Christian
 
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
GeneralRe: GDI+memberNish - Native CPian10 Jun '02 - 0:58 
I just started on this stuff CG.
Prob is I don't have VS.NET here at work.
And I won't be able to download and install the PSDK Frown | :-(
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: GDI+memberChristian Graus10 Jun '02 - 1:14 
Without the SDK, you're programming for 1996. Would you like me to send it to you on CD ?

 
Christian
 
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
GeneralRe: GDI+memberNish - Native CPian10 Jun '02 - 1:14 
Christian Graus wrote:
Without the SDK, you're programming for 1996. Would you like me to send it to you on CD ?
 
No CG. I have made the required moves here and if all goes well I'll get a copy of VS .NET within two weeks.
 
In the background I am also trying to coax my company to get an MSDN subscription, now that my attempts to get them to buy VS .NET has totally failed!!!
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: GDI+memberRama Krishna10 Jun '02 - 1:36 
Yes I really love LinearGradientBrush & TextureBrush. They are cool.
GeneralRe: GDI+memberNish - Native CPian10 Jun '02 - 1:28 
Rama Krishna wrote:
Yes I really love LinearGradientBrush & TextureBrush. They are cool.
 
Cry | :(( Cry | :(( Cry | :((
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: GDI+memberAlexander Kourov17 Jun '02 - 16:42 
Nish, why you still not got a pirate CD with VS.NET? In my country (Russia) I purchased a copy of VS.NET for $2! Mail me about it, this question is interested for me...
Sorry for wrong english.
GeneralRe: GDI+memberNishant S18 Jun '02 - 18:28 
Alexander Kourov wrote:
In my country (Russia) I purchased a copy of VS.NET for $2!
 
You russians are so lucky!
 
Alexander Kourov wrote:
Sorry for wrong english.
 
No probs at all
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

GeneralRe: GDI+memberAlexander Kourov19 Jun '02 - 17:04 
Yeah, imagine you are coming to a large serious shop with a lot of bars with pirate CDs. Hundreds beauty CDs with attractive covers for $2 only. And it's absolutely legally and the shop is in a center of a city with two millions of people. There are so much different software, and discs made really highly qualitative. Pirates provide their discs with suitable shells with comments and cracks and additional info ( here's a sample screenshot - not the best pirate shell) - it's almost industry...
Sorry for deviation from topic's theme...
GeneralRe: GDI+memberNishant S19 Jun '02 - 17:17 
Alexander Kourov wrote:
( here's a sample screenshot - not the best pirate shell)
 
OMG | :OMG: OMG | :OMG: OMG | :OMG:
 
That's amazing!!!
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

GeneralRe: GDI+memberChristian Graus19 Jun '02 - 17:49 
Nishant S wrote:
You russians are so lucky!
 
Why - because they steal software ? He does not OWN VS.NET.

 
Christian
 
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
 
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
GeneralRe: GDI+memberNishant S19 Jun '02 - 18:11 
Christian Graus wrote:
Why - because they steal software ? He does not OWN VS.NET.
 
I know CG, I know! Oh well, I won't win this argument, so I won't even argue! But I hope you'll understand that the day I earn money nice and proper I'll go fully legal. Right it's not even worth trying! MS won't lose anything in a way since even otherwise I wouldn't be able to afford any of this stuff!
 
I dunno about Russia though. I kinda fancied that Russians were a rich people!
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

GeneralRe: GDI+memberChristian Graus19 Jun '02 - 18:23 
Nishant S wrote:
MS won't lose anything in a way since even otherwise I wouldn't be able to afford any of this stuff!
 
Yeah, I know. M$ doesn't lose anything because you would not buy it anyhow, plus they are rich and can afford for people to pirate their software, etc, etc, etc.
 
Nishant S wrote:
I kinda fancied that Russians were a rich people!
 
You WHAT ? Have you heard of the Cold War ? Communism ? Stalin ? The Russian economy is in tatters, they are headed back towards being a 3rd world country. The only reason they rose above that is that Stalin sold all their food and let his people starve to pay for industrialisation.

 
Christian
 
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
 
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
GeneralRe: GDI+memberJinhyuck Jung12 Nov '02 - 21:41 
I think GDI+ is too heavy.
 
they can render jpg/gif/bmp. but, you can implement jpg/gif/bmp renderer using IPicture interfaces. it needs anything further.
and, GradientFill API can do the same. why have to use those heavy stuffs?
i don't understand.Smile | :)
GeneralRe: GDI+memberChristian Graus13 Nov '02 - 0:13 
To be honest, I've never used IPicture, I needed to write a full paint program and GDI+ was perfect. If IPicture is lighter and does the little you want, then I say go for it Smile | :)
 
Christian
 
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
 
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
 
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

GeneralRe: GDI+ (please tell me how)memberchachoo19 Feb '04 - 4:14 
Hi ChristianSmile | :)
 
I am a novice in this stuff. I found your articles on GDI+ of great help.
Hope you will help me here.
 
I want to use GDI+ for gradients as backgrounds in my MFC based dialogs.
Currently, when not using GDI+, I create a HBRUSH and use it in OnCtlColor method.
 
Now, using GDI+ it seems I would be making some LinearGradientBrush or TextureBrush ... but how would I be using it Confused | :confused:
 
Thanx
 


GeneralUsefull...memberJean-Michel LE FOL9 Jun '02 - 23:22 
Usefull on NT4 and Win95.
For Win98 and Win2k, Microsoft added the GradientFill API.
 
From MSDN :
The GradientFill function fills rectangle and triangle structures.
BOOL GradientFill(
  HDC hdc,                   // handle to DC
  PTRIVERTEX pVertex,        // array of vertices
  ULONG dwNumVertex,         // number of vertices
  PVOID pMesh,               // array of gradients
  ULONG dwNumMesh,           // size of gradient array
  ULONG dwMode               // gradient fill mode
); 

GeneralRe: Usefull...memberNish - Native CPian10 Jun '02 - 0:57 
Hello Jean
 
Can it create diagonal gradients too?
 
Nish
 


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: Usefull...memberAnonymous10 Jun '02 - 4:53 
Yes - do it as two gradient triangles with the adjacent edges the same colour.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 10 Jun 2002
Article Copyright 2002 by Nish Sivakumar
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid