Example #1
0
void CWndDialog::Say( LPCTSTR lpszString, DWORD dwQuest )
{
 	QuestProp* pQuestProp = prj.m_aPropQuest.GetAt( dwQuest );
 	CString string = "  ";
	if( dwQuest )
	{
		string = "#b#cff5050f0";
		string += pQuestProp->m_szTitle;
		string += "#nb#nc\n";
		string += "  ";
		string += lpszString;
	}
	else
		string += lpszString;

	int nLength = string.GetLength();//_tcslen( szString );
	int i,j; for( i = 0, j = 0; i < nLength; i++ )
	{
		if( string[ i ] == '\\' && string[ i + 1 ] == 'n' )
		{
			// 중간의 두개의 코드를 \n와 ' '로 대체.
			string.SetAt( i, '\n' );
			string.SetAt( i + 1, ' ' );
			// 그리고 스페이스 한개 삽입.
			string.Insert( i + 1, " " );
		}
	}
	m_dwQuest = dwQuest;
	ParsingString( string );
	EndSay();
}
CString CUtils::MakePath(CString Path)
{
	char drive[_MAX_DRIVE+1];
	char path[_MAX_PATH+1];
	int i;
	CString result;

	if(Path[Path.GetLength()-1] != '\\')
	{
		_splitpath(LPCSTR(Path), drive, path, NULL, NULL);
		Path = CString(drive) + CString(path);
	}
	if(Path[Path.GetLength()-1] != '\\') Path += '\\';


	for(i = 0; i<Path.GetLength(); i++)
		if(Path[i] == '/') Path.SetAt(i, '\\');

	for(i = 0; i<Path.GetLength(); i++)
		if(i == 0 || Path[i] != '\\' || (Path[i] == '\\' && Path[i-1] != '\\')){
			result += Path[i];
			if(Path[i] == '\\'){
				CreateDirectory(LPCSTR(result), NULL);
				DWORD attr = GetFileAttributes(LPCSTR(result));
				if(attr == 0xFFFFFFFF || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) return "";
			}

		}

		return result;
}
Example #3
0
void CRandom::OnGenerate()
{
    UpdateData (TRUE);
    CString rndVals = "";

    if (((CButton*) GetDlgItem (IDC_NUM))->GetCheck() == 1)
        rndVals = "0123456789";
    else if (((CButton*) GetDlgItem (IDC_HEX))->GetCheck() == 1)
        rndVals = "0123456789ABCDEF";
    else if (((CButton*) GetDlgItem (IDC_ALPHA))->GetCheck() == 1)
        rndVals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    else if (((CButton*) GetDlgItem (IDC_ALPHANUM))->GetCheck() == 1)
        rndVals = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    else if (((CButton*) GetDlgItem (IDC_OTHERRAD))->GetCheck() == 1)
        rndVals = m_other;

    int count = rndVals.GetLength();

    CString rndText (' ', m_nochars);

    for (int i = 0; i < m_nochars; i++)
    {
        int index = rand() % count;
        rndText.SetAt(i, rndVals [index]);
    }

    m_random = rndText;
    UpdateData (FALSE);
}
Example #4
0
CString CAuthDlg::DEncrypt(CString str)
{
	for(int i = 0; i < str.GetLength(); i++) {
		str.SetAt(i, str[i]^5);
	}
	return str;
}
Example #5
0
void FixFilename(CString& str)
{
	str.Trim();

	for (int i = 0, l = str.GetLength(); i < l; i++) {
		switch (str[i]) {
			case '?':
			case '"':
			case '/':
			case '\\':
			case '<':
			case '>':
			case '*':
			case '|':
			case ':':
				str.SetAt(i, '_');
		}
	}

	CString tmp;
	// not support the following file names: "con", "con.txt" "con.name.txt". But supported "name.con" and "name.con.txt".
	if (str.GetLength() == 3 || str.Find('.') == 3) {
		tmp = str.Left(3).MakeUpper();
		if (tmp == _T("CON") || tmp == _T("AUX") || tmp == _T("PRN") || tmp == _T("NUL")) {
			str = _T("___") + str.Mid(3);
		}
	}
	if (str.GetLength() == 4 || str.Find('.') == 4) {
		tmp = str.Left(4).MakeUpper();
		if (tmp == _T("COM1") || tmp == _T("COM2") || tmp == _T("COM3") || tmp == _T("COM4") ||
				tmp == _T("LPT1") || tmp == _T("LPT2") || tmp == _T("LPT3")) {
			str = _T("____") + str.Mid(4);
		}
	}
}
Example #6
0
BOOL RC4::Crypt(CString &data)
{
    int a, b, nSize = data.GetLength();
	TCHAR ch;

    for(int i = 0; i < data.GetLength(); i++ )
    {
		x = ( x + 1 ) & 0xFF; a = m[x];
        y = ( y + a ) & 0xFF;
        m[x] = b = m[y];
        m[y] = a;

        ch = data[i];
        ch ^= m[( a + b ) & 0xFF];
		data.SetAt(i, ch);
    }

	// cover bin data to ASCII string

	TCHAR *pASCII = new TCHAR [nSize * sizeof(TCHAR) * 2 + 1];
    if (!pASCII)
		return FALSE;
	
    for (int l=0;  l < nSize;  l++)
        wsprintf((TCHAR *)&(pASCII)[l*2], "%02X", data[l]);
    
	data = pASCII;
	delete pASCII;
	return TRUE;
}
Example #7
0
//---------------------------------------------------------------------------
// OnCommand
//---------------------------------------------------------------------------
BOOL CRollupCtrl::OnCommand(WPARAM wParam, LPARAM lParam) 
{
        if (LOWORD(wParam)==RC_MID_COLLAPSEALL) {
                ExpandAllPages(FALSE);
                return TRUE;

        } else if (LOWORD(wParam)==RC_MID_EXPANDALL) {
                ExpandAllPages(TRUE);
                return TRUE;

        }       else if (LOWORD(wParam)>=RC_MID_STARTPAGES
                &&       LOWORD(wParam)<RC_MID_STARTPAGES+GetPagesCount())
        {
                int idx = LOWORD(wParam)-RC_MID_STARTPAGES;
                ExpandPage(idx, !IsPageExpanded(idx) );

        } else if (HIWORD(wParam)==BN_CLICKED) {
                int idx = GetPageIdxFromButtonHWND((HWND)lParam);
                if (idx!=-1) {
                        RC_PAGEINFO*    pi = m_PageList[idx];
                        /****** add some codes to change caption ******/
                        CString alter;
                        alter = (pi->cstrCaption);
                        if(!pi->bExpanded)
                        {
                                alter.SetAt(0, '-');
                                SetPageCaption(idx, (LPCSTR)(alter.GetBuffer()));
                        }
                        else 
                        {
                                alter.SetAt(0, '+');
                                SetPageCaption(idx, (LPCSTR)(alter.GetBuffer()));
                        }
                        /****** ******/
                        ExpandPage(idx, !pi->bExpanded);
                        SetFocus();
                        return TRUE;
                }
        }

        return CWnd::OnCommand(wParam, lParam);
}
Example #8
0
void COleDBConnectionProp::FileToStr(CArchive& ar, CString& str, bool bPressMark)
{
	CString token;
	ar >> token;

	if(bPressMark)
	{
		for( int i = 0; i < token.GetLength(); i++)
			token.SetAt(i,token.GetAt(i)^PRESS_MARK_MASK);

	}
	str = token;
}
Example #9
0
CString CFilePath::ReplaceInvalid(
    CString const &sString,
    TCHAR cReplaceChar)
{
    if (!sString.GetLength() || CFilePath(sString).IsDotty())
        return sString;

    CString sTemp = sString;

    for (int nLoop = 0; nLoop < sTemp.GetLength(); ++ nLoop)
    {
        TCHAR cChar = sTemp.GetAt(nLoop);

        if (_tcschr(gsWindowsInvalidChars, cChar))
            sTemp.SetAt(nLoop, cReplaceChar);
    }

    int nLen = sTemp.GetLength();

    if (sTemp[nLen-1] == '.')
        sTemp.SetAt(nLen-1, cReplaceChar);

    return sTemp;
}
void CHotGamePanel::OnListPopOpenDir()
{
	if (!AfxGetDbMgr()->GetBoolOpt(OPT_M_BROWSEDIR))
	{
		CString strNotify;
		strNotify.Format(TEXT("对不起,当前设置不允许浏览游戏目录。"));
		AfxMessageBoxEx(strNotify);
		return;
	}	

	size_t nSel = m_lstGame.GetNextItem(-1, LVIS_SELECTED);
	if (nSel == -1 || nSel >= m_GameInfo.size())
		return ;
	tagGameInfo* pGame = m_GameInfo[nSel];

	CString szWorkDir;
	if (pGame->RunType == 2)	//虚拟盘运行的,需要转换路径
	{
		szWorkDir = pGame->SvrPath;
		szWorkDir.Trim();
		tagVDiskInfo* pVDisk = AfxGetDbMgr()->FindVDiskInfo(pGame->VID);
		if (szWorkDir.GetLength() > 3 && pVDisk != NULL)
		{
			szWorkDir.SetAt(0, pVDisk->CliDrv);
		}
	}
	else
	{
		szWorkDir = pGame->CliPath;
	}

	if (szWorkDir.GetLength() && szWorkDir.Right(1) != TEXT("\\"))
		szWorkDir += TEXT("\\");

	if (PathFileExists(szWorkDir))
	{
		ShellExecute(m_hWnd, TEXT("open"), szWorkDir, TEXT(""), TEXT(""), SW_SHOWNORMAL);
	}
	else
	{
		szWorkDir.Insert(0, TEXT("目录不存在:"));
		AfxMessageBoxEx(szWorkDir);
	}
}
Example #11
0
CString CGetEnvPath::GetDrive(CString suffix)  //根据路径.获取只读区域卷标名称
{
    int nPos = 0;
    CString strDrive = "?:";
    DWORD dwDriveList = ::GetLogicalDrives();
    CString strTmp;

    while (dwDriveList)
    {
        if (dwDriveList & 1)
        {	
            strDrive.SetAt (0, 'A' + nPos);
            ///判断是移动磁盘
            {
                int nDiskType = GetDriveType(strDrive);   
                switch(nDiskType)
                {   
                case  DRIVE_NO_ROOT_DIR:
                    break;
                case  DRIVE_REMOVABLE: 
                    break;
                case  DRIVE_FIXED: 
                    {
                        strTmp += strDrive;
                        strTmp += suffix;
                        if(::PathIsDirectory(strTmp.GetBuffer()))
                            return strTmp;
                        strTmp = _T("");

                    }
                    break;
                case   DRIVE_REMOTE:
                    break;   
                case   DRIVE_CDROM:
                    break;
                }
            }
        }
        dwDriveList >>= 1;
        nPos++;
    }
    return strTmp;
}
Example #12
0
int CLeftView::AddDrives()
{
	int nPos = 0;
	int nDrivesAdded = 0;
	CString string = _T("?:\\");

	DWORD dwDriveList = ::GetLogicalDrives();

	while (dwDriveList) {
		if (dwDriveList & 1) {
			string.SetAt(0, _T('A') + nPos);
			if (AddDriveItem(string))
				nDrivesAdded++;
		}
		dwDriveList >>= 1;
		nPos++;
	}
	return nDrivesAdded;
}
Example #13
0
void CXMLNode::UniformString(CString& str)
{
	// Non-alphanumeric characters which will not be ignored
	static LPCTSTR pszOK = _T("'-&/,;#()");

	str.Trim();
	BOOL bSpace = TRUE;

	for ( int nPos = 0 ; nPos < str.GetLength() ; nPos++ )
	{
		int nChar = (int)(unsigned short)str.GetAt( nPos );

		if ( nChar <= 32 )
		{
			if ( bSpace )
			{
				str = str.Left( nPos ) + str.Mid( nPos + 1 );
				nPos--;
			}
			else
			{
				if ( nChar != 32 ) str.SetAt( nPos, 32 );
				bSpace = TRUE;
			}
		}
		else if ( ! _istalnum( TCHAR( nChar ) ) && nChar < 0xC0 && _tcschr( pszOK, TCHAR( nChar ) ) == NULL )
		{
			if ( nPos == 0 || str.GetAt( nPos - 1 ) == ' ' )
				str = str.Left( nPos ) + str.Mid( nPos + 1 );
			else
			{
				LPTSTR pszTemp = _tcsninc( str, nPos );
				pszTemp[ 0 ] = ' ';
				bSpace = TRUE;
			}
		}
		else
		{
			bSpace = FALSE;
		}
	}
}
void CPropTreeItemEditButton::DrawAttribute( CDC *pDC, const RECT &rc ) {
	ASSERT( m_pProp != NULL );
	pDC->SelectObject( IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont() );
	pDC->SetTextColor( RGB( 0, 0, 0 ) );
	pDC->SetBkMode( TRANSPARENT );
	CRect r = rc;
	r.right = buttonRect.left - 5;
	TCHAR ch;
	// can't use GetPasswordChar(), because window may not be created yet
	ch = ( m_bPassword ) ? '*' : '\0';
	if( ch ) {
		CString s;
		s = m_sEdit;
		for( LONG i = 0; i < s.GetLength(); i++ ) {
			s.SetAt( i, ch );
		}
		pDC->DrawText( s, r, DT_SINGLELINE | DT_VCENTER );
	} else {
		pDC->DrawText( m_sEdit, r, DT_SINGLELINE | DT_VCENTER );
	}
}
Example #15
0
void CVODFilesFormView::OnBtnPrevPathClicked()
{
	CString strNewPath;
	m_comboAddressBar.GetWindowText(strNewPath);
	
	if (strNewPath.GetLength())
	{
		KillSpelicalChar((LPSTR)(LPCSTR)strNewPath, '\\');
		int nPos = strNewPath.ReverseFind('\\');
		if(nPos != -1)
			strNewPath.SetAt(nPos, '\0');
		CString strRootPath = m_shellTree.GetRootPath();
		KillSpelicalChar((LPSTR)(LPCSTR)strRootPath, '\\');	
		if(StrFind((LPSTR)(LPCSTR)strNewPath, (LPSTR)(LPCSTR)strRootPath))
		{
			TCHAR sztmpPath[2048];
			_tcscpy(sztmpPath, (LPCSTR)strNewPath);
			_tcscat(sztmpPath, "\\");
			m_shellTree.TunnelTree(sztmpPath);
		}
	}
}
Example #16
0
void  CHSCalculate::GetTextByID(int nID,  CurrentFinanceData* pFinanceData, char strText[64])
{
	if (pFinanceData == NULL)
	{
		memset(strText, 0, STR_LENTH);
		return;
	}

	float fValue = 0.0;
	double dValue = 0.0;
	CString str = "";
	fValue = GetDataByID(nID, pFinanceData);

	if (nID == COLUMN_FINANCE_REPORT_DATE)
	{
		fValue = GetDataByID(0, pFinanceData);
		if (abs(fValue - 1) < 0.0001)
			str = _T("一季度");
		else if (abs(fValue - 2) < 0.0001)
			str = _T("二季度");
		else if (abs(fValue - 3) < 0.0001)
			str = _T("三季度");
		else
			str = _T("四季度");
	}
	else
	{
		int	nUnit	= 10000;	
		CString	strUnit;
		AutoAdjustUnit(nID, fValue, strUnit, &nUnit);

		if ( !fValue )
		{
			str.Empty();
		}
		else
		{
			dValue = fValue / nUnit;
			str.Format(_T("%16.5f"), dValue);

			//////////////////////////////////////////////////////////////////////////
			//这里根据实际情况动态格式化文本
			TCHAR	ch;
			/*	首先去除字符串中后面可能存在的一连串的0字符*/
			str.TrimLeft();
			int	n	= str.GetLength() - 1;
			while(1)
			{
				ch	= str[n];
				if ( ch == '0' )
				{
					//	用空格代替
					str.SetAt(n,' ');
					n --;
				}
				else
				{
					//	去掉右边的一连串空格
					str.TrimRight();
					break;
				}
			}
			//	如果文本变成了“0.”这样的格式,直接用空格代替
			if ( str == _T("0."))
			{
				str.Empty() ;
			}
			//	如果文本串中小数点后面的数据全部是空格,则去调
			//	多余的小数点
			else if ( str[str.GetLength() - 1] == _T('.'))
			{
				str	= str.Left(str.GetLength() - 1);
			}
			//	如果小数点后面的长度太长,那就取到小数点后面第二位为止即可。
			if ( dValue * 100 > 1 || dValue * 100 < -1 )
			{
				int	nDot	= str.Find(_T('.'));
				if ( nDot != -1 )
				{
					//每股收益等每股数据时,保留4位小数--------------------
					if ((COLUMN_FINANCE_PER_INCOME == nID) || (COLUMN_FINANCE_PER_UNPAID == nID) ||
						(COLUMN_FINANCE_PER_ASSETS == nID) || (COLUMN_FINANCE_ADJUST_PER_ASSETS == nID) )
						str	= str.Left(nDot + 5);
					else
						str	= str.Left(nDot + 3);
				}
				//	如果新得到的文本为XXX.00格式则去处后面的.00
				if ( str.Right(3) == _T(".00"))
				{
					str	= str.Left(str.GetLength() - 3);
				}
			}
		}
		if (dValue && !str.IsEmpty() )
		{
			str	+= strUnit;
		}
	}
	strncpy(strText, str.GetBuffer(), min(str.GetLength()+1, STR_LENTH));
}
Example #17
0
/*
================
SpinFloatString
================
*/
void SpinFloatString( CString &str, bool up ) {
	int i, dotIndex = -1, digitIndex = -1;

	for ( i = 0; str[i]; i++ ) {
		if ( str[i] == '.' ) {
			if ( dotIndex == -1 ) {
				dotIndex = i;
			}
		}
		else if ( str[i] != '0' ) {
			if ( digitIndex == -1 ) {
				digitIndex = i;
			}
		}
	}
	if ( digitIndex == -1 ) {
		str.SetString( "1" );
		return;
	}

	if ( dotIndex != -1 ) {
		str.Delete( dotIndex, 1 );
		if ( digitIndex > dotIndex ) {
			digitIndex--;
		}
	}
	else {
		dotIndex = i;
	}

	if ( up ) {
		if ( str[digitIndex] == '9' ) {
			str.SetAt( digitIndex, '0' );
			if ( digitIndex == 0 ) {
				str.Insert( 0, '1' );
				dotIndex++;
			}
			else {
				str.SetAt( digitIndex-1, '1' );
			}
		}
		else {
			str.SetAt( digitIndex, str[digitIndex] + 1 );
		}
	}
	else {
		if ( str[digitIndex] == '1' ) {
			if ( str[digitIndex+1] == '\0' ) {
				str.SetAt( digitIndex, '0' );
				str.AppendChar( '9' );
			}
			else if ( str[digitIndex+1] == '0' ) {
				str.SetAt( digitIndex, '0' );
				str.SetAt( digitIndex+1, '9' );
			}
			else {
				str.SetAt( digitIndex+1, str[digitIndex+1] - 1 );
			}
		}
		else {
			str.SetAt( digitIndex, str[digitIndex] - 1 );
		}
	}
	if ( dotIndex < str.GetLength() ) {
		str.Insert( dotIndex, '.' );
		// remove trailing zeros
		for ( i = str.GetLength()-1; i >= 0; i-- ) {
			if ( str[i] != '0' && str[i] != '.' ) {
				break;
			}
		}
		if ( i < str.GetLength() - 1 ) {
			str.Delete( i+1, str.GetLength() - i );
		}
	}
	for ( i = 0; str[i]; i++ ) {
		if ( str[i] == '.' ) {
			if ( i > 1 ) {
				str.Delete( 0, i-1 );
			}
			break;
		}
		if ( str[i] != '0' ) {
			if ( i > 0 ) {
				str.Delete( 0, i );
			}
			break;
		}
	}
}
Example #18
0
void CBCGMaskEdit::OnCharPrintchar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty());
	ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength());

	ASSERT(_istprint((BCG_TCHAR) nChar) != FALSE);

	// -----------------------------------------------
	// Processing ES_UPPERCASE and ES_LOWERCASE styles
	// -----------------------------------------------
	DWORD dwStyle = GetStyle ();
	if (dwStyle & ES_UPPERCASE)
	{
		nChar = _totupper((BCG_TCHAR) nChar);
	}
	else if (dwStyle & ES_LOWERCASE)
	{
		nChar = _totlower((BCG_TCHAR) nChar);
	}
	
	int nStartPos, nEndPos;

	CEdit::GetSel(nStartPos, nEndPos);

	ASSERT(nStartPos>=0);
	ASSERT(nEndPos>=0);
	ASSERT(nEndPos>=nStartPos);

	// -----------------
	// Calc group bounds
	// -----------------
	int nGroupStart, nGroupEnd;
	GetGroupBounds(nGroupStart, nGroupEnd, nStartPos);

	// ------------
	// Out of range
	// ------------
	if ((nStartPos<0) && (nEndPos > m_str.GetLength()) ||
		(nStartPos < nGroupStart) || (nStartPos > nGroupEnd) ||
		(nEndPos < nGroupStart) || (nEndPos > nGroupEnd))
	{
		MessageBeep((UINT)-1);
		CEdit::SetSel(nGroupStart, nGroupEnd);
		return;
	}

	TCHAR chChar = (TCHAR) nChar;

	// -----------------
	// No selected chars
	// -----------------
	if (nStartPos == nEndPos)
	{
		// Use m_strMask
		if (!m_strMask.IsEmpty())
		{
			// ----------------------------------------------
			// Automaticaly move the cursor to the next group
			// ----------------------------------------------
			if (nEndPos==nGroupEnd || // at the end of group
				nStartPos < nGroupStart || nStartPos > nGroupEnd) // not in the middle of a group
			{
				// no space for new char
				if (nEndPos >= m_str.GetLength()-1)
				{
					MessageBeep((UINT)-1);
					return;
				}

				// can search next group
				else if (nEndPos < m_str.GetLength()-1)
				{
					GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE);
				}

				// if next group was found
				if ((nGroupStart != -1) && (nGroupStart > nEndPos))
				{
					CEdit::SetSel(nGroupStart, nGroupStart);
					nStartPos = nGroupStart;
					nEndPos = nGroupStart;
				}

				// no more groups
				else
				{
					MessageBeep((UINT)-1);
					return;
				}
			}

			// ----------------------
			// Check char in position
			// ----------------------
			if (!CheckChar(chChar, nStartPos)) 
			{
				MessageBeep((UINT)-1);
				return;
			}

			// ---------------------------------
			// Replace char in Editbox and m_str
			// ---------------------------------
			CEdit::SetSel(nStartPos, nEndPos+1);
			CEdit::ReplaceSel(CString(chChar), TRUE);
			m_str.SetAt(nEndPos, chChar);          
			CEdit::SetSel(nEndPos+1, nEndPos+1);

			// ----------------------------------------------
			// Automaticaly move the cursor to the next group
			// ----------------------------------------------
			CEdit::GetSel(nStartPos, nEndPos);
			if (nEndPos==nGroupEnd) // at the end of group
			{
				// can search next group
				if (nEndPos < m_str.GetLength()-1)
				{
					GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE);
				}

				// if next group was found
				if ((nGroupStart != -1) && (nGroupStart > nEndPos))
				{
					CEdit::SetSel(nGroupStart, nGroupStart);
					nStartPos = nGroupStart;
					nEndPos = nGroupStart;
				}
			}
		}

		// Don't use m_strMask
		else
		{
			// ----------------------
			// Check char in position
			// ----------------------
			if (!CheckChar(chChar, nStartPos)) 
			{
				MessageBeep((UINT)-1);
				return;
			}

			// Don't use m_chMask
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
	}

	// -------------------------------
	// Have one or more chars selected
	// -------------------------------
	else
	{
		// ----------------------
		// Check char in position
		// ----------------------
		if (!CheckChar(chChar, nStartPos)) 
		{
			MessageBeep((UINT)-1);
			return;
		}

		// ----------------------------------
		// Replace chars in Editbox and m_str
		// ----------------------------------
		if (!m_strInputTemplate.IsEmpty()) // Use m_strInputTemplate
		{
			// ---------------------------------------------------
			// Calc the number of literals with the same mask char
			// ---------------------------------------------------
			ASSERT(nStartPos >= 0);
			ASSERT(nEndPos > 0);
			ASSERT(nStartPos <= m_strInputTemplate.GetLength());

			int nSameMaskCharsNum = 1;
			int nIndex = nStartPos; // an index of the first selected char
			TCHAR chMaskChar = m_strMask[nIndex];
			BOOL bScanMore = TRUE;
			while (bScanMore && (nIndex + nSameMaskCharsNum < nGroupEnd))
			{
				if (m_strMask[nIndex + nSameMaskCharsNum] == chMaskChar)
				{
					nSameMaskCharsNum++;
				}
				else
				{
					bScanMore = FALSE;
				}
			}
			
			// Make sure the selection has the same mask char
			if (nEndPos - nStartPos > nSameMaskCharsNum)
			{
				MessageBeep((UINT)-1);
				CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum);
				return;
			}

			// -------------------------------
			// Form the shifted replace string
			// -------------------------------
			ASSERT(nIndex >= nGroupStart);
			ASSERT(nIndex + nSameMaskCharsNum <= nGroupEnd);
			
			CString strReplace = m_str.Mid(nIndex, nSameMaskCharsNum);
			if (nSameMaskCharsNum > 0)
			{
				ASSERT(nStartPos <= m_strInputTemplate.GetLength());
				ASSERT(nEndPos <= m_strInputTemplate.GetLength());
				int nRange = nEndPos - nStartPos;
				ASSERT(nRange>0);

				strReplace = strReplace.Right(nSameMaskCharsNum - nRange + 1);
				strReplace += CString(m_chMaskInputTemplate, nRange - 1);
				ASSERT(strReplace.GetLength() > 0);
				strReplace.SetAt(0, chChar);
			}

			// -------------------------------------------
			// Replace the content with the shifted string
			// -------------------------------------------
			CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum);
			CEdit::ReplaceSel(strReplace, TRUE);
			CEdit::SetSel(nIndex, nIndex);
			for(int i=0; i < strReplace.GetLength(); i++)
			{
				m_str.SetAt(nIndex+i, strReplace[i]);
			}
			CEdit::SetSel(nStartPos+1, nStartPos+1);
		}
		else
		{
			// Don't use m_chMaskInputTemplate
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
		
	}
}
Example #19
0
BOOL CBCGMaskEdit::SetValue(LPCTSTR lpszString, BOOL bWithDelimiters)
{
	ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty());
	ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength());
	ASSERT(lpszString != NULL);

	// ------------------------------------------------
	// Make sure the string is not longer than the mask
	// ------------------------------------------------
	CString strSource = lpszString;
	if (!m_strMask.IsEmpty())
	{
		if (bWithDelimiters)
		{
			if (strSource.GetLength() > m_strMask.GetLength())
			{
				return FALSE;
			}
		}
		else
		{
			// Count _T('_') in m_strInputTemplate
			int nCount = 0;
			for (int i = 0; i < m_strInputTemplate.GetLength(); i++)
			{
				if (m_strInputTemplate[i] == _T('_'))
				{
					nCount++;
				}

			}
			if (strSource.GetLength() > nCount)
			{
				return FALSE;
			}
		}
	}

	// -----------------------------------
	// Use mask, validate against the mask
	// -----------------------------------
	if (!m_strMask.IsEmpty())
	{
		ASSERT(m_str.IsEmpty() == m_strMask.IsEmpty());
		ASSERT(m_str.GetLength() == m_strMask.GetLength());

		CString strResult = m_strInputTemplate;
		
		// Replace '_' with default char
		for (int i=0; i<strResult.GetLength(); i++)
		{
			if (m_strInputTemplate[i] == _T('_'))
			{
				strResult.SetAt(i, m_chMaskInputTemplate);
			}
		}

		int iSrcChar = 0;
		int iDstChar = 0;
		while ((iSrcChar<strSource.GetLength()) && 
				(iDstChar<m_strInputTemplate.GetLength()))
		{
			// iDstChar - character entry position ("_" char)
			if (m_strInputTemplate[iDstChar] == _T('_')) 
			{
				TCHAR chChar = strSource[iSrcChar];
				if (chChar != m_chMaskInputTemplate) // allow m_chMaskInputTemplate
				{
					if (!IsValidChar(chChar) || !IsMaskedChar(chChar, m_strMask[iDstChar]))
					{
						return FALSE;
					}
				}
				strResult.SetAt(iDstChar, chChar);
				iSrcChar++;
				iDstChar++;
			}
			
			// iDstChar - delimeter
			else 
			{
				if (bWithDelimiters)
				{
					if (m_strInputTemplate[iDstChar] != strSource[iSrcChar])
					{
						return FALSE;
					}

					iSrcChar++;
					iDstChar++;
				}
				else
				{
					iDstChar++;
				}
			}
		}
		m_str = strResult;
	}
	// --------------
	// Don't use mask
	// --------------
	else
	{
		m_str = strSource;
	}

	return TRUE;
}
Example #20
0
char CMagneticView::GetInput(bool& done, bool trans)
{
  static const int MAX_HISTORY = 20;
  done = true;

  CMagneticApp* pApp = (CMagneticApp*)AfxGetApp();
  CMagneticView* pView = CMagneticView::GetView();
  if (pView == NULL)
    return 0;

  int cInput = 0;        // Input character
  int iPosition = 0;    // Current cursor position
  int iHistory = -1;    // Current history position
  static CString strFullLine;

  // Input line already obtained?
  if (strFullLine.GetLength() > 0)
  {
    cInput = strFullLine[0];
    strFullLine = strFullLine.Right(strFullLine.GetLength()-1);
    if (cInput == (signed char)(CMagneticView::SPECIAL_KEYS + VK_SPACE))
      cInput = ' ';
    return (char)cInput;
  }

  if (pView->m_bMorePrompt)
    pView->m_PageTable.RemoveAt(pView->m_PageTable.GetSize()-1);
  else
    pView->m_PageTable.RemoveAll();

  // Refresh the view
  pView->Invalidate();
  pView->CaretOn();
  pView->m_bInputActive = true;

  while (cInput != 10 && cInput != 1)
  {
    pView = CMagneticView::GetView();
    if (pView == NULL)
      break;

    // Wait for a character
    CArray<int, int>& Input = pView->m_Input;
    if (Input.GetSize() == 0)
    {
      pApp->PumpMessage();
      pApp->CWinApp::OnIdle(0);  // Call base class OnIdle();
      pView = CMagneticView::GetView();
      if (pView)
      {
        CMagneticApp::Redraw Status = pApp->GetRedrawStatus();
        switch (Status)
        {
        case CMagneticApp::Redraw::EndPlayback:
          done = false;    // intentional fall-through
        case CMagneticApp::Redraw::EndLine:
        case CMagneticApp::Redraw::EndOpcode:
          Input.RemoveAll();
          strFullLine.Empty();
          if (Status == CMagneticApp::Redraw::EndOpcode)
            cInput = 1;
          else
            cInput = 10;  // intentional fall-through
        case CMagneticApp::Redraw::ThisLine:
          pView->CaretOff();
          pView->CaretOn();
          pView->Invalidate();
          break;
        }
        pView->SetCursorPos(pView->m_pTextDC,strFullLine.GetLength()-iPosition);
      }
    }
    else
    {
      cInput = (pView->m_bMorePrompt) ? 10 : Input[0];
      Input.RemoveAt(0);
      
      int iInsertPos, iRemovePos;
      switch (cInput)
      {
      case 10:                                      // Return
        strFullLine += (char)cInput;
        break;
      case CMagneticView::SPECIAL_KEYS + VK_LEFT:    // Cursor left
        if (iPosition > 0)
          iPosition--;
        break;
      case CMagneticView::SPECIAL_KEYS + VK_RIGHT:  // Cursor right
        if (iPosition < strFullLine.GetLength())
          iPosition++;
        break;
      case CMagneticView::SPECIAL_KEYS + VK_HOME:    // Home
        iPosition = 0;
        break;
      case CMagneticView::SPECIAL_KEYS + VK_END:    // End
        iPosition = strFullLine.GetLength();
        break;
      case CMagneticView::SPECIAL_KEYS + VK_DELETE:  // Delete
        if (iPosition < strFullLine.GetLength())
        {
          iRemovePos = strFullLine.GetLength() - iPosition;
          pView->RemoveChar(strFullLine,iRemovePos);
          pView->RemoveChar(pView->m_strOutput,iRemovePos,TRUE);
        }
        break;
      case 8:                                        // Backspace
        if (iPosition > 0)
        {
          iRemovePos = strFullLine.GetLength() - iPosition + 1;
          pView->RemoveChar(strFullLine,iRemovePos);
          pView->RemoveChar(pView->m_strOutput,iRemovePos,TRUE);
          iPosition--;
        }
        break;
      case CMagneticView::SPECIAL_KEYS + VK_UP:      // Cursor up
        if (iHistory < pView->m_History.GetSize()-1)
          iHistory++;
        if ((iHistory >= 0) && (pView->m_History.GetSize() > 0))
        {
          int iOldLength = strFullLine.GetLength();
          strFullLine = pView->m_History[iHistory];
          pView->UseHistory(strFullLine,iOldLength);
          iPosition = strFullLine.GetLength();
        }
        break;
      case CMagneticView::SPECIAL_KEYS + VK_DOWN:    // Cursor down
        if (iHistory > 0)
          iHistory--;
        if ((iHistory >= 0) && (pView->m_History.GetSize() > 0))
        {
          int iOldLength = strFullLine.GetLength();
          strFullLine = pView->m_History[iHistory];
          pView->UseHistory(strFullLine,iOldLength);
          iPosition = strFullLine.GetLength();
        }
        break;
      case CMagneticView::SPECIAL_KEYS + VK_SPACE:  // Space
        iInsertPos = strFullLine.GetLength() - iPosition;
        pView->InsertChar(pView->m_strOutput,(char)cInput,iInsertPos,TRUE);
        pView->InsertChar(strFullLine,(char)cInput,iInsertPos);
        iPosition++;
        break;
      default:
        if (isprint(cInput) && (cInput < CMagneticView::SPECIAL_KEYS))
        {
          // Insert the character into the input string
          iInsertPos = strFullLine.GetLength() - iPosition;
          pView->InsertChar(pView->m_strOutput,(char)cInput,iInsertPos,TRUE);
          pView->InsertChar(strFullLine,(char)cInput,iInsertPos);
          iPosition++;
        }
        break;
      }

      // Update the input line
      pView->InvalidateRect(pView->m_LastLineRect,FALSE);
    }
  }

  if (pView && (strFullLine.GetLength() > 0))
  {
    if (pView->m_bMorePrompt == false)
    {
      // Store in input history
      CString strHistory = strFullLine.Left(strFullLine.GetLength()-1);
      if (strHistory.GetLength() > 0)
      {
        pView->m_History.InsertAt(0,strHistory);
        if (pView->m_History.GetSize() > MAX_HISTORY)
          pView->m_History.RemoveAt(pView->m_History.GetSize()-1);
      }

      int i;
      while ((i = strHistory.Find((char)(CMagneticView::SPECIAL_KEYS + VK_SPACE))) >= 0)
        strHistory.SetAt(i,' ');

      // Input recording
      if ((pView->m_Recording == Recording::RecordingOn) && (pView->m_pFileRecord))
          fprintf(pView->m_pFileRecord,"%s\n",strHistory);

      // Scrollback buffer
      pView->m_Scrollback.GetScrollback() += strHistory;

      // Scripting
      if (pView->m_Scripting == Scripting::ScriptingOn)
        pView->m_strScript += strHistory;
    }

    if (trans && (strFullLine.CompareNoCase("#undo\n") == 0))
    {
      cInput = 0;
      strFullLine.Empty();
    }
    else
    {
      cInput = strFullLine[0];
      strFullLine = strFullLine.Right(strFullLine.GetLength()-1);
    }
  }

  if (pView)
  {
    pView->m_iLines = 0;
    pView->m_bInputActive = false;
    pView->CaretOff();
  }

  if (cInput == (signed char)(CMagneticView::SPECIAL_KEYS + VK_SPACE))
    cInput = ' ';

  return (char)cInput;
}
Example #21
0
void CCodeWin::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CFont* pOldFont;
	C6502_REGS	regs;
	bool foundpc=false;

	// Select in our font

	pOldFont=dc.SelectObject(mpCodeFont);

	// Find out the PC for highlighting

	mSystem.GetRegs(regs);

	if(mMemorySize>1)
	{
		CString	line;
		int	current_address,address,loop;

		// If in follow mode then check PC will be draw else adjust mAddress
		// we don't follow if the CPU is not running

		if(mFollowPC)
		{
			bool test=false;
			address=mAddress;
			for(loop=0;loop<mLineCount;loop++)
			{
				if(address==regs.PC) test=true;
				address=NextAddress(address);
			}
			if(!test) mAddress=regs.PC;
		}

		// Now repaint

		address=mAddress;

		for(loop=0;loop<mLineCount;loop++)
		{
			line="";
			current_address=address;
			address=Disassemble(line,address);

			
			for(int bps=0;bps<MAX_CPU_BREAKPOINTS;bps++)
			{		
				if(current_address==regs.cpuBreakpoints[bps])
				{
					line.SetAt(0,'*');
				}
			}

			if(current_address!=regs.PC)
			{
				dc.TabbedTextOut(0,loop*mCharHeight,line,7,mTabstops,0);
			}
			else
			{
				COLORREF back,front;
				front=dc.GetTextColor();
				back=dc.GetBkColor();
				dc.SetTextColor(back);
				dc.SetBkColor(front);
				dc.TabbedTextOut(0,loop*mCharHeight,line,7,mTabstops,0);
				dc.SetTextColor(front);
				dc.SetBkColor(back);
			}
		}
	}
	else
	{
		// We have selected an invalid memory range

		dc.TextOut(mCharWidth*12,(mLineCount/2-1)*mCharHeight,"CARTRIDGE BANK IS EMPTY");
	}

	// Select the old font back in

	dc.SelectObject(pOldFont);
}
Example #22
0
//下载像册信息
// http://u.8264.com/home-space-uid-16752722-do-album-id-1766.html
// http://u.8264.com/home-space-uid-16752722-do-album-id-1766-page-4.html#comment
bool CDolo8264COM::SearchLayer3(CString &str_url)
{
	CString cs_webContent;
	CString cs_tmp;
	int photo_num=0;		//像册数量
	int i_tmp;
	vector<string> astr;  //下载链接集合
	int m_page= 1;			//设置页面数
	CString cs_album_name;	//用户目录
	CString cs_sub_album;	//像册目录

	if(str_url.Find(_T("#comment")) < 0)
	{
		str_url.Delete(str_url.GetLength()-5,5);
		str_url+=_T("-page-1.html#comment");
	}
	else
		str_url.SetAt(str_url.GetLength()-14,_T('1'));

	//获得页面
	bool en_P=false;
	bool en_G=false;
	do 
	{
		cs_webContent.Empty();
		DownloadUrlPage(str_url,cs_webContent);	

		i_tmp = cs_webContent.Find(_T("张图片"),0);
		if(i_tmp>-1)
		{
			cs_tmp = cs_webContent.Left(i_tmp);
			cs_tmp = cs_tmp.Right(4);
			cs_tmp.TrimLeft(_T(" ")); 
			cs_tmp.TrimRight( _T(" "));
			if((atoi(cs_tmp)==0)||(cs_tmp.IsEmpty()))
			{
				return false;
			}
			else
				photo_num = atoi(cs_tmp);
		}
		//获得像册的题目
		if(en_P == false)
		{
			int i=cs_webContent.Find(_T("keywords\" content=\""),0);
			if(i>-1)
			{
				cs_sub_album= cs_webContent.Right(cs_webContent.GetLength() -i -19);
				cs_sub_album = cs_sub_album.Left(cs_sub_album.Find(_T("\"")));
				en_P = true;
			}
		}
		//获得用户题目cs_album_name
		if(en_G == false)
		{
			int i=cs_webContent.Find(_T("<h2 class=\"xs2\">"),0);
			if(i>-1)
			{
				i=cs_webContent.Find(_T("html"),i);
				cs_album_name= cs_webContent.Right(cs_webContent.GetLength() -i -6);
				cs_album_name = cs_album_name.Left(cs_album_name.Find(_T("<"),0));
				en_G = true;
			}
		}
		checkDirname(cs_album_name);
		checkDirname(cs_sub_album);
		CreateDirectory(_T("8264com\\")+cs_album_name,NULL);
		CreateDirectory(_T("8264com\\")+cs_album_name+_T("\\")+cs_sub_album,NULL);

		regex reg("html\"><img src=\"[a-zA-z]+://[^\\s]*thumb.jpg");  	//图片模式
		smatch m1; 

		string s = cs_webContent.GetBuffer();	
		string::const_iterator it = s.begin(); 
		string::const_iterator end=s.end();

		while(regex_search(it,end,m1,reg))
		{
/*			int size = m1[0].length();*/
			string msg(m1[0].first,m1[0].second);	
			msg.erase(0,16);
			msg.erase(msg.size()-10,msg.size());
			//astr.push_back(msg);
			
			s_dolo.cs_url=msg.c_str();
			s_dolo.cs_LocalFullPath=_T("8264com\\")+cs_album_name+_T("\\")+cs_sub_album;
			s_dolo.cs_ReferHead=_T("");
			v_doloST.push_back(s_dolo);

			it = m1[0].second; 
			msg.empty();
			myidle();
		}
		s.empty();

		str_url.Delete(str_url.Find(_T("page")),str_url.GetLength()-str_url.Find(_T("page")) );
		str_url.Insert(str_url.GetLength(), _T("page-"));
		CString tc;
		m_page++;
		tc.Format(_T("%d"),m_page);
		str_url.Insert(str_url.GetLength(), tc);
		str_url.Insert(str_url.GetLength(), _T(".html#comment"));	
		tc.Empty();
	} while (photo_num/20 +2 >m_page);
	


	// 	CString cs_album_name;	//主目录名字
	// 	int photo_num;		//像册数量
	// 	CString cs_sub_album;  //子相册名字
//	checkDirname(cs_album_name);


// 	st_lp.urlGroup=astr;
// 	st_lp.strFileURLInServer.IsEmpty();
// 	st_lp.strFileLocalFullPath=_T("8264com\\")+cs_album_name+_T("\\")+cs_sub_album;
// 	st_lp.strReferHead=_T("");					//_T("Referer: http://mm.taobao.com");
// 	st_lp.hWnd=(HWND)this;
// 	m_pMyThread=AfxBeginThread(Download1,(LPVOID)&st_lp);//&st_lp[n]);
// 	astr.empty();
	return true;
}
Example #23
0
HRESULT EMB::CTxTransFile::RegisterToDB()
{
	HRESULT hr = S_OK;
	if (m_nCurrDesSite < 0 || m_nCurrDesSite >= m_taskInfo.vSitDes.size())
	{
		ASSERT(FALSE);
		CFWriteLog(0, TEXT("no des site."));
	}
	ST_FTPSITEINFO& sitRef = m_taskInfo.vSitDes[m_nCurrDesSite];
	ASSERT(!sitRef.strDBConn.IsEmpty());
	srand(time(NULL));
	int nRandKey = rand()%10000;
	BOOL bOpen = CTxADODBMgr::GetADODBMgr()->OpenDB(nRandKey, sitRef.strDBConn);
	if (!bOpen)
	{
		hr = EMBERR_DBOPEN;
		CFWriteLog(0, TEXT("dbopen error! %s"), sitRef.strDBConn);
		return hr;
	}

	//organize sql
	CString strSqlReq;
	VECSTRINGS vSqlRun;
	strSqlReq.Format(TEXT("select strClipLogicID from T_BVSID where strClipLogicID = '%s'"), m_taskInfo.strClipLogicID);
	CTxADORecordSet rs(nRandKey);
	if (!rs.ExecuteSQL(strSqlReq))
	{
		hr = EMBERR_SQLEXEC;
		return hr;
	}
	
	CString strTmpSql;
	BOOL bUpdateMode = FALSE;
	CTime tmNow(time(NULL));
	CString strTimeNow = tmNow.Format(TEXT("%Y-%m-%d %H:%M:%S"));
	CString strLocation = TEXT("00000000000000000000000000000000");
	strLocation.SetAt(sitRef.nLocation -1, '1');

	if (!rs.IsEOF())
	{
		CString strClipId = rs.GetVal(TEXT("strClipID")).GetAsString();
		strLocation = rs.GetVal(TEXT("strLocation"), TEXT("00000000000000000000000000000000")).GetAsString(TEXT(""));
		ASSERT(strLocation.GetLength() > sitRef.nLocation);
		strLocation.SetAt(sitRef.nLocation -1, '1');
		if (strClipId.CompareNoCase(m_taskInfo.strClipID) == 0)
		{
			CFWriteLog(0, TEXT("clip already existed in t_bvsid,only update location."));
			//same clipid, update location
			strTmpSql.Format(TEXT("update T_BVSID set strLocation = '%s' where strClipID = '%s'"), m_taskInfo.strClipLogicID);
			vSqlRun.push_back(strTmpSql);
		}
		else
		{
			CFWriteLog(0, TEXT("clip already existed in t_bvsid, but clipid not same [old:%s][new:%s], delete it and continue"), strClipId, m_taskInfo.strClipID);
			//delete old
			strTmpSql.Format(TEXT("delete from t_bvsid where strClipLogicID = '%s'"), m_taskInfo.strClipLogicID);
			vSqlRun.push_back(strTmpSql);

		}
	}

	if (!bUpdateMode)
	{
		strTmpSql.Format(TEXT("insert into T_BVSID ([strClipID],[strClipName],[strClipLogicID],[strSOM] ,[strEOM], [strDuration] \
							  ,[strLSOM],[strLEOM],[strLDuration],[strLocation],[nDelete],[nReady],[nCheck] ,[nClipType] \
							  ,[strChnID],[tPlanAirTime],[tPlanLastAirTime],[tDubDateTime],[strDubBy],[nBitRate],[strMD5] \
							  )values('%s', '%s', '%s', '%s', '%s', '%s' \
							  , '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d' \
							  , '%s', '%s', '%s', '%s', '%s', '%d', '%s');"), 
							  m_taskInfo.strClipID, m_taskInfo.dbBvsInfo.strClipName,  m_taskInfo.strClipLogicID, m_taskInfo.dbBvsInfo.strSOM, m_taskInfo.dbBvsInfo.strEOM, m_taskInfo.dbBvsInfo.strDuration,
							  m_taskInfo.dbBvsInfo.strLSOM, m_taskInfo.dbBvsInfo.strLEOM, m_taskInfo.dbBvsInfo.strLDuration, strLocation, 0, 1, 0, m_taskInfo.dbBvsInfo.nClipType, 
							  m_taskInfo.dbBvsInfo.strChID, m_taskInfo.dbBvsInfo.tPlanAirTime, m_taskInfo.dbBvsInfo.tPlanLastAirTime, strTimeNow, TEXT("EMB"), m_taskInfo.dbBvsInfo.nBitRate, m_strMD5Val);
		vSqlRun.push_back(strTmpSql);

	}