MFC Programming using SDI
-
HI, I am new to mFC programming . I ahve been trying to create an application where a figure is drawn with a default colour and then user can select from a range of colours in the menu. The problem wid my application is that it is not accepting the new colour when i check it. It is supposed to draw the new figure in a different colour when I select a colour from the menu. I might be going wrong somewhr. could anyone tell me how to go about doing what I am trying to implement. Thanks U get wht u Give
-
HI, I am new to mFC programming . I ahve been trying to create an application where a figure is drawn with a default colour and then user can select from a range of colours in the menu. The problem wid my application is that it is not accepting the new colour when i check it. It is supposed to draw the new figure in a different colour when I select a colour from the menu. I might be going wrong somewhr. could anyone tell me how to go about doing what I am trying to implement. Thanks U get wht u Give
Are you drawing the figure in the
OnDraw()
orOnPaint()
method? Where are you storing the new color value? Is it being used?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
Are you drawing the figure in the
OnDraw()
orOnPaint()
method? Where are you storing the new color value? Is it being used?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
I am using the ondraw function. I have a variable called color in the doc class and a function which returns the current colour. I ma calling this function in the ondraw function to get the colour. Below is the code of ondraw function and the doc class..
void CFiguresdiView::OnDraw(CDC* pDC) { CFiguresdiDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here COLORREF m_nColor = pDoc->GetCurrentColor(); CBrush brush (m_nColor); int x1 = 100; int y1 = 100; int x2 = 300; int y2 = 400; CRect rect (x1, y1, x2, y2); pDC->FillRect (rect, &brush); }
In the document class i ahve the following code.COLORREF CFiguresdiDoc::GetCurrentColor() { return m_nColor; } void CFiguresdiDoc::OnColorsRed() { m_nColor=RGB (255,0,0); } void CFiguresdiDoc::OnColorsGreen() { m_nColor = RGB(0,255,0);// TODO: Add your command handler code here } void CFiguresdiDoc::OnUpdateColorsGreen(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 0)); } void CFiguresdiDoc::OnUpdateColorsRed(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 255));// TODO: Add your command update UI handler code here }
m_nColor is of type COLORREF. i AHVE SET THE DEFAULT COLOR AS RED . It is set in the onNew Document function. IF i try doing the same thing on OnButtonDown event of mouse in the client area the color does change. I am not able to figure out how i can click on the colour in the menu and as soon as i click the menu option the Figure gets redrawn with the chosen colour. I probably need to write some message map but i cant figure out how. Thanks david -
I am using the ondraw function. I have a variable called color in the doc class and a function which returns the current colour. I ma calling this function in the ondraw function to get the colour. Below is the code of ondraw function and the doc class..
void CFiguresdiView::OnDraw(CDC* pDC) { CFiguresdiDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here COLORREF m_nColor = pDoc->GetCurrentColor(); CBrush brush (m_nColor); int x1 = 100; int y1 = 100; int x2 = 300; int y2 = 400; CRect rect (x1, y1, x2, y2); pDC->FillRect (rect, &brush); }
In the document class i ahve the following code.COLORREF CFiguresdiDoc::GetCurrentColor() { return m_nColor; } void CFiguresdiDoc::OnColorsRed() { m_nColor=RGB (255,0,0); } void CFiguresdiDoc::OnColorsGreen() { m_nColor = RGB(0,255,0);// TODO: Add your command handler code here } void CFiguresdiDoc::OnUpdateColorsGreen(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 0)); } void CFiguresdiDoc::OnUpdateColorsRed(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 255));// TODO: Add your command update UI handler code here }
m_nColor is of type COLORREF. i AHVE SET THE DEFAULT COLOR AS RED . It is set in the onNew Document function. IF i try doing the same thing on OnButtonDown event of mouse in the client area the color does change. I am not able to figure out how i can click on the colour in the menu and as soon as i click the menu option the Figure gets redrawn with the chosen colour. I probably need to write some message map but i cant figure out how. Thanks david