Esempio n. 1
0
// Enable or disable the secure mode, default is enabled
void CSecureEditEx::EnableSecureMode(BOOL bEnable)
{
	if(m_bSecMode == bEnable) return; // Nothing to do

	LPTSTR lpSource = GetPassword(); ASSERT(lpSource != NULL);
	ASSERT((int)_tcslen(lpSource) == m_nOldLen);

	const int iPos = static_cast<int>(GetSel() & 0xFFFF);

	_DeleteAll();
	m_bSecMode = bEnable;

	if(lpSource != NULL)
	{
		m_nOldLen = (int)_tcslen(lpSource);

		if(bEnable == FALSE) SetWindowText(lpSource);
		else
		{
			if(m_nOldLen != 0)
			{
				_InsertCharacters(0, lpSource, (unsigned int)m_nOldLen);
				_tcsset_s(lpSource, m_nOldLen + 1, TCH_STDPWCHAR);
			}

			SetWindowText(lpSource);
		}

		if((iPos >= 0) && (iPos <= m_nOldLen)) SetSel(iPos, iPos, FALSE);
		else { ASSERT(FALSE); }
	}

	DeletePassword(lpSource); lpSource = NULL;
}
Esempio n. 2
0
// Set the currently entered password, may be NULL
void CSecureEditEx::SetPassword(LPCTSTR lpPassword)
{
	_DeleteAll();

	if(m_bSecMode == FALSE)
	{
		if(lpPassword != NULL) SetWindowText(lpPassword);
		else SetWindowText(_T(""));

		return;
	}

	if(lpPassword != NULL)
	{
		unsigned int uLen = (unsigned int)_tcslen(lpPassword);
		if(uLen != 0) _InsertCharacters(0, lpPassword, uLen);

		size_t sizeTempBuffer = uLen + 1;
		LPTSTR tszBuf = new TCHAR[sizeTempBuffer];
		ASSERT(tszBuf != NULL);
		if(tszBuf != NULL)
		{
			_tcscpy_s(tszBuf, sizeTempBuffer, lpPassword);
			_tcsset_s(tszBuf, sizeTempBuffer, TCH_STDPWCHAR);
			m_nOldLen = (int)_tcslen(tszBuf);
			ASSERT(m_nOldLen == (int)uLen);
			SetWindowText(tszBuf);

			delete []tszBuf; tszBuf = NULL;
		}
		else SetWindowText(_T(""));
	}
	else SetWindowText(_T(""));
}
Esempio n. 3
0
PINFOCOPYDLL_API LPCWSTR __stdcall version()
{
	static _TCHAR _version[256];
	_tcsset_s(_version,'\0',sizeof(_version));
	_tcscpy_s(_version, getVer());
	_tcscat_s(_version, L"(DLL Ver." VER_STR_PRODUCTVERSION L" " VER_STR_LEGALCOPYRIGHT L")");
	return _version;
}
Esempio n. 4
0
// Called *after* the content of the edit control has been updated!
void CSecureEditEx::OnEnUpdate() 
{
	_RegisterDropTarget();

	if(m_bSecMode == FALSE)
	{
		m_nOldLen = GetWindowTextLength();
		return;
	}

	// Get information about the *new* contents of the edit control
	const int iWndLen = GetWindowTextLength();
	const int iDiff = iWndLen - m_nOldLen;

	if(iDiff == 0) return; // No change?

	const size_t sizeWindowBuffer = iWndLen + 1;
	LPTSTR lpWnd = new TCHAR[sizeWindowBuffer];
	ASSERT(lpWnd != NULL); if(lpWnd == NULL) return;
	GetWindowText(lpWnd, iWndLen + 1);
	const DWORD dwPos = (GetSel() & 0xFFFF); // Get the *new* cursor position

	if(iDiff < 0)
	{
		ASSERT(iDiff == -1);
		_DeleteCharacters(dwPos, static_cast<unsigned int>(-iDiff));
	}
	else
		_InsertCharacters(dwPos - static_cast<DWORD>(iDiff), &lpWnd[dwPos -
			static_cast<DWORD>(iDiff)], static_cast<unsigned int>(iDiff));

	ASSERT(m_apChars.GetSize() == iWndLen);

	m_nOldLen = static_cast<int>(m_apChars.GetSize());
	_tcsset_s(lpWnd, sizeWindowBuffer, TCH_STDPWCHAR);
	SetWindowText(lpWnd);
	SetSel(static_cast<int>(dwPos), static_cast<int>(dwPos), FALSE);
	DeleteTPtr(lpWnd, TRUE, FALSE); // Memory overwritten already
}