Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using vc++/mfc to draw a round rectangle (OnPaint()),Can anyone help me to add shadow to a rectangle on right and bottom edges ?
Posted
Comments
Sergey Alexandrovich Kryukov 13-Dec-11 3:06am    
"Round rectangle"? :-)
OK, what's the problem?
--SA

"Round rectangle" is oxymoron. Perhaps yours is rounded. A simple model of a shadow is :-).
A simple model of a shadow is a slightly fuzzy semi-transparent image of the elevated shape, not the edges, shifted according to light source. It is not quite realistic but is commonly accepted.

I only found this code: Fuzzy DropShadows in GDI+[^]. Sorry, this is C# and .NET, but as the algorithm is based on GDI+, you can easily translate it; you only need the algorithm.

—SA
 
Share this answer
 
Comments
Emilio Garavaglia 14-Dec-11 11:00am    
""Round rectangle" is oxymoron...."
In plain English yes ... in MS-APIish no: http://msdn.microsoft.com/en-us/library/aa929212.aspx
Sergey Alexandrovich Kryukov 15-Dec-11 5:59am    
Ha-ha, good point. Here is the thing: this is not even a language. There is not such word "Rect", so "Round" could be another abbreviation. I prefer .NET approach where abbreviations are highly discouraged by naming conventions, for a good reason.

Thank you,
--SA
I guess you have done it without using GDI. your code may look somewhat like below.

C++
.....
dc.SelectObject( &somebrush );
dc.RoundRect( x1, y1, x2, y2, p1, p2 );
......

now to bring the shadow effect change the code as below.

C++
......
// New codes Starts here
CBrush shdwBrsh;
shdwBrsh.CreateSolidBrush( GetSysColor( COLOR_BTNSHADOW ));
dc.SelectObject( &shdwBrsh );
dc.RoundRect( x1+5, y1+5, x2+5, y2+5, p1, p2 );
// New codes Ends here

dc.SelectObject( &somebrush );
dc.RoundRect( x1, y1, x2, y2, p1, p2 );
............
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Dec-11 6:01am    
Well... where is the semi-transparency which a shadow should have?
--SA
Resmi Anna 15-Dec-11 6:16am    
without GDI this is the maximum shadow effect that we can have. COLOR_BTNSHADOW gives the shadow effect that suits for for a normal MFC dialog box

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900