Paint MFC program

I followed a MFC program can draw lines, rectangles, curves in the canvys, and can select the pen and brush color and styles, but there's some problem.

first, the menu item check, I don't know why, in the initizlize window, in the
BrushStyle menu
, the
Null
and
Vertical
2 items are checked, but I use the different brushStyle marco,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void CSketcherDoc::OnBrushstyleNull()
{
	m_BrushStyle = BS_HOLLOW;
}

void CSketcherDoc::OnBSVert()
{
	m_BrushStyle = HS_VERTICAL;
}

void CSketcherDoc::OnUpdateBrushstyleNull(CCmdUI *pCmdUI)
{
	pCmdUI->SetCheck(m_BrushStyle == BS_HOLLOW);
}



void CSketcherDoc::OnUpdateBSVert(CCmdUI *pCmdUI)
{
	pCmdUI->SetCheck(m_BrushStyle == HS_VERTICAL);
}



next, I don't understande the moving item code(the
Draw
and
Move
functions are implementated)

1
2
3
4
5
6
7
8
9
10
11
12
13
void CSketcherView::MoveElement(CClientDC& aDC, const CPoint& point)
{
	CSize distance  = point - m_CursorPos;
	m_CursorPos = point;

	if(m_pSelected)
	{
	aDC.SetROP2(R2_NOTXORPEN);
	m_pSelected->Draw(&aDC, m_pSelected);   // I don't understand this line	
         m_pSelected->Move(distance);
	m_pSelected->Draw(&aDC, m_pSelected);   // draw the moved element
	}
}


The guide said this line : redraw the selected element in its current color(selected color) to reset it to the background color, and Move()...


I don't understand this, if I comment this line, when I move one item, it will draw follow the cursor, with this line, it's all ok.
Why redraw the element can make it invisible? I think draw it again will get the same color.

==========================
plus, the program have a little problem, when first click in the client area, it can't draw, only second time click can draw, I don't know what's wrong with it, can you help me look at it?
I uploaded at :
https://hotfile.com/dl/188509200/5648a28/Sketcher.rar.html
(1.6MB)
=========================
why VS2010 MFC project so huge, almost 100MB each project?
Do you understand these two problems yet - or are you still waiting for some further explanation??
yeah, I don't know why, waiting for explanation.
Let's start with this one:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void CSketcherDoc::OnBrushstyleNull()
{
	m_BrushStyle = BS_HOLLOW;
}

void CSketcherDoc::OnBSVert()
{
	m_BrushStyle = HS_VERTICAL;
}

void CSketcherDoc::OnUpdateBrushstyleNull(CCmdUI *pCmdUI)
{
	pCmdUI->SetCheck(m_BrushStyle == BS_HOLLOW);
}


void CSketcherDoc::OnUpdateBSVert(CCmdUI *pCmdUI)
{
	pCmdUI->SetCheck(m_BrushStyle == HS_VERTICAL);
}

This is going to be a long winded explanation.

When programming a user interface - we usually change the state of
controls visually so that the user can see whether that particular control is
eanbled or disabled. This applies particularly to menu options and toolbar buttons.

We usually do this by a combination of graying out the text, or displaying/removing a checkmark next to the item (menu items) or showing
a toolbar buttons in the DOWN position(selected) or in the UP position (NOT SELECTED).

MFC generates a particular message called ON_UPDATE_COMMAND_UI messages for toolbars and menu items.
The purpose of this messge is for you to update the toolbar button or menu
item.

So we have TWO message for each menuitem or toolbar button.
one to tell us the button has been clicked, and the other telling us to update the menu item or button state.

So going to the code above:
1
2
3
4
void CSketcherDoc::OnBrushstyleNull() //we  do this when the user click the NULL brush menu option.
{
	m_BrushStyle = BS_HOLLOW;
}


1
2
3
4
5
6
7
8
9
//We use this code when we get the ON_UPDATE_COMMAND_UI message for for NULL Brush menu option
void CSketcherDoc::OnUpdateBrushstyleNull(CCmdUI *pCmdUI)
{
      //We set or remove  a check mark next to the NULL brush menu
      //option depending on whether or not  the  NULL brush is
      //is the currently selected brush
     pCmdUI->SetCheck(m_BrushStyle == BS_HOLLOW);
}


That is the basic explanation - there is more detail - but you can get that from
the MSDN website.

==============================================
Your other question was
the program have a little problem, when first click in the client area, it can't draw, only second time click can draw, I don't know what's wrong with it, can you help me look at it?


You will need to change the constructor for the CSketcherView in the SketcherView.cpp file.

1
2
3
4
5
6
7
8
9
10
11
12
CSketcherView::CSketcherView() :
	 m_FirstPoint(CPoint(0,0)), 
	 m_SecondPoint(CPoint(0,0)), 
	 m_pTempElement(NULL),
	 m_pSelected(NULL),
	 m_MoveMode(false),//<<< Change this to false like I have done here.
	 m_CursorPos(CPoint(0, 0)),
	 m_FirstPos(CPoint(0, 0))
{
	// TODO: add construction code here

}

thanks a lot!!!
can you tell me some suggestion about how two find bugs in a program, like some principle?
Topic archived. No new replies allowed.