www.pudn.com > my2cadtest07261930.rar > DelTool.cpp, change:2006-07-26,size:1953b


 
#include "stdafx.h" 
#include "DelTool.h" 
 
extern CList<CShape *> m_list; 
 
CDelTool::CDelTool(HWND hWnd):CTool(hWnd) 
{ 
 
} 
 
CDelTool::~CDelTool() 
{ 
 
} 
 
void CDelTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
     
	POINT curPoint; 
	curPoint.x = LOWORD(lParam); 
	curPoint.y = HIWORD(lParam);   		 
	m_catchShape = NULL; 
     
   for(int nI=0;nI<m_list.GetCount();nI++) 
	 { 
		 if(m_list[nI].node->IsLock())      //已经被选取的图形 
		 { 
		   for(int nJ=0;nJ<m_list[nI].node->GetPointCount();nJ++) 
			   { 
				   int distance=m_list[nI].node->GetPointArr()[nJ].DistanceTo(curPoint); 
				   if(distance<6) 
				   { 
					 int stateYes=::MessageBox(m_hWnd,"是否确定删除该图形?","删除",MB_OKCANCEL); 
					   if(stateYes==IDOK) 
					   { 
                           m_hdc = GetDC(m_hWnd); 
						   RECT rect; 
						   rect=m_list[nI].node->GetRECT(); 
						   ::InvalidateRect(m_hWnd,&rect,true); 
						   m_list.DeleteNode(nI); 
                           ReleaseDC(m_hWnd,m_hdc); 
                           m_list.SetEditStatus(true); 
						   return; 
					   } 
					   else 
					   { 
						   return; 
					   } 
				   } 
			   } 
		 } 
	 } 
 
    bool oncemsgbox=true; 
    int stateYes; 
	 
  	for( nI=0;nI<m_list.GetCount();nI++)  //多图一起操作 
	 {		  
		if(m_list[nI].node->IsLock())       
		 { 
		   	if(oncemsgbox) 
			{ 
			 stateYes=::MessageBox(m_hWnd,"是否确定删除此组图形?","删除",MB_OKCANCEL); 
             oncemsgbox=false; 
			} 
			 
		    if(stateYes==IDOK) 
			{ 
               m_hdc = GetDC(m_hWnd); 
			   RECT rect; 
			   rect=m_list[nI].node->GetRECT(); 
               ::InvalidateRect(m_hWnd,&rect,true); 
               m_list.DeleteNode(nI); 
 
			   nI--;      //删除当前节点后 后续节点的索引就等于了当前索引直 
			   
			   m_list.SetEditStatus(true); 
                
			   ReleaseDC(m_hWnd,m_hdc); 
			 } 
			 else 
			 { 
			   return; 
			 } 
        } 
	 }				 
    
}