Click to See Complete Forum and Search --> : Draw Program/Dialog Box
April 13th, 1999, 11:54 AM
As a newcomer to VC++, I need a little help. Have added menu item and toolbar button to a basic drawing program. Both of these bring up a dialog box with 4 radio buttons for changing the drawing color.
Have been able to get the program to display the dialog and it appears to select a new color, but when I go back to drawing, color has not changed.
Can anyone provide a hint or snippet of code for how I can change the drawing color?
Thanks in advance for any assistance.
Cathy
April 13th, 1999, 01:27 PM
I believe you have to get the device context and select a brush with that color.
void CFileView::OnDraw(CDC* pDC)
{
CBrush *pOldBrush, RedBrush;
RedBrush.CreateSolidBrush(RGB(255, 0, 0));
pOldBrush = pDC->SelectObject(&RedBrush);
// draw stuff
pDC->SelectObject(pOldBrush);
}
Hope this gets you pointed in the right direction. It seems like there are a lot of examples out there. But I can't remember any right now.
April 13th, 1999, 01:37 PM
Many thanks for your assistance! Will give this a try when I get to the lab later today. Again, as a beginner, I REALLY appreciate someone taking the time to lend me a hand.
Cathy
April 13th, 1999, 01:50 PM
http://msdn.microsoft.com/library/devprods/vs6/vc++/vcsample/_core_graphical_display_objects_samples.htm
Here is a link to msdn samples that might help.
April 15th, 1999, 01:16 AM
Another thing to check: when your dialog processes the change of color, is this data saved to the view that does
the drawing before the dialog destructor is called? It is posible for the dialog to have the new choice, yet not
have the view also be told of the new color selection.
You do need to create a brush of the desired color, and select it into the device context (DC). You can use the
DC passed in to the OnDraw method (I believe it is a pointer to a CDC object, if my memory serves me correctly).
ALWAYS delete your GDI objects, of which a brush is one type, when you are done drawing. GDI has a limited
number of items it can keep track of; after that threshhold is passed, results are unpredictable.
The various MS samples describe how to do this, as does the Petzold "Programming Windows 95" book. I'm sure
just about any Windows graphics book will cover these basics well enough for you to do want you need for your
application.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.