Beispiel #1
0
void CBCGMaskEdit::GetWindowText(CString& strString) const
{
	if (m_bGetMaskedCharsOnly)
	{
		strString = GetMaskedValue();
	}
	else
	{
		strString = GetValue();
	}
}
LRESULT CBCGPMaskEdit::OnGetText(WPARAM wParam, LPARAM lParam)
{
	if (m_bPasteProcessing)
	{
		return Default ();
	}

	int nMaxCount = (int)wParam;
	if (nMaxCount == 0)
	{
		return 0;       // nothing copied
	}

	LPTSTR lpszDestBuf = (LPTSTR)lParam;
	if (lpszDestBuf == NULL)
	{
		return 0;       // nothing copied
	}

	//-------------
	// Receive text
	//-------------
	CString strText;
	if (m_bGetMaskedCharsOnly)
	{
		strText = GetMaskedValue();
	}
	else
	{
		strText = GetValue();
	}

	//----------
	// Copy text
	//----------
	int nCount = min(nMaxCount, strText.GetLength());
	LPCTSTR lpcszTmp = strText;
	CopyMemory(lpszDestBuf, lpcszTmp, nCount*sizeof(TCHAR));

	// Add terminating null character if possible
	if (nMaxCount > nCount)
	{
		lpszDestBuf[nCount] = _T('\0'); 
	}
	
	return nCount*sizeof(TCHAR);
}
LRESULT CBCGPMaskEdit::OnGetTextLength(WPARAM, LPARAM)
{
	if (m_bPasteProcessing)
	{
		return Default ();
	}

	//-------------
	// Receive text
	//-------------
	CString strText;
	if (m_bGetMaskedCharsOnly)
	{
		strText = GetMaskedValue();
	}
	else
	{
		strText = GetValue();
	}

	return (LRESULT) strText.GetLength ();
}
Beispiel #4
0
LRESULT CBCGMaskEdit::OnPaste (WPARAM, LPARAM)
{
	m_bPasteProcessing = TRUE;

	int nBeginOld, nEndOld;
	CEdit::GetSel(nBeginOld, nEndOld);

	Default ();

	int nBegin, nEnd;
	CEdit::GetSel(nBegin, nEnd);
	nEnd = max (nBegin, nEnd);

	CString str;
	CWnd::GetWindowText(str);

	CString strPaste = str.Mid (nBeginOld, nEnd - nBeginOld);
	CString strOld;
	int nLeft = nBeginOld;

	if (m_bSetMaskedCharsOnly)
	{
		strOld = GetMaskedValue();

		if (!m_strMask.IsEmpty ())
		{
			for (int iChar = 0;
				iChar < m_strInputTemplate.GetLength() && iChar < nBeginOld;
				iChar++)
			{
				if (m_strInputTemplate[iChar] != _T('_'))
				{
					nLeft--;
				}
			}
		}
	}
	else
	{
		strOld = GetValue();
	}

	CString strNew = strOld.Left (nLeft) + strPaste;
	BOOL bOverwrite = !m_strMask.IsEmpty ();
	int nRight = nLeft + (bOverwrite ? strPaste.GetLength () : 0);
	if (nRight < strOld.GetLength ())
	{
		strNew += strOld.Mid (nRight);
	}

	if (!SetValue(strNew, !m_bSetMaskedCharsOnly))
	{
		MessageBeep((UINT)-1);
	}

	CWnd::SetWindowText(m_str);

	if (m_bSelectByGroup)
	{
		GetGroupBounds(nBeginOld, nEndOld, nBeginOld, TRUE);
	}
	CEdit::SetSel(nBeginOld, nBeginOld);

	m_bPasteProcessing = FALSE;

	return 0L;
}