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

📄 finddlg.cpp

📁 一个源代码管理工具,支持悬浮框拖曳,后台数据库管理,代码高亮显示灯功能
💻 CPP
字号:
// FindDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CodeManager.h"
#include "FindDlg.h"
#include "MainFrm.h"
#include "CodeManagerView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFindDlg dialog
IMPLEMENT_DYNCREATE(CFindDlg, CDialog)

CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFindDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFindDlg)
	m_ctrlIndex = _T("");
	//}}AFX_DATA_INIT
}


void CFindDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFindDlg)
	DDX_Control(pDX, IDC_RESULTLIST, m_resultList);
	DDX_Control(pDX, IDC_SHOWBUT, m_showBuf);
	DDX_Control(pDX, IDC_INDEXEDIT, m_indexEdit);
	DDX_Control(pDX, IDC_INDEXSTATIC, m_ctrIndexSt);
	DDX_Text(pDX, IDC_INDEXEDIT, m_ctrlIndex);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFindDlg, CDialog)
	//{{AFX_MSG_MAP(CFindDlg)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BUTSEARCH, OnButsearch)
	ON_LBN_DBLCLK(IDC_RESULTLIST, OnDblclkResultlist)
	ON_BN_CLICKED(IDC_SHOWBUT, OnShowbut)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFindDlg message handlers

void CFindDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	CRect rect;
	GetWindowRect(&rect);
	if(m_resultList.m_hWnd != NULL)
		m_resultList.MoveWindow(0, 46, rect.Width()-6, rect.Height()-70);
	if(m_showBuf.m_hWnd != NULL)
		m_showBuf.MoveWindow(rect.Width()-78, rect.Height()-22, 72, 20);
	// TODO: Add your message handler code here
}

void CFindDlg::OnButsearch() 
{
	// TODO: Add your control notification handler code here
	m_resultList.ResetContent();
	UpdateData();
//	m_indexEdit;

	CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();

	CString strvalue = "select * from CodeTable where CodeName like ";
	strvalue = strvalue + "'" + "%" + m_ctrlIndex + "%" + "'";

	pFrame->m_DbObject.GetValue(strvalue);

	_variant_t vname;
	long lvalue;
	while(!pFrame->m_DbObject.m_pRecordset->adoEOF)
	{
		vname = pFrame->m_DbObject.m_pRecordset->GetCollect("CodeName");
	//	MessageBox((LPCTSTR)(_bstr_t)vname);
		int index = m_resultList.AddString((LPCTSTR)(_bstr_t)vname);
		lvalue = (long)pFrame->m_DbObject.m_pRecordset->GetCollect("CodeID");
		m_resultList.SetItemData(index, lvalue);
		pFrame->m_DbObject.m_pRecordset->MoveNext();
	}
/*	CString str;
	long lt, ldir, ltype;
	_variant_t vname, vtemp, vt;
	HTREEITEM ht;
	while(!m_DbObject.m_pRecordset->adoEOF)
	{
		vname = m_DbObject.m_pRecordset->GetCollect("CodeName");
		vtemp = m_DbObject.m_pRecordset->GetCollect("CodeID");
		ldir = (long)m_DbObject.m_pRecordset->GetCollect("IsDir");
	//	ltype = (long)m_DbObject.m_pRecordset->GetCollect("IconFlag");
		str = (LPCTSTR)(_bstr_t)vname;
		lt = (long)vtemp;
		ht = m_wndTree.InsertItem(str);

		if(ldir)
		{
			m_wndTree.SetItemImage(ht, 0, 0);
		}
		else
		{
			m_wndTree.SetMyItemImage(ht, str);
		}
		m_wndTree.SetItemData(ht,lt);
		m_DbObject.m_pRecordset->MoveNext();
	}*/
}


void CFindDlg::OnDblclkResultlist() 
{
	ShowFile();
}


int CFindDlg::ShowFile()
{
	CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
	CCodeManagerView *EditView = (CCodeManagerView *)pFrame->GetActiveView();
//	int lvalue = m_resultList.GetItemData(m_resultList.GetCurSel());
//	HTREEITEM hs = pFrame->m_wndTree.GetSelectedItem();
	if(m_resultList.GetCurSel() == LB_ERR)
		return 0;
	CString strvalue = "select * from CodeTable where CodeID = ", strdata;
	strdata.Format("%ld", m_resultList.GetItemData(m_resultList.GetCurSel()));
	strvalue = strvalue + "" + strdata + "";

	pFrame->m_DbObject.GetValue(strvalue);
	_variant_t vname;
	vname = pFrame->m_DbObject.m_pRecordset->GetCollect("CodeName");
	long ldir = (long)pFrame->m_DbObject.m_pRecordset->GetCollect("IsDir");
//	MessageBox((LPCTSTR)(_bstr_t)vname);
	try
	{
		long nSize = pFrame->m_DbObject.m_pRecordset->GetFields()->GetItem("CodeData")->ActualSize;
		if(nSize > 0)
		{
			_variant_t	varBLOB;
			varBLOB = pFrame->m_DbObject.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);
					EditView = (CCodeManagerView *)pFrame->GetActiveView();
					EditView->LoadText(str);
					EditView->SelectLanguage(_CPP);

					delete [] pBuffer;
					pBuf=0;
						 
				}
			}
		}
		else
		{
			CString str;
			EditView = (CCodeManagerView *)pFrame->GetActiveView();
			EditView->LoadText(str);
			//	EditView->SelectLanguage(_CPP);
	
		}

		}
	catch (_com_error e)
	{
	}
	if(ldir)
	{
		m_resultList.ResetContent();
		strvalue.Empty();
		strvalue = "select * from CodeTable where ParentID = ";
		strvalue = strvalue + "'" + strdata + "'";

		pFrame->m_DbObject.GetValue(strvalue);

		long lvalue;
		while(!pFrame->m_DbObject.m_pRecordset->adoEOF)
		{
			vname = pFrame->m_DbObject.m_pRecordset->GetCollect("CodeName");
		//	MessageBox((LPCTSTR)(_bstr_t)vname);
			int index = m_resultList.AddString((LPCTSTR)(_bstr_t)vname);
			lvalue = (long)pFrame->m_DbObject.m_pRecordset->GetCollect("CodeID");
			m_resultList.SetItemData(index, lvalue);
			pFrame->m_DbObject.m_pRecordset->MoveNext();
		}
	}
	return 0;
}

void CFindDlg::OnShowbut() 
{
	// TODO: Add your control notification handler code here
	ShowFile();
}

⌨️ 快捷键说明

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