Exemplo n.º 1
0
void trackconnect::OnBnClickedButtonConnect()
{
	char *fileName = "loginInfo.txt";
	//CFile myFile;
	CFileException fileException;
	CStdioFile myFile;

	CString usrename, passwd;
	BYTE nf1, nf2, nf3, nf4;
	m_ip.GetAddress(nf1, nf2, nf3, nf4);
	m_strIp.Format("%d.%d.%d.%d", nf1, nf2, nf3, nf4);//这里的nf得到的值是IP值了.
	strcpy(m_connectInfo.Ip, m_strIp.GetString());
	m_username.GetWindowText(usrename);
	m_passwd.GetWindowText(passwd);
	if (strcmp(m_strIp.GetString(), "0.0.0.0") == 0)
	{
		MessageBox("IP为空");
		return;
	}
	if (strcmp(usrename.GetString(), "") == 0)
	{
		MessageBox("用户名为空");
		return;
	}
	memcpy(m_connectInfo.passwd, passwd.GetString(), sizeof(m_connectInfo.passwd));
	memcpy(m_connectInfo.username, usrename.GetString(), sizeof(m_connectInfo.username));
	if (m_initNetFun)
	{
		m_initNetFun(m_DialogParam, &m_connectInfo);
	}
	BOOL openResult = myFile.Open(fileName, CFile::modeCreate | CFile::modeReadWrite);
	if (!openResult)
	{
		MessageBox(_T("打开文件错误!"));
	}
	else
	{
		myFile.SeekToBegin();
		myFile.WriteString(usrename);
		myFile.Write(("\r\n"), 2);
		myFile.WriteString(m_strIp);
		myFile.Write(("\r\n"), 2);
		myFile.Flush();
		myFile.Close();
	}
	// TODO: Add your control notification handler code here
}
void AddLog(LPCTSTR lpstrLog,...)
{
	if (!bOpened)
		return;
	try
	{
		CString			csBuffer;
		va_list			argList;

		// Format arguments
		va_start(argList, lpstrLog);
		csBuffer.FormatV( lpstrLog, argList);
		va_end( argList);
		// Write string
		myFile.WriteString( csBuffer);
		myFile.Flush();
	}
	catch (CException *pEx)
	{
		pEx->Delete();
		myFile.Abort();
	}
}
Exemplo n.º 3
0
void CDlgNote::OnBnClickedButtonSave()
{
	// TODO: 在此添加控件通知处理程序代码
	int nCount=m_List_ctlTitle.GetItemCount();
	if(nCount<=0)return;
	UpdateData(TRUE);
	UpdateData(FALSE);
	CString strTitle=_T("");
	CString strOldPath=_T("");
	int nCurrentSelect=0;
	BOOL bSelect=FALSE;
	for(int i=0; i<m_List_ctlTitle.GetItemCount(); i++) 
	{ 
		if( m_List_ctlTitle.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED ) 
		{ 

			strTitle=m_List_ctlTitle.GetItemText(i, 0);
			strOldPath=m_List_ctlTitle.GetItemText(i, 1);
			nCurrentSelect=i;
			bSelect=TRUE;
		} 
	}
	if (bSelect==FALSE)
	{

		return;
	}
	if (strTitle.IsEmpty())
	{

		MessageBox(_T("备忘标题不能为空!"),_T("波波丁财富记"),MB_OK);
		return;
	}
	CString strRepeat=_T("");
	for(int i=0; i<m_List_ctlTitle.GetItemCount(); i++) //判断是否有重复的标题名
	{ 
		if( m_List_ctlTitle.GetItemState(i, LVIS_SELECTED) != LVIS_SELECTED ) 
		{ 

			strRepeat=m_List_ctlTitle.GetItemText(i, 0);
			if (strRepeat.Compare(strTitle)==0)
			{
				MessageBox(_T("备忘标题不能重复!"),_T("波波丁财富记"),MB_OK);
				return;
			}
		} 
	}


	Invalidate(TRUE);
	setlocale( LC_CTYPE, "chs" );//设定
	/******************************************************************************/

	CString strTemp=m_Edit_strContent;
	CString strSavePath;
	strSavePath=CBoBoDingApp::g_strNotePath+m_Edit_strTitle+_T(".txt");
	/******************************************************************************/
	//文件重命名
	if(!strOldPath.IsEmpty())
	{


		_wrename(strOldPath, strSavePath);

		m_List_ctlTitle.SetItemText(nCurrentSelect,1,strSavePath);


	}
	/******************************************************************************/
	CStdioFile  File;
	strTemp.ReleaseBuffer();
	File.Open(strSavePath,CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );//如果文件事先不存在的话,就需要CFile::modeCreate,否则就不需要。 
	File.WriteString(strTemp);
	File.Flush();
	File.Close();


	MessageBox(_T("保存成功!"),_T("波波丁财富记"),MB_OK);

	/******************************************************************************/



}