Esempio n. 1
0
// Insert	- Inserts a sub string into the string
// Returns	- Reference to the same string object
// pos		- Position to insert at. Extends the string with spaces if needed
// s		- Sub string to insert
CStringEx& CStringEx::Insert(int pos, LPCTSTR s)
{
	int len = lstrlen(s);
	if ( len == 0 )
		return *this;

	int oldlen = GetLength();
	int newlen = oldlen + len;
	LPTSTR str;
	if ( pos >= oldlen )
	{			
		// insert after end of string
		newlen += pos - oldlen ;
		str = GetBuffer( newlen );
		_tcsnset( str+oldlen, _T(' '), pos-oldlen );
		_tcsncpy( str+pos, s, len );
	}
	else
	{	
		// normal insert
		str = GetBuffer( newlen );
		memmove( str+pos+len, str+pos, sizeof(_T(' ')) *(oldlen-pos) );
		_tcsncpy( str+pos, s, len );
	}
	ReleaseBuffer( newlen );

	return *this;
}
Esempio n. 2
0
static VOID
ClearCommandLine(LPTSTR str, INT maxlen, SHORT orgx, SHORT orgy)
{
    INT count;

    SetCursorXY (orgx, orgy);
    for (count = 0; count < (INT)_tcslen (str); count++)
        ConOutChar (_T(' '));
    _tcsnset (str, _T('\0'), maxlen);
    SetCursorXY (orgx, orgy);
}
Esempio n. 3
0
/* Starts tagFormattedData_J1939 related codes */
tagFormattedData_J1939::tagFormattedData_J1939()
{
    _tcsnset(m_acTimeSys,   L'\0', LEN_STR_TIMESTAMP_J1939);
    _tcsnset(m_acTimeRel,   L'\0', LEN_STR_TIMESTAMP_J1939);
    _tcsnset(m_acTimeAbs,   L'\0', LEN_STR_TIMESTAMP_J1939);

    _tcsnset(m_acMsgType,   L'\0', LEN_STR_TYPE_J1939     );
    _tcsnset(m_acChannel,   L'\0', LEN_STR_CHANNEL_J1939  );

    _tcsnset(m_acPGNHex,    L'\0', LEN_STR_PGN_J1939      );
    _tcsnset(m_acPGNDec,    L'\0', LEN_STR_PGN_J1939      );
    _tcsnset(m_acMsgName,   L'\0', LEN_STR_NAME_J1939     );
    _tcsnset(m_acSenderName,L'\0', LEN_STR_SENDNODE_J1939 );

    _tcsnset(m_acSrcHex,    L'\0', LEN_STR_SRC_J1939      );
    _tcsnset(m_acSrcDec,    L'\0', LEN_STR_SRC_J1939      );
    _tcsnset(m_acDestHex,   L'\0', LEN_STR_DEST_J1939     );
    _tcsnset(m_acDestDec,   L'\0', LEN_STR_DEST_J1939     );


    _tcsnset(m_acPriority,  L'\0', LEN_STR_PRIO_J1939     );
    _tcsnset(m_acMsgDir,    L'\0', LEN_STR_DIR_J1939      );
    _tcsnset(m_acDataLen,   L'\0', LEN_STR_DLC_J1939      );

    m_acMsgDir[LEN_STR_DIR_J1939 - 2] = L'x'; // It will be either Tx or Rx

    m_pcDataHex = NULL;
    m_pcDataDec = NULL;
}
Esempio n. 4
0
HRESULT DeleteItemInCfgFile(IN LPTSTR szSection, IN LPTSTR szName, IN ITEM_TYPE iItemType,LPTSTR szCfgFile)
{
  HRESULT Hr=S_OK;
  //	TCHAR szCfgFile[MAX_PATH]=_T("");
  //	TCHAR szSection[MAX_PATH]=_T("");
  //	OpenDirInCfgFile(pidlCurDir,szSection,szCfgFile);
  //
  //    //3.Get the name of pidl
  //	CNWSPidlMgr pidlMgr;
  //    TCHAR szName[MAX_PATH]={};
  //    HR(pidlMgr.GetName(pidlItem,szName));
  //    //4.Get the type of pidl
  //    ITEM_TYPE iItemType;
  //     iItemType = pidlMgr.GetItemType(pidlItem);

  DWORD dwCheck;
  TCHAR tmpStr[MAX_PATH]={};
  DWORD dwLen=MAX_PATH;
  if( iItemType == NWS_FOLDER )
  {
    dwCheck = GetPrivateProfileString( szSection,_T("dir"),_T(""),tmpStr,dwLen, szCfgFile);
  }
  else if( iItemType == NWS_FILE )
  {
    dwCheck = GetPrivateProfileString( szSection,_T("file"),_T(""),tmpStr,dwLen, szCfgFile);
  }

  //5. delete the name of pidl if it exist in tmpStr and form a newstr
  TCHAR szNewStr[MAX_PATH]={};
  if(_tcsstr(tmpStr,szName)==NULL) //basiclly filter
  {
    MessageBox(NULL,_T("DeleteItemInCfgFile: the pidl to be deleted can't be found in current folder!"),_T("Error"),MB_OK);
    return E_FAIL;
  }

  INT iNameLen= (INT)_tcslen(szName);
  INT iStrLen = (INT)_tcslen(tmpStr);
  INT iPos = 0;
  TCHAR *pSplitChr=NULL;
  BOOL bFound=FALSE;
  while(iPos + iNameLen <= iStrLen)
  {
    if( iPos + iNameLen == iStrLen) 
    {
      if(_tcsncmp(tmpStr+iPos,szName,iNameLen) == 0) //is the tail item
      {
        //iPos=0:is the only one item; iPos!=0:has more than one items
        if(iPos != 0) 
          _tcsncpy(szNewStr,tmpStr,iPos-1);
        bFound=TRUE;
        break;
      }
    }
    else
    {
      pSplitChr=_tcschr(tmpStr+iPos,_T(';'));
      if(pSplitChr == NULL)
        break;
      if( ((pSplitChr-(tmpStr+iPos)) == iNameLen) && 
        (_tcsncmp(tmpStr+iPos,szName,iNameLen) == 0) )
      {
        _tcsncpy(szNewStr,tmpStr,iPos);
        _tcscat(szNewStr,pSplitChr+1);
        bFound=TRUE;
        break;
      }
      else
      {
        iPos = (INT)(pSplitChr - (TCHAR*)tmpStr[0] + 1);
      }
    }
  }
  if(bFound == FALSE)
  {
    MessageBox(NULL,_T("DeleteItemInCfgFile: pidl ready to delete can't be find in current folder!"),_T("Error"),MB_OK);
    return E_FAIL;
  }

  //6. delete the old keyvalue and insert the new keyvalue
  if( iItemType == NWS_FOLDER )
  {
    if(_tcslen(szNewStr)!=0)
      dwCheck = WritePrivateProfileString( szSection,_T("dir"),szNewStr,szCfgFile);
    else
      dwCheck = WritePrivateProfileString( szSection,_T("dir"),NULL,szCfgFile);


    //Delete the deleted folder's corresponding section from cfg file
    //Notes:
    //To make this sample project perfect,indeed,we need to
    //recursively delete all the sub folders corresponding sections
    //from configuration file, to do this will spend lots.
    //
    //However, for our purpose is to describe how to delete/create folder,
    //for simplicity, we only delete the section which directly
    //referred by the deleted folder object from configuration file.

    if(_tcscmp(szSection,_T("ROOT"))==0)
    {
      _tcsnset(szSection,0,MAX_PATH);
      _tcscpy(szSection,szName);
    }
    else
    {
      _tcscat(szSection,_T("\\"));
      _tcscat(szSection,szName);
    }
    WritePrivateProfileString(szSection,NULL,NULL,szCfgFile);
  }
  else if( iItemType == NWS_FILE )
  {
    if(_tcslen(szNewStr)!=0)
      dwCheck = WritePrivateProfileString( szSection,_T("file"),szNewStr,szCfgFile);
    else
      dwCheck = WritePrivateProfileString( szSection,_T("file"),NULL,szCfgFile);
  }
  return Hr;
}