📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "ParseCProj.h"
#include "MainFrm.h"
//视图区类
#include "ClassViewForm.h"
#include "FileViewForm.h"
#include "SystemInfoForm.h"
#include "ToolsConDlg.h"
//文件操作类
#include "FileEx.h"
//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_COMMAND(ID_VCFILE_OPEN, OnVcfileOpen)
ON_COMMAND(ID_VCFILE_CLOSE, OnVcfileClose)
ON_COMMAND(ID_VIEW_SYSTREE, OnViewSystree)
ON_UPDATE_COMMAND_UI(ID_VIEW_SYSTREE, OnUpdateViewSystree)
ON_COMMAND(ID_VIEW_SYSINFO, OnViewSysinfo)
ON_WM_SYSCOMMAND()
ON_MESSAGE(DEFNM_TRAYICON, OnTrayNotification)
ON_MESSAGE(WM_UPDATE_STATUSBAR_INFO, OnUpdateStatusbarInfo)
ON_COMMAND(ID_TOOLS_CUSTOM, OnToolsCustom)
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_TOOLS_MENU_BASEMENUID, ID_TOOLS_MENU_ENDMENUID, OnExecToolApp)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_FILEANDCLASS_INFO,
ID_ROWANDCOL_INFO,
ID_FILESIZE_INFO,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
//必须的消息影射函数
LRESULT CMainFrame::OnTrayNotification(WPARAM wparam, LPARAM lparam)
{
if ( wparam == GLOBAL_TRAYICON_ID )
{
if ( lparam == WM_RBUTTONUP )
{
m_sysTrayIcon.PopupMenu();
}
else
{
if ( lparam == WM_LBUTTONDBLCLK )
{
m_sysTrayIcon.SetActive(FALSE);
}
}
}
return 1;
}
void CMainFrame::OnUpdateStatusbarInfo(WPARAM wparam, LPARAM lparam)
{
CString strInfo = "";
strInfo.Format("[总行]:%d [当前行]::%d [当前列]::%d", m_wndRichEdit.GetLineCount(),
m_wndRichEdit.GetCursorRow() + 1, m_wndRichEdit.GetCursorCol() + 1);
this->m_wndStatusBar.SetPaneText(1, (LPCTSTR)strInfo);
}
/*******************************************/
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
Create(NULL, "VC/Delphi工程解析器", WS_OVERLAPPEDWINDOW,
rectDefault, NULL, MAKEINTRESOURCE(IDR_MAINFRAME));
SetIcon(::AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
m_bIsVCProjFlag = TRUE; //默认为VC工程
}
CMainFrame::~CMainFrame()
{
}
//得到软件系统路径
CString CMainFrame::GetAppPath()
{
char strPath[MAX_PATH];
memset(strPath, 0x0, sizeof(strPath));
::GetModuleFileName(::AfxGetInstanceHandle(), strPath, MAX_PATH);
CString strRet = strPath;
int nIndex = strRet.ReverseFind('\\');
strRet = strRet.Left(nIndex + 1);
return strRet;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
CRect rcMain;
this->GetClientRect(rcMain);
m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_NORMAL, 3*rcMain.Width() / 6);
m_wndStatusBar.SetPaneInfo(1, m_wndStatusBar.GetItemID(1), SBPS_NORMAL, 2*rcMain.Width() / 5);
m_wndStatusBar.SetPaneInfo(2, m_wndStatusBar.GetItemID(2), SBPS_STRETCH, NULL);
//根据配置文件来更新系统主菜单
if(!UpdateToolsMenu())
{
AfxMessageBox("更新工具配置菜单时出错,请检查!");
return -1;
}
if (!m_wndLeftBar.Create(_T("系统视图"), this, GLOBAL_SYSLEFTVIEW_ID))
return -1;
m_wndLeftBar.SetBarStyle(m_wndLeftBar.GetBarStyle() | CBRS_TOOLTIPS |
CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
//
if (!m_wndTabCtrl.Create(TCS_DOWN | WS_CHILD | WS_VISIBLE,
CRect(0,0,100,100), &m_wndLeftBar, GLOBAL_SYSTABCTRL_ID))
return -1;
//加入类视图页ClassViewForm
m_wndTabCtrl.AddPage(RUNTIME_CLASS(CClassViewForm), IDD_CLASSVIEW, _T("类视图"), IDI_CLASSTAB_ICON);
//加入文件视图页FileViewForm
m_wndTabCtrl.AddPage(RUNTIME_CLASS(CFileViewForm), IDD_FILEVIEW, _T("文件视图"), IDI_FILETAB_ICON);
//创建两者的图标[注意图标ID的连续性]
ilTFImageList.Create(16, 16, TRUE, 6, 1);
HICON hIcon;
for(int nIndex = IDI_FILETREE_VCPROJ; nIndex <= IDI_FILETREE_UINT; ++nIndex)
{
hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(nIndex), IMAGE_ICON, 16, 16, 0);
ASSERT(hIcon);
ilTFImageList.Add(hIcon);
}
//增加类视图树型目录图标
hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CLASS_ICON), IMAGE_ICON, 16, 16, 0);
ASSERT(hIcon);
ilTFImageList.Add(hIcon);
hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_FUNS_PUBLIC_ICON), IMAGE_ICON, 16, 16, 0);
ASSERT(hIcon);
ilTFImageList.Add(hIcon);
hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_FUNS_PRIVATE_ICON), IMAGE_ICON, 16, 16, 0);
ASSERT(hIcon);
ilTFImageList.Add(hIcon);
//*************************************
m_wndTabCtrl.UpdateWindow();
// TODO: Delete these three lines if you don't want the toolbar to be dockable
//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndLeftBar.EnableDocking(CBRS_ALIGN_LEFT);
EnableDocking(CBRS_ALIGN_ANY);
//DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndLeftBar, AFX_IDW_DOCKBAR_LEFT);
/**********************系统窗口初始化代码**************************/
//创建客户区图标列表
ilCTImageList.Create(16, 16, TRUE, 4, 1);
ilCTImageList.Add(::AfxGetApp()->LoadIcon(IDI_FILETREE_FILE));
RecalcLayout(1);
if( !m_wndContentTab.Create(WS_CHILD | WS_VISIBLE | TCS_SINGLELINE | TCS_HOTTRACK |
TCS_TABS | TCS_FORCEICONLEFT | WS_CLIPSIBLINGS,
CRect(0, 0, 0, 0), this, GLOBAL_SYSCLIENTTABCTRL_ID) )
return -1;
m_wndContentTab.SetImageList(&ilCTImageList);
if( !m_wndRichEdit.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
CRect(0, 0, 0, 0), &m_wndContentTab, GLOBAL_SYSCLIENTTABCTRL_ID + 1) )
return -1;
//m_wndRichEdit.ShowScrollBar(SB_VERT, TRUE);
//m_wndRichEdit.ShowScrollBar(SB_HORZ, TRUE);
m_wndContentTab.AddPage(&m_wndRichEdit, _T("文件预览"), 0);
m_wndContentTab.SetActivePage(0);
/*****************************************************************/
//任务栏管理(系统全局处理)
HICON hTrayIcon = ::AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_sysTrayIcon.Create(this->m_hWnd, GLOBAL_TRAYICON_ID, hTrayIcon, _T("VC/Delphi工程解析器\n双击打开主界面窗口!"));
hTrayMenu.LoadMenu(IDR_TRAY_MENU);
m_sysTrayIcon.SetMenu(hTrayMenu.m_hMenu);
//注册热键
if( ::RegisterHotKey(this->m_hWnd, GLOBAL_SYSHOTKEY_ID, MOD_CONTROL | MOD_ALT, 90) == 0)
MessageBox("热键已被其他应用程序所注册,\n注册热键<CTRL + ALT + Z>失败!", "错误...", MB_OK | MB_ICONINFORMATION);
::ShowWindow(this->m_hWnd, SW_MAXIMIZE);
//
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.style &= ~FWS_ADDTOTITLE ;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/****************************用户自定义函数********************/
//获取|设置某个子菜单的状态
UINT CMainFrame::GetMainMenuState(int nMenuID, UINT uSubID, UINT uFlag)
{
CMenu* pMainMenu = this->GetMenu();
ASSERT(pMainMenu->GetSafeHmenu());
CMenu* pSubFileMenu = pMainMenu->GetSubMenu(nMenuID);
ASSERT(pSubFileMenu->GetSafeHmenu());
UINT uState = pSubFileMenu->GetMenuState(uSubID, uFlag);
return uState;
}
void CMainFrame::SetMainMenuState(int nMenuID, UINT uSubID, UINT uFlag, BOOL bEnable)
{
CMenu* pMainMenu = this->GetMenu();
ASSERT(pMainMenu->GetSafeHmenu());
CMenu* pSubFileMenu = pMainMenu->GetSubMenu(nMenuID);
ASSERT(pSubFileMenu->GetSafeHmenu());
pSubFileMenu->EnableMenuItem(uSubID, uFlag | (bEnable ? MF_ENABLED : MF_DISABLED));
}
//得到TOOLBAR和STATUSBAR的尺寸
CSize CMainFrame::GetToolBarSize()
{
CRect rect;
this->m_wndToolBar.GetWindowRect(rect);
CSize size(rect.Width(), rect.Height());
return size;
}
CSize CMainFrame::GetStatusBarSize()
{
CRect rect;
this->m_wndStatusBar.GetWindowRect(rect);
CSize size(rect.Width(), rect.Height());
return size;
}
void CMainFrame::UpdateSysTrees()
{
/**********************更新文件树型目录********************///!!![顺序不能颠倒]
//!!!其中修改了原作者的类[新增了一个返回活页内的窗口句柄的函数::GetPageWnd()]
CCoolTabCtrl::CPageItem* lpFilePageItem = (CCoolTabCtrl::CPageItem*)m_wndTabCtrl.GetPageItem(1);
CFileViewForm* lpFileViewForm = (CFileViewForm*)lpFilePageItem->GetPageWnd();
ASSERT(lpFileViewForm->m_wndFileTree.GetSafeHwnd());
lpFileViewForm->m_wndFileTree.SetImageList(&ilTFImageList, TVSIL_NORMAL);
//更新文件树
UpdateFileTreeView(&lpFileViewForm->m_wndFileTree);
/***********************更新类树型目录*********************/
CCoolTabCtrl::CPageItem* lpClassPageItem = (CCoolTabCtrl::CPageItem*)m_wndTabCtrl.GetPageItem(0);
CClassViewForm* lpClassViewForm = (CClassViewForm*)lpClassPageItem->GetPageWnd();
ASSERT(lpClassViewForm->m_wndClassTree.GetSafeHwnd());
lpClassViewForm->m_wndClassTree.SetImageList(&ilTFImageList, TVSIL_NORMAL);
//根据文件树来更新类目录树
UpdateClassTreeView(&lpClassViewForm->m_wndClassTree, &lpFileViewForm->m_wndFileTree);
this->RecalcLayout();
}
//更新VC文件树
void CMainFrame::UpdateVCFileTreeView(CTreeCtrl* lpTree)
{
POSITION pos = m_lstProjFile.GetHeadPosition();
while(pos != NULL)
{
CString strProjName = m_lstProjFile.GetNext(pos);
//更新VC工程文件树
CParseVCFile file; CFileException e;
if(!file.Open((LPCTSTR)strProjName, CFile::modeRead, &e))
{
char err[256];
e.GetErrorMessage((char*)err, 256);
AfxMessageBox(err);
return ;
}
//初始化文件列表
file.InitFileList();
//
HTREEITEM hProjRoot = lpTree->InsertItem((LPCTSTR)strProjName, 0, 0);
//头文件节点
HTREEITEM hHeadRoot = lpTree->InsertItem("Head Files", 3, 3, hProjRoot);
ASSERT(hHeadRoot != NULL);
CStringList* sltHeadList = file.GetHeadList();
if(sltHeadList == NULL) return;
int nCurIndex = 0, nTotalHeadFileCount = sltHeadList->GetCount(); //得到进度信息
POSITION headListPos = sltHeadList->GetHeadPosition();
CFileFind* ffFinder = new CFileFind;
while(headListPos != NULL)
{
CStringList* sltCppList = file.GetCppList();
if(sltCppList == NULL) return;
CString strHeadFilename = sltCppList->GetNext(headListPos);
strHeadFilename = strHeadFilename.Left(strHeadFilename.GetLength() - 1);
//去掉基路径
int nPointPos = strHeadFilename.ReverseFind('\\');
strHeadFilename = strHeadFilename.Right(strHeadFilename.GetLength() - nPointPos - 1);
//
if(ffFinder->FindFile((LPCTSTR)strHeadFilename) != 0)
{
lpTree->InsertItem((LPCTSTR)strHeadFilename, 4, 4, hHeadRoot);
++nCurIndex;
CString strTipInfo = "";
strTipInfo.Format("[总共%d个头文件] [当前正在解析第%d个头文件::%s]----请稍侯...",
nTotalHeadFileCount, nCurIndex, strHeadFilename);
m_wndStatusBar.SetPaneText(0, strTipInfo);
}
}
//源文件节点
HTREEITEM hCppRoot = lpTree->InsertItem("Source Files", 2, 2, hProjRoot);
ASSERT(hCppRoot != NULL);
CStringList* sltCppList = file.GetCppList();
if(sltCppList == NULL) return;
nCurIndex = 0; int nTotalCppFileCount = sltCppList->GetCount();
POSITION cppListPos = sltCppList->GetHeadPosition();
while(cppListPos != NULL)
{
CString strCppFilename = file.GetCppList()->GetNext(cppListPos);
strCppFilename = strCppFilename.Left(strCppFilename.GetLength() - 1);
//去掉基路径
int nPointPos = strCppFilename.ReverseFind('\\');
strCppFilename = strCppFilename.Right(strCppFilename.GetLength() - nPointPos - 1);
//
if(ffFinder->FindFile((LPCTSTR)strCppFilename) != 0)
{
lpTree->InsertItem((LPCTSTR)strCppFilename, 4, 4, hCppRoot);
++nCurIndex;
CString strTipInfo = "";
strTipInfo.Format("[总共%d个源文件] [当前正在解析第%d个源文件::%s]----请稍侯...",
nTotalCppFileCount, nCurIndex, strCppFilename);
m_wndStatusBar.SetPaneText(0, strTipInfo);
}
}
CString strTipInfo = "";
strTipInfo.Format("解析完毕----[共分析%d个头文件 %d个源文件]", nTotalHeadFileCount, nTotalCppFileCount);
m_wndStatusBar.SetPaneText(0, strTipInfo);
delete ffFinder;
//关闭文件
file.Close();
//展开所有父节点
lpTree->Expand(hProjRoot, TVE_EXPAND);
lpTree->Expand(hHeadRoot, TVE_EXPAND);
lpTree->Expand(hCppRoot, TVE_EXPAND);
}
}
//更新文件树
void CMainFrame::UpdateDelphiFileTreeView(CTreeCtrl* lpTree)
{
POSITION pos = m_lstProjFile.GetHeadPosition();
while(pos != NULL)
{
CString strProjName = m_lstProjFile.GetNext(pos);
//更新Delphi工程文件树
CParseDelphiFile file; CFileException e;
if(!file.Open((LPCTSTR)strProjName, CFile::modeRead, &e))
{
char err[256];
e.GetErrorMessage((char*)err, 256);
AfxMessageBox(err);
return ;
}
//
HTREEITEM hProjRoot = lpTree->InsertItem((LPCTSTR)strProjName, 1, 1);
//头文件节点
HTREEITEM hHeadRoot = lpTree->InsertItem("Uses Files", 5, 5, hProjRoot);
ASSERT(hHeadRoot != NULL);
CStringList* m_lstFilelist = file.GetProjFiles();
if(m_lstFilelist == NULL) return;
int nCurIndex = 0, nTotalFileCount = m_lstFilelist->GetCount(); //得到进度信息
POSITION headListPos = m_lstFilelist->GetHeadPosition();
CFileFind* ffFinder = new CFileFind;
while(headListPos != NULL)
{
CString strHeadFilename = m_lstFilelist->GetNext(headListPos);
strHeadFilename.Left(strHeadFilename.ReverseFind('.'));
//
if(ffFinder->FindFile((LPCTSTR)strHeadFilename) != 0)
{
lpTree->InsertItem((LPCTSTR)strHeadFilename, 4, 4, hHeadRoot);
++nCurIndex;
CString strTipInfo = "";
strTipInfo.Format("[总共%d个单元文件] [当前正在解析第%d个单元文件::%s]----请稍侯...",
nTotalFileCount, nCurIndex, strHeadFilename);
m_wndStatusBar.SetPaneText(0, strTipInfo);
}
}
CString strTipInfo = "";
strTipInfo.Format("解析完毕----[共分析%d个单元文件]", nTotalFileCount);
m_wndStatusBar.SetPaneText(0, strTipInfo);
delete ffFinder;
//关闭文件
file.Close();
//展开所有父节点
lpTree->Expand(hProjRoot, TVE_EXPAND);
lpTree->Expand(hHeadRoot, TVE_EXPAND);
}
}
void CMainFrame::UpdateFileTreeView(CTreeCtrl* lpTree)
{
ASSERT(lpTree->GetSafeHwnd());
//对工程文件列表做合法性检查
POSITION pos = m_lstProjFile.GetHeadPosition();
BOOL bIsVCProj = FALSE, bIsDelphiProj = FALSE;
while(pos != NULL)
{
CString strProjName = m_lstProjFile.GetNext(pos);
CString strFileExt = strProjName.Right(strProjName.GetLength() - strProjName.Find('.') - 1);
strFileExt.MakeLower();
if(strFileExt == "dsp"){ bIsVCProj = TRUE; m_bIsVCProjFlag = TRUE; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -