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


// AttribTool.cpp: implementation of the CAttribTool class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "AttribTool.h" 
#include "commctrl.h" 
#pragma comment(lib, "comctl32.lib") 
 
extern CList<CShape *> m_list; 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CAttribTool::CAttribTool(HWND hWnd):CTool(hWnd) 
{ 
   
 
 
 
 
 
} 
 
CAttribTool::~CAttribTool() 
{ 
 
} 
 
void CAttribTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
 POINT curPT; 
 curPT.x=LOWORD(lParam); 
 curPT.y=HIWORD(lParam); 
  
 switch (m_status) 
 { 
   case NoClick: 
	 { 
		 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(curPT); 
							   if(distance<6) 
								   { 
									 m_catchShape=m_list[nI].node; 
									 m_begPT=curPT; 
									 this->AttribDlg(); 
//									 m_status=FirstClick; 
                                     m_status=NoClick; 
									m_list.SetEditStatus(true); 
									 return; 
								   } 
							    
						   }                  					    
				 } 
			 } 
     } 
  break; 
  case FirstClick: 
	  { 
         this->AttribDlg(); 
         m_status=NoClick; 
         m_list.SetEditStatus(true); 
	  } 
  break; 
 } 
 
} 
 
void CAttribTool::AttribDlg() 
{ 
  
  	m_hDlgWnd = NULL;	 
	for(int i = 0; i < 8; i++) 
	{ 
		m_cCustomColors[i] = RGB(255, 255, 255); 
	} 
	 
	m_cDlgStruct.lStructSize = sizeof(CHOOSECOLOR); 
	m_cDlgStruct.hwndOwner = NULL; 
	m_cDlgStruct.hInstance = NULL; 
	m_cDlgStruct.lpTemplateName = NULL; 
	m_cDlgStruct.rgbResult = m_catchShape->GetLOGPEN().lopnColor; 
	m_cDlgStruct.lpCustColors = m_cCustomColors;		 
	m_cDlgStruct.Flags = CC_ANYCOLOR | CC_RGBINIT; 
	m_cDlgStruct.lCustData = 0; 
	m_cDlgStruct.lpfnHook = NULL; 
 
    m_penstruct.lopnStyle = m_catchShape->GetLOGPEN().lopnStyle; 
    
  ::DialogBoxParam(hInst,(LPCTSTR)IDD_CHANGEPEN, m_hWnd, (DLGPROC)AttribProc,(LPARAM)this); 
 
}  
 
 
BOOL CAttribTool::AttribProc(HWND hAttribDlg,UINT msg, WPARAM wParam, LPARAM lParam) 
{ 
   
  char szText[30]="";  
 
  static CAttribTool *pthis = NULL; 
   
 switch( msg ) 
	{ 
	case WM_INITDIALOG:	 
			pthis = (CAttribTool *)lParam;				 
			pthis->OnInitDialog(hAttribDlg,lParam);  
			return TRUE; 
	        break; 
	case WM_COMMAND: 
		switch(LOWORD(wParam)) 
		{ 
		  case IDC_CBOPENSTYLE: 
            { 
             
           	if (HIWORD(wParam) == CBN_SELCHANGE)//如果选择 
					{ 
					    pthis->m_nIndex = ::SendMessage(pthis->m_hCBO, CB_GETCURSEL, 0, 0);//获得选中项序号 
						::SendMessage(pthis->m_hCBO, CB_GETLBTEXT,pthis->m_nIndex,(LPARAM)szText);//获得选中项的文本 
					//	::MessageBox(penattrib->m_hCBO,szText,"selected",MB_OK); 
					/* 
						switch (nIndex) 
						{ 
						case 0: 
							{								 
								pthis->m_penstruct.lopnStyle = PS_DASH;	 
							} 
							break; 
						case 1: 
							{ 
								pthis->m_penstruct.lopnStyle = PS_DASHDOT; 
							} 
							break; 
						case 2: 
							{ 
								pthis->m_penstruct.lopnStyle = PS_DOT;							 
							} 
							break; 
						case 3: 
							{ 
								pthis->m_penstruct.lopnStyle = PS_SOLID; 
							} 
							break; 
						} 
					*/	 
					} 
				}			 
			break; 
			 
		case IDOK: 
			pthis->OnOk(); 
           ::EndDialog(hAttribDlg,LOWORD(wParam)); 
			return true; 
			break; 
		case IDCANCEL: 
			::EndDialog(hAttribDlg,LOWORD(wParam)); 
			return true; 
			break; 
		case IDC_PENCOLORSET: 
			pthis->GetPenColor(hAttribDlg); 
			break;              
		} 
		break; 
	case WM_CTLCOLORSTATIC: 
		pthis->OnCtlColorStatic(wParam, lParam);		 
		break; 
	case WM_CLOSE: 
		::EndDialog(hAttribDlg, LOWORD(wParam)); 
		return true; 
		break; 
	} 
	 
	return 0; 
 
 
} 
 
void CAttribTool::OnInitDialog(HWND &hwnd, LPARAM &lParam) 
{ 
 
   char buffer[10]=""; 
    char szText[30]=""; 
	m_hDlgWnd = hwnd; 
	m_hPenWidth = ::GetDlgItem(m_hDlgWnd, IDC_EDITLINEWIDTH1); 
	m_hPenColor = ::GetDlgItem(m_hDlgWnd,IDC_COLORVIEW1); 
    m_hCBO = ::GetDlgItem(m_hDlgWnd,IDC_CBOPENSTYLE1); 
	 
    sprintf(buffer,"%d",m_catchShape->GetLOGPEN().lopnStyle); 
	::SetWindowText(m_hCBO,buffer); 
 
	//添加画笔宽度数直 
    sprintf(buffer,"%d",m_catchShape->GetLOGPEN().lopnWidth.x); 
	::SetWindowText(m_hPenWidth,buffer); 
	 
	//添加下拉框项目			  
	::strcpy(szText,"PS_SOLID        实线"); 
	::SendMessage(m_hCBO,CB_ADDSTRING,0,(LPARAM)szText); 
 
	::strcpy(szText,"PS_DOT           虚线"); 
	::SendMessage(m_hCBO,CB_ADDSTRING,0,(LPARAM)szText); 
 
	::strcpy(szText,"PS_DASHDOT  点划线"); 
	::SendMessage(m_hCBO,CB_ADDSTRING,0,(LPARAM)szText); 
	 
	::strcpy(szText,"PS_DASH         划线"); 
	::SendMessage(m_hCBO,CB_ADDSTRING,0,(LPARAM)szText); 
 
 
} 
 
void CAttribTool::OnCtlColorStatic(WPARAM &wParam, LPARAM &lParam) 
{ 
	HBRUSH m_Brush; 
	HDC hdc; 
	if((HWND)lParam == m_hPenColor) 
	{ 
        m_penstruct.lopnColor= m_cDlgStruct.rgbResult; 
		m_Brush = ::CreateSolidBrush(m_cDlgStruct.rgbResult); 
         
		hdc = (HDC)wParam; 
		::SelectObject(hdc, m_Brush); 
		::Rectangle(hdc, 0, 0, 200, 200); 
	}   
	::DeleteObject(m_Brush); 
	::ReleaseDC((HWND)lParam,hdc); 
} 
 
void CAttribTool::OnOk() 
{ 
	  char buffer[10]=""; 
	  int width; 
      ::GetWindowText(m_hPenWidth,buffer,10);				 
	   sscanf(buffer,"%d",&width); 
      m_penstruct.lopnWidth.x=width; 
      m_penstruct.lopnColor= m_cDlgStruct.rgbResult; 
   
	switch (m_nIndex) 
	{ 
	case 0: 
		{								 
			m_penstruct.lopnStyle = PS_DASH;	 
		} 
		break; 
	case 1: 
		{ 
			m_penstruct.lopnStyle = PS_DASHDOT; 
		} 
		break; 
	case 2: 
		{ 
			m_penstruct.lopnStyle = PS_DOT;							 
		} 
		break; 
	case 3: 
		{ 
			m_penstruct.lopnStyle = PS_SOLID; 
		} 
		break; 
	} 
	 
    m_catchShape->SetLOGPEN(m_penstruct); 
    InvalidateRect(m_hWnd,NULL,true); 
 
	   							    
} 
 
bool CAttribTool::GetPenColor(HWND &hwnd) 
{ 
  	m_cDlgStruct.hwndOwner = hwnd; 
	if(::ChooseColor(&m_cDlgStruct)) 
	{ 
		m_penstruct.lopnColor= m_cDlgStruct.rgbResult; 
		InvalidateRect(m_hPenColor, NULL, 1);			 
		return true; 
	} 
	else 
	{ 
		return false; 
	} 
	 
}