www.pudn.com > agsm2-1.2_src.zip > SMSDialog.cpp


// SMSDialog.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "agsm2.h" 
#include "SMSDialog.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSMSDialog dialog 
 
 
CSMSDialog::CSMSDialog(CWnd* pParent /*=NULL*/) 
	: CDialog(CSMSDialog::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CSMSDialog) 
	m_smsOwner = _T(""); 
	m_smsRichEditContent = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CSMSDialog::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CSMSDialog) 
	DDX_Control(pDX, IDC_EDIT_SMS, m_smsRichEdit); 
	DDX_Control(pDX, IDC_COMBO_STATUS, m_smsStatus); 
	DDX_Text(pDX, IDC_EDIT_OWNER, m_smsOwner); 
	DDV_MaxChars(pDX, m_smsOwner, 20); 
	DDX_Text(pDX, IDC_EDIT_SMS, m_smsRichEditContent); 
	DDV_MaxChars(pDX, m_smsRichEditContent, 160); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CSMSDialog, CDialog) 
	//{{AFX_MSG_MAP(CSMSDialog) 
	ON_NOTIFY(NM_RCLICK, IDC_EDIT_SMS, OnRclickEditSms) 
	ON_WM_RBUTTONDOWN() 
	ON_EN_CHANGE(IDC_EDIT_SMS, OnChangeEditSms) 
	ON_COMMAND(ID_MENUITEM_RE_COPY, OnMenuitemReCopy) 
	ON_COMMAND(ID_MENUITEM_RE_CUT, OnMenuitemReCut) 
	ON_COMMAND(ID_MENUITEM_RE_PASTE, OnMenuitemRePaste) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSMSDialog message handlers 
BOOL CSMSDialog::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	m_smsRichEdit.SetEventMask(ENM_CHANGE|ENM_MOUSEEVENTS);	 
	// TODO: Add extra initialization here 
	m_smsRichEdit.SetWindowText(m_smsRichEditContent); 
	m_smsStatus.SelectString(0,m_smsStatusStr); 
#if 0 
	// Find the longest string in the AddressType box. 
	CString str; 
	CSize   sz; 
	int     dx=0; 
	CDC*    pDC = m_smsAddressType.GetDC(); 
	for (int i=0;i < m_smsAddressType.GetCount();i++) 
	{ 
		m_smsAddressType.GetLBText( i, str ); 
		sz = pDC->GetTextExtent(str); 
 
		if (sz.cx > dx) 
			dx = sz.cx; 
	} 
	m_smsAddressType.ReleaseDC(pDC); 
 
	// Adjust the width for the vertical scroll bar and the left and right border. 
	dx += ::GetSystemMetrics(SM_CXVSCROLL) + 2*::GetSystemMetrics(SM_CXEDGE); 
 
	// Set the width of the list box so that every item is completely visible. 
	m_smsAddressType.SetDroppedWidth(dx); 
	m_smsAddressType.SetCurSel(0); 
#endif 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CSMSDialog::OnOK()  
{ 
	// TODO: Add extra validation here 
	int iCur = m_smsStatus.GetCurSel(); 
	if(iCur != CB_ERR ) 
		m_smsStatus.GetLBText(iCur,m_smsStatusStr); 
	else 
		m_smsStatusStr = _T(""); 
	CDialog::OnOK(); 
} 
 
void CSMSDialog::OnRclickEditSms(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	TRACE("OnRclickEditSms\n"); 
	*pResult = 0; 
} 
 
void CSMSDialog::OnRButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	TRACE("OnRButtonDown\n"); 
	CDialog::OnRButtonDown(nFlags, point); 
} 
 
void CSMSDialog::OnChangeEditSms()  
{ 
	// TODO: If this is a RICHEDIT control, the control will not 
	// send this notification unless you override the CDialog::OnInitDialog() 
	// function and call CRichEditCtrl().SetEventMask() 
	// with the ENM_CHANGE flag ORed into the mask. 
	 
	// TODO: Add your control notification handler code here 
	TRACE("OnChangeEditSms\n"); 
} 
 
BOOL CSMSDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	MSGFILTER * lpMsgFilter = (MSGFILTER *)lParam;  
	if ((wParam == IDC_EDIT_SMS) && (lpMsgFilter->nmhdr.code == EN_MSGFILTER)    
		&& (lpMsgFilter->msg == WM_RBUTTONDOWN))                                        
   
    {//if we get through here, we have trapped the right click event of the richeditctrl!  
		 CPoint point;                                             
		 ::GetCursorPos(&point); //where is the mouse? 
		 CMenu menu; //lets display out context menu :)  
		 DWORD dwSelectionMade;                                        
		 VERIFY(menu.LoadMenu(IDR_MENU_RICHEDIT) );   
		 CMenu *pmenuPopup = menu.GetSubMenu(0); 
		 ASSERT(pmenuPopup != NULL);      
		 if(m_smsRichEdit.CanPaste()) 
			pmenuPopup->EnableMenuItem(ID_MENUITEM_RE_PASTE,MF_ENABLED); 
		 else 
			pmenuPopup->EnableMenuItem(ID_MENUITEM_RE_PASTE,MF_GRAYED); 
		long nStartChar, nEndChar; 
		m_smsRichEdit.GetSel(nStartChar, nEndChar);  
		TRACE("Selection %d --- %d\n",nStartChar,nEndChar); 
		if(nStartChar == nEndChar) 
		{ 
			pmenuPopup->EnableMenuItem(ID_MENUITEM_RE_COPY,MF_GRAYED); 
			pmenuPopup->EnableMenuItem(ID_MENUITEM_RE_CUT,MF_GRAYED); 
		}else{ 
			pmenuPopup->EnableMenuItem(ID_MENUITEM_RE_COPY,MF_ENABLED); 
			pmenuPopup->EnableMenuItem(ID_MENUITEM_RE_CUT,MF_ENABLED); 
		} 
		 dwSelectionMade = pmenuPopup->TrackPopupMenu( (TPM_LEFTALIGN|TPM_LEFTBUTTON) , 
														   point.x, point.y, this);                                 
   
		 pmenuPopup->DestroyMenu();  
		 // Exercise for the reader...deal with the user's choice here :)                                       
     }	 
	return CDialog::OnNotify(wParam, lParam, pResult); 
} 
 
void CSMSDialog::OnMenuitemReCopy()  
{ 
	// TODO: Add your command handler code here 
	TRACE("OnMenuitemReCopy\n"); 
	m_smsRichEdit.Copy(); 
} 
 
void CSMSDialog::OnMenuitemReCut()  
{ 
	// TODO: Add your command handler code here 
	TRACE("OnMenuitemReCut\n"); 
	m_smsRichEdit.Cut(); 
} 
 
void CSMSDialog::OnMenuitemRePaste()  
{ 
	// TODO: Add your command handler code here 
	TRACE("OnMenuitemRePaste\n"); 
	m_smsRichEdit.Paste(); 
}