⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 一个源代码管理工具,支持悬浮框拖曳,后台数据库管理,代码高亮显示灯功能
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				if(ret == IDCANCEL)
					return ;

			}
				
		}
		edit.SetModify(FALSE);
	}
	
	CFileDialog fd (TRUE, _T(""), NULL, OFN_HIDEREADONLY|OFN_EXPLORER|OFN_NOCHANGEDIR, "*.*|*.*||"); 
	if(IDCANCEL == fd.DoModal())
	{
		return;
	}	
	m_strFileName = fd.GetPathName();
	
	EditView->LoadFile(m_strFileName);
	EditView->SelectLanguage(_CPP);
}

void CMainFrame::SaveContext()
{
	CCodeManagerView *EditView = (CCodeManagerView *)GetActiveView();
	CRichEditCtrl &richctrl=EditView->GetRichEditCtrl();
	
	if(0 == m_strFileName.GetLength())
		return;

	CFile cFile(m_strFileName, CFile::modeCreate|CFile::modeWrite);
	EDITSTREAM es;
	es.dwCookie = (DWORD) &cFile;
	es.pfnCallback = EditStreamCallbackWriteToFile; 
	richctrl.StreamOut(SF_TEXT, es);
	richctrl.SetModify(FALSE); 
}


void CMainFrame::OnFileMysave() 
{
	if(m_bdType)
	{
		CCodeManagerView *EditView = (CCodeManagerView *)GetActiveView();
		CRichEditCtrl &edit = EditView->GetRichEditCtrl();
		CString strText;
		edit.GetWindowText(strText);
		BYTE *pBuf = (BYTE*)strText.GetBuffer(strText.GetLength());
		CString strvalue = "select * from CodeTable where CodeID = ", strdata;
		long lvalue = m_wndTree.GetItemData(m_wndTree.GetSelectedItem());
		strdata.Format("%ld", lvalue);
		strvalue = strvalue + "" + strdata +"";
		m_DbObject.GetValue(strvalue);

		m_DbObject.SetDataChunk(pBuf);
		m_DbObject.Update();
		strText.ReleaseBuffer();

		edit.SetModify(FALSE);
	}
	else
	{
		if(m_strFileName.IsEmpty())
		{
			CFileDialog fd (TRUE, _T(""), NULL, OFN_HIDEREADONLY|OFN_EXPLORER|OFN_NOCHANGEDIR, "*.*|*.*||"); 
			if(fd.DoModal()==IDCANCEL)
				return;
			m_strFileName = fd.GetPathName();
		}
		SaveContext();	
	}


}

void CMainFrame::OnViewList() 
{
	// TODO: Add your command handler code here
	ShowControlBar(&m_DownBar, !m_DownBar.IsVisible(), FALSE);
}

void CMainFrame::OnUpdateViewList(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_DownBar.IsVisible())
		pCmdUI->SetCheck(TRUE);
	else
		pCmdUI->SetCheck(FALSE);
}

void CMainFrame::OnViewFile() 
{
	// TODO: Add your command handler code here
	ShowControlBar(&m_LeftBar, !m_LeftBar.IsVisible(), FALSE);
}

void CMainFrame::OnUpdateViewFile(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_LeftBar.IsVisible())
		pCmdUI->SetCheck(TRUE);
	else
		pCmdUI->SetCheck(FALSE);
}

void CMainFrame::OnDbView() 
{
//	COleDateTime oleDt=COleDateTime::GetCurrentTime();
//	CString strFileName=oleDt.Format("%y年%m月%d日");
//	AfxMessageBox(strFileName);
	// TODO: Add your command handler code here
	_RecordsetPtr m_pRecordset;
	m_pRecordset.CreateInstance("ADODB.Recordset");

	//可
/*	_variant_t RecordsAffected,count;
	//m_pRecordset = m_pConnection->Execute("SELECT * FROM CodeTable",&RecordsAffected,adCmdText);
	m_pRecordset->Open("select * from CodeTable",_variant_t((IDispatch *)m_pConnection),adOpenStatic,adLockOptimistic,adCmdText);
	_variant_t vIndex = (long)0 , vcount, t;
	vcount = m_pRecordset->GetCollect(vIndex);
	CString str;
	str = (LPCTSTR)(_bstr_t)vcount;
	MessageBox(str);

/*	CString str1 = "asdfdfhfghj";
	m_pRecordset->AddNew();//添加新记录
	m_pRecordset->PutCollect("CodeName",_variant_t(str1));
	m_pRecordset->PutCollect("CodePath",_variant_t("c:\\"));
	CString strsql;
	m_pRecordset->Update();*/
//	strsql.Format("delete from CodeTable where CodeID = %d",3);
	//ok
	/*m_pConnection->Execute("delete from CodeTable where CodeID = 9",&RecordsAffected,adCmdText);
	if(RecordsAffected.lVal != 0)
		MessageBox("该记录已被删除");*/
	//m_pRecordset->Open("delete from CodeTable where CodeID = 6",_variant_t((IDispatch *)m_pConnection),adOpenStatic,adLockOptimistic,adCmdText);
//	m_pRecordset->Delete(adAffectCurrent);
/*	_CommandPtr m_pCommand;
	m_pCommand.CreateInstance("ADODB.Command");
	_variant_t vNULL;
	vNULL.vt = VT_ERROR;
	vNULL.scode = DISP_E_PARAMNOTFOUND;///定义为无参数
	m_pCommand->ActiveConnection = m_pConnection;///非常关键的一句,将建立的连接赋值给它
	m_pCommand->CommandText = "delete from CodeTable where CodeID = '3'";///命令字串
	m_pCommand->Execute(&vNULL,&vNULL,adCmdText);///执行命令,取得记录集*/

/*	vIndex = (long)1;
	vcount = m_pRecordset->GetCollect(vIndex);
	str = (LPCTSTR)(_bstr_t)vcount;
	MessageBox(str);*/

//	m_pRecordset->Open("insert into CodeTable values(1,1,1,1,1,1,1,1) ",_variant_t((IDispatch *)m_pConnection),adOpenStatic,adLockOptimistic,adCmdText);
//	m_pRecordset->Update();
//	MessageBox("success");

	  CFile f;
	  CString  FilePathName, stestr = "jpg Files (*.jpg)|*.*||";
	  CFileException e;

      CFileDialog dlg(TRUE,NULL,NULL,0, stestr, this);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
      
	  if(dlg.DoModal()==IDOK)
      {FilePathName=dlg.GetPathName();

//	if(m_Pic.m_IPicture != NULL) m_Pic.FreePictureData(); // Important - Avoid Leaks...

	if(f.Open(FilePathName, CFile::modeRead | CFile::typeBinary, &e)) //打开了一个jpg文件
	{	

		int nSize = f.GetLength();          //先得到jpg文件长度
		BYTE * pBuffer = new BYTE [nSize];  //按文件的大小在堆上申请一块内存
	 
		if (f.Read(pBuffer, nSize) > 0 )    //把jpg文件读到pBuffer(堆上申请一块内存)
		{   // +----------------------------------------------
						BYTE *pBuf = pBuffer;     ///下面这一大段是把pBuffer里的jpg数据放到库中
						VARIANT			varBLOB;
						SAFEARRAY		*psa;
					    SAFEARRAYBOUND	rgsabound[1];
				
						m_pRecordset->AddNew();  
							
						if(pBuf)
							{    
							rgsabound[0].lLbound = 0;
							rgsabound[0].cElements = nSize;
							psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
						/*	for (long i = 0; i < (long)nSize; i++)
								SafeArrayPutElement (psa, &i, pBuf++);*/

							 BYTE *buf;
							 ::SafeArrayAccessData(psa, (void **)&buf);
							 for(long index=0;index<nSize;index++)          
							 {
							  buf[index]=pBuffer[index];  
							 }
							 ::SafeArrayUnaccessData(psa);

							varBLOB.vt = VT_ARRAY | VT_UI1;
							varBLOB.parray = psa;
							m_pRecordset->GetFields()->GetItem("CodeData")->AppendChunk(varBLOB);
							}
						m_pRecordset->Update();
						
			// +----------------------------------------------


	//		(m_Pic.LoadPictureData(pBuffer, nSize));//接作调用函数读pBuffer的jpg数据准备显示
			delete [] pBuffer;     //删掉堆上申请的那一块内存
			pBuf=0;                //以防二次乱用
		}
		f.Close();
	
}
 
	  }	
	  
	
	
}

void CMainFrame::OnTestGet() 
{
	// TODO: Add your command handler code here
	int j;
	CString str,st;
	HTREEITEM hItem;
	hItem = m_wndTree.GetSelectedItem();
	j = m_wndTree.GetItemData(hItem);
	st = m_wndTree.GetItemText(hItem);
	str.Format("Data is %d Text is %s",j,st);
	MessageBox(str);
}

void CMainFrame::OnFileFileimport() 
{
	ImportFile();
}

void CMainFrame::OnFileNew() 
{
	// TODO: Add your command handler code here
	CCodeManagerView *EditView = (CCodeManagerView *)GetActiveView();
	CRichEditCtrl &edit = EditView->GetRichEditCtrl();
	if(!m_strFileName.IsEmpty())
	{
		if(edit.GetModify())
		{
			if(m_bdType)
			{
				HTREEITEM hs = m_wndTree.GetSelectedItem();
				CString str = "文件";
				str += m_wndTree.GetItemText(hs);
				str += "内容已发生改变,是否保存到数据库?";
				int ret = MessageBox(str, "代码利器", MB_YESNOCANCEL|MB_ICONQUESTION);
				if(ret == IDYES)
				{
					CCodeManagerView *EditView = (CCodeManagerView *)GetActiveView();
					CRichEditCtrl &edit = EditView->GetRichEditCtrl();
					CString strText;
					edit.GetWindowText(strText);
					BYTE *pBuf = (BYTE*)strText.GetBuffer(strText.GetLength());
					CString strvalue = "select * from CodeTable where CodeID = ", strdata;
					long lvalue = m_wndTree.GetItemData(m_wndTree.GetSelectedItem());
					strdata.Format("%ld", lvalue);
					strvalue = strvalue + "" + strdata +"";
					m_DbObject.GetValue(strvalue);

					m_DbObject.SetDataChunk(pBuf);
					m_DbObject.Update();
					strText.ReleaseBuffer();

					edit.SetModify(FALSE);
				}
				if(ret == IDCANCEL)
					return;

			}
			else
			{
		/*		if(m_strFileName.IsEmpty())
				{
					int ret2 = MessageBox("文件内容已发生改变,想保存文件吗?", "代码利器", MB_YESNOCANCEL|MB_ICONQUESTION);
					if(ret2 == IDYES)
					{					
						CFileDialog fd (FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.*|*.*||")); 
						if(fd.DoModal() == IDOK)
						{
							m_strFileName = fd.GetPathName();
							SaveContext();
						}
					}
					if(ret2 == IDCANCEL)
						return ;
				}
				else
				{*/
				CString str = "文件";
				str += m_strFileName;
				str += "内容已发生改变,想保存文件吗?";
				int ret = MessageBox(str, "代码利器", MB_YESNOCANCEL|MB_ICONQUESTION);

				if(ret == IDYES)
					SaveContext();
				if(ret == IDCANCEL)
					return ;

				//}
					
			}
			edit.SetModify(FALSE);
		}
	}
	
	edit.SetWindowText("");
	m_strFileName = "";
	m_bdType = FALSE;
	EditView->SetSynEditViewFont(EditView->GetSynEditViewFont());
	
}

void CMainFrame::OnTestRead() 
{
	_RecordsetPtr m_pRecordset;
	m_pRecordset.CreateInstance("ADODB.Recordset");
	//可
	_variant_t RecordsAffected,count;
	//m_pRecordset = m_pConnection->Execute("SELECT * FROM CodeTable",&RecordsAffected,adCmdText);
	m_pRecordset->Open("select * from CodeTable",_variant_t((IDispatch *)m_pConnection),adOpenStatic,adLockOptimistic,adCmdText);
	try
	{
		long nSize = m_pRecordset->GetFields()->GetItem("CodeData")->ActualSize;
		if(nSize > 0)
		{
			_variant_t	varBLOB;
			varBLOB = m_pRecordset->GetFields()->GetItem("CodeData")->GetChunk(nSize);
			if(varBLOB.vt == (VT_ARRAY | VT_UI1))
			{
				if(BYTE *pBuffer = new BYTE [nSize+1])		///重新申请必要的存储空间
				{	
					char *pBuf = NULL;
					SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
					memcpy(pBuffer,pBuf,nSize);				///复制数据到缓冲区m_pBMPBuffer
					SafeArrayUnaccessData (varBLOB.parray);
				//	int nSize = lDataSize;

					CString str;
					str.Format("%s", pBuf);
					//strcpy(str,pBuffer);
					CCodeManagerView *EditView = (CCodeManagerView *)GetActiveView();
					EditView->LoadText(str);
					EditView->SelectLanguage(_CPP);

					 delete [] pBuffer;
					 pBuf=0;
					 
				}
			}
		}
	}
	catch (_com_error e) {
	}
		
}

void CMainFrame::BrowseDir(CString strDir, CCoolTreeCtrl &m_wndTree, HTREEITEM hti)
{
	CFileFind ff;
    CString szDir = strDir;
	HTREEITEM hti2;
    if(szDir.Right(1) != "\\")
       szDir += "\\";

    szDir += "*.*";

    BOOL res = ff.FindFile(szDir);
    while(res)
	{
		res = ff.FindNextFile();
		hti2=hti;

		CString str, dbstr[6];

        if(ff.IsDirectory() && !ff.IsDots())
		{
			//如果是一个子目录,用递归继续往深一层找
			HTREEITEM hti1;
			
			str.Format("%s", ff.GetFileName());
			hti1=m_wndTree.InsertItem(_T(str), hti);
			m_wndTree.SetItemImage(hti1, 0, 0);

			dbstr[0] = str;
			dbstr[1].Empty();
		//	dbstr[2].Format("%s", "2004-10-05");
			COleDateTime oleDt = COleDateTime::GetCurrentTime();
			dbstr[2]=oleDt.Format("%y年%m月%d日");

			if(hti != NULL)
				dbstr[3].Format("%ld", m_wndTree.GetItemData(hti));

			dbstr[4].Format("%s", "1");//0为文件
			m_DbObject.AddRecord(dbstr);

			_variant_t vtemp;
			vtemp = m_DbObject.m_pRecordset->GetCollect("CodeID");
			m_wndTree.SetItemData(hti1, long(vtemp));

			hti=hti1;
			
			BrowseDir(ff.GetFilePath(),m_wndTree,hti);
		}
		else if(!ff.IsDirectory() && !ff.IsDots())
		{
			//显示当前访问的文件
		//	CString str, dbstr[6];
		//	CString strexp;
			int i,j;
			str.Format("%s",ff.GetFileName());

			for(i = str.GetLength() - 1; i >= 0; i--)
			{
				if(str.GetAt(i) == '.')
					break;
			}

			if(i >= 0)
			{
			/*	strexp = str;

				for(j = 0; i < str.GetLength(); j++)
				{
					strexp.SetAt(j, str.GetAt(i));
					i++;
				}
				strexp.SetAt(j, '\0');

				for(i = 0; i < 8; i++)
				{
					if(FileExp[i] == strexp)
						break;
				}*/

				//下面这段代码应该比上面这段代码快
				/*********/
				int index;
				char *p = str.GetBuffer(str.GetLength());

				p += i;

				for(i = 0; i < m_nFileNum; i++)
				{
					if(NewFileExp[i] == p)
						break;
				}
				/*********/

				if(i < m_nFileNum)
				{
					HTREEITEM hti1;
					hti1 = m_wndTree.InsertItem(_T(str), hti);
					m_wndTree.SetMyItemImage(hti1, str);

					dbstr[0] = str;
					dbstr[1].Format("%s", ff.GetFilePath());
					dbstr[2].Format("%s", "2004-10-05");
					COleDateTime oleDt = COleDateTime::GetCurrentTime();
					dbstr[2]=oleDt.Format("%y年%m月%d日");

					if(hti != NULL)
						dbstr[3].Format("%ld", m_wndTree.GetItemData(hti));

					dbstr[4].Format("%s", "0");//0为文件
					m_DbObject.AddRecord(dbstr);

					_variant_t vtemp;
					vtemp = m_DbObject.m_pRecordset->GetCollect("CodeID");
					m_wndTree.SetItemData(hti1, long(vtemp));
				}
			}

		}
		hti=hti2;
	}
	ff.Close();//关闭
}

void CMainFrame::OnFileDirimport() 
{
	ImportDir();
}

int CMainFrame::TakeDirDialog(CString &str)
{
//	CString str;
	BROWSEINFO bi;
	char name[255];
	ZeroMemory(&bi, sizeof(BROWSEINFO));
	bi.hwndOwner = GetSafeHwnd();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -