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

📄 floatdlg.cpp

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

#include "stdafx.h"
#include "CodeManager.h"
#include "FloatDlg.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFloatDlg dialog


CFloatDlg::CFloatDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFloatDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFloatDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CFloatDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFloatDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFloatDlg, CDialog)
	//{{AFX_MSG_MAP(CFloatDlg)
	ON_WM_LBUTTONDOWN()
	ON_MESSAGE(WM_DROPFILES,OnDropFiles)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_CONTEXTMENU()
	ON_COMMAND(ID_SHOW, OnShow)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFloatDlg message handlers

void CFloatDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	PostMessage (WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x , point. y ));
	CDialog::OnLButtonDown(nFlags, point);
}

BOOL CFloatDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
	GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
	HINSTANCE hInst = LoadLibrary("User32.DLL"); 
	if(hInst) 
	{ 
		typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD); 
		MYFUNC fun = NULL;
		//取得SetLayeredWindowAttributes函数指针 
		fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
		if(fun)fun(this->GetSafeHwnd(),0,180,2); 
		FreeLibrary(hInst); 
	}
//	SetLayeredWindowAttributes(this->GetSafeHwnd(),0,128,2);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFloatDlg::OnDropFiles(HDROP hDropInfo)
{
	CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
	::SetForegroundWindow(pFrame->m_hWnd);
	if(pFrame->IsIconic())
		pFrame->ShowWindow(SW_SHOWNORMAL);
	int FileCount = DragQueryFile(hDropInfo, -1, NULL, 0);//获得拖动文件数目
	for(int i = 0; i < FileCount; i++)
	{
		int NameSize = DragQueryFile(hDropInfo, i, NULL, 0);//获得文件名大小
		char *pFileName = new char[NameSize + 1], char *ptemp;
		if(pFileName == NULL)
		{
			MessageBox("临时内存分配错误,请重试!");
			return;
		}
		DragQueryFile(hDropInfo, i, pFileName, NameSize + 1);//将文件名拷贝到FileName中  
		ptemp = pFileName;

		CFileFind ff;
		BOOL res = ff.FindFile(pFileName);

		if(res)
		{
			ff.FindNextFile();
			if(ff.IsDirectory() && !ff.IsDots())
			{//导入的是目录
				HTREEITEM hItem, hpItem, hti;

				CString FilePath, FileName, dbstr[6];

				int i,j;
				FilePath.Format("%s", pFileName);
				FileName = FilePath;
				for(i = FilePath.GetLength() - 1; i >= 0; i--)
					if(FilePath.GetAt(i) == '\\')
						break;
				if(i >= 0)
				{
					i++;
					for(j = 0; i < FilePath.GetLength(); j++, i++)
						FileName.SetAt(j, FilePath.GetAt(i));
					FileName.SetAt(j, '\0');
				}


				hItem = pFrame->m_wndTree.GetSelectedItem();
				if(hItem == NULL)
					hItem = pFrame->m_wndTree.GetRootItem();
				hpItem = pFrame->m_wndTree.GetParentItem(hItem);
				if(pFrame->m_SelectFlag == 1)
				{
					if(pFrame->SelectDlg.DoModal() == IDOK)
					{
						if(pFrame->m_NewFlag)                         //新建同级节点
						{
							hti = pFrame->m_wndTree.InsertItem(FileName, hpItem);
							pFrame->m_wndTree.SetItemImage(hti, 0, 0);

							dbstr[0] = FileName;
							dbstr[1].Empty();
							
						//	dbstr[2].Format("%s", "2004-10-05");

							COleDateTime oleDt = COleDateTime::GetCurrentTime();
							dbstr[2]=oleDt.Format("%y年%m月%d日");
							if(hti != NULL)
							{
								if(hpItem != NULL)
									dbstr[3].Format("%ld", pFrame->m_wndTree.GetItemData(hpItem));
								else
									dbstr[3].Empty();
							}
							dbstr[4].Format("%s", "1");//0为文件
						}
						else                                  //新建子节点
						{
						//	如父节点原来无子节点,则更改父节点状态并修改数据库
							if((hItem != NULL) && (!pFrame->m_wndTree.ItemHasChildren(hItem)))
							{
								pFrame->m_wndTree.SetItemImage(hItem, 0, 0);
								CString strvalue = "select * from CodeTable where CodeID = ", strdata;
								long lvalue = pFrame->m_wndTree.GetItemData(hItem);
								strdata.Format("%ld", lvalue);
								strvalue = strvalue + "" + strdata +"";
								pFrame->m_DbObject.GetValue(strvalue);
								pFrame->m_DbObject.SetData("IsDir", "1");
								pFrame->m_DbObject.Update();
							}


							hti = pFrame->m_wndTree.InsertItem(FileName, hItem);
							pFrame->m_wndTree.SetItemImage(hti, 0, 0);
						//	m_wndTree.SetItemData(hti, m_wndTree.GetItemData());
							dbstr[0] = FileName;
							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", pFrame->m_wndTree.GetItemData(hItem));
							dbstr[4].Format("%s", "1");//0为文件
						}

						pFrame->m_DbObject.AddRecord(dbstr);

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

						pFrame->BrowseDir(FilePath, pFrame->m_wndTree, hti);
						if(!pFrame->m_NewFlag)
							pFrame->m_wndTree.Expand(hItem, TVE_EXPAND);
						CString ts = "成功导入" + FilePath + "下所有文件";
						MessageBox(ts, "源码利器");
					}
				}
				else
				{
					if(pFrame->m_NewFlag)                         //新建同级节点
					{
						hti = pFrame->m_wndTree.InsertItem(FileName, hpItem);
						pFrame->m_wndTree.SetItemImage(hti, 0, 0);

						dbstr[0] = FileName;
						dbstr[1].Empty();
//						dbstr[2].Format("%s", "2004-10-05");
						COleDateTime oleDt = COleDateTime::GetCurrentTime();
						dbstr[2]=oleDt.Format("%y年%m月%d日");
						if(hti != NULL)
						{
							if(hpItem != NULL)
								dbstr[3].Format("%ld", pFrame->m_wndTree.GetItemData(hpItem));
							else
								dbstr[3].Empty();
						}
						dbstr[4].Format("%s", "1");//0为文件
					}
					else                                  //新建子节点
					{
						//如父节点原来无子节点,则更改父节点状态并修改数据库
						if((hItem != NULL) && (!pFrame->m_wndTree.ItemHasChildren(hItem)))
						{
							pFrame->m_wndTree.SetItemImage(hItem, 0, 0);
							CString strvalue = "select * from CodeTable where CodeID = ", strdata;
							long lvalue = pFrame->m_wndTree.GetItemData(hItem);
							strdata.Format("%ld", lvalue);
							strvalue = strvalue + "" + strdata +"";

							pFrame->m_DbObject.GetValue(strvalue);
							pFrame->m_DbObject.SetData("IsDir", "1");
							pFrame->m_DbObject.Update();
						}

						hti = pFrame->m_wndTree.InsertItem(FileName, hItem);
						pFrame->m_wndTree.SetItemImage(hti, 0, 0);
					//	m_wndTree.SetItemData(hti, m_wndTree.GetItemData());
						dbstr[0] = FileName;
						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", pFrame->m_wndTree.GetItemData(hItem));
						dbstr[4].Format("%s", "1");//0为文件
					}

					pFrame->m_DbObject.AddRecord(dbstr);

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

					pFrame->BrowseDir(FilePath, pFrame->m_wndTree, hti);
					if(!pFrame->m_NewFlag)
						pFrame->m_wndTree.Expand(hItem, TVE_EXPAND);
					CString ts = "成功导入" + FilePath + "下所有文件";
					MessageBox(ts, "源码利器");
					
				}
			}
			else
			{//导入单个文件
				HTREEITEM hItem, hpItem, htemp1, hroot;

				CString strPathName,dbstr[6],stemp;

				
				int k;
				 
				strPathName.Format("%s", pFileName);

				for(k = strPathName.GetLength() - 1; k >= 0; k--)
					if(strPathName.GetAt(k) == '\\')
						break;
				if(k >= 0)
					ptemp += k + 1;

				hItem = pFrame->m_wndTree.GetSelectedItem();
				hpItem = pFrame->m_wndTree.GetParentItem(hItem);
				hroot = pFrame->m_wndTree.GetRootItem();

			//	if(hItem == NULL)
			//		hItem = hpItem = hroot;

				if(pFrame->m_SelectFlag == 1)
				{
					if(pFrame->SelectDlg.DoModal() == IDOK)
					{
//						str1.Format("%s", pFileName);

						if(pFrame->m_NewFlag)                         //新建同级节点
						{
							if(hpItem != NULL)
								dbstr[3].Format("%ld", pFrame->m_wndTree.GetItemData(hpItem));
							htemp1 = pFrame->m_wndTree.InsertItem(_T(ptemp), hpItem);
							pFrame->m_wndTree.SetMyItemImage(htemp1, ptemp);
						}
						else                                  //新建子节点
						{
							/*如父节点原来无子节点,则更改父节点状态并修改数据库*/
							if((hItem != NULL) && (!pFrame->m_wndTree.ItemHasChildren(hItem)))
							{
								pFrame->m_wndTree.SetItemImage(hItem, 0, 0);
								CString strvalue = "select * from CodeTable where CodeID = ", strdata;
								long lvalue = pFrame->m_wndTree.GetItemData(hItem);
								strdata.Format("%ld", lvalue);
								strvalue = strvalue + "" + strdata +"";

								pFrame->m_DbObject.GetValue(strvalue);
								pFrame->m_DbObject.SetData("IsDir", "1");
								pFrame->m_DbObject.Update();
							}

							if(hItem != NULL)
								dbstr[3].Format("%ld", pFrame->m_wndTree.GetItemData(hItem));
							htemp1 = pFrame->m_wndTree.InsertItem(_T(ptemp), hItem);
							pFrame->m_wndTree.SetMyItemImage(htemp1, ptemp);
						}
						dbstr[0].Format("%s", ptemp);

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

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

						_variant_t vtemp;
						vtemp = pFrame->m_DbObject.m_pRecordset->GetCollect("CodeID");
						pFrame->m_wndTree.SetItemData(htemp1, long(vtemp));
					}
					else
						;
				}
				else
				{
	//				str1.Format("%s", pFileName);

					if(pFrame->m_NewFlag)                         //新建同级节点
					{
						if(hpItem != NULL)
							dbstr[3].Format("%ld", pFrame->m_wndTree.GetItemData(hpItem));
						htemp1 = pFrame->m_wndTree.InsertItem(_T(ptemp), hpItem);
						pFrame->m_wndTree.SetMyItemImage(htemp1, ptemp);
					}
					else                                  //新建子节点
					{
						/*如父节点原来无子节点,则更改父节点状态并修改数据库*/
						if((hItem != NULL) && (!pFrame->m_wndTree.ItemHasChildren(hItem)))
						{
							pFrame->m_wndTree.SetItemImage(hItem, 0, 0);
							CString strvalue = "select * from CodeTable where CodeID = ", strdata;
							long lvalue = pFrame->m_wndTree.GetItemData(hItem);
							strdata.Format("%ld", lvalue);
							strvalue = strvalue + "" + strdata +"";

							pFrame->m_DbObject.GetValue(strvalue);
							pFrame->m_DbObject.SetData("IsDir", "1");
							pFrame->m_DbObject.Update();
						}
						if(hItem != NULL)
							dbstr[3].Format("%ld", pFrame->m_wndTree.GetItemData(hItem));
						htemp1 = pFrame->m_wndTree.InsertItem(_T(ptemp), hItem);
						pFrame->m_wndTree.SetMyItemImage(htemp1, ptemp);

					}
					dbstr[0].Format("%s", ptemp);

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

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

					_variant_t vtemp;
					vtemp = pFrame->m_DbObject.m_pRecordset->GetCollect("CodeID");
					pFrame->m_wndTree.SetItemData(htemp1, long(vtemp));
				}
				if(hItem != NULL)
					pFrame->m_wndTree.Expand(hItem, TVE_EXPAND);
			}
		}

		delete pFileName;
	}
	CDialog::OnDropFiles(hDropInfo);
}

void CFloatDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CFrameWnd *pFrame = (CFrameWnd *)AfxGetApp()->GetMainWnd(); 
	::SetForegroundWindow(pFrame->m_hWnd);
	if(pFrame->IsIconic())
		pFrame->ShowWindow(SW_SHOWNORMAL);
//	::ShowWindow(pFrame->m_hWnd,SW_SHOWNORMAL);
	CDialog::OnLButtonDblClk(nFlags, point);
}

void CFloatDlg::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
	CMenu menuPopup;
	menuPopup.LoadMenu(IDR_FLOATMENU);
//	menuPopup.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);

	CMenu* pPopup = menuPopup.GetSubMenu(0);

	pPopup->TrackPopupMenu(TPM_RIGHTALIGN, point.x, point.y, this);
}


void CFloatDlg::OnShow() 
{
	// TODO: Add your command handler code here
	CFrameWnd *pFrame = (CFrameWnd *)AfxGetApp()->GetMainWnd(); 
	::SetForegroundWindow(pFrame->m_hWnd);
	if(pFrame->IsIconic())
		pFrame->ShowWindow(SW_SHOWNORMAL);
}


⌨️ 快捷键说明

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