📄 mainfrm.cpp
字号:
#include "stdafx.h"
#include "plxc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDM_COMMADBAR, OnCommadbar)
ON_UPDATE_COMMAND_UI(IDM_COMMADBAR, OnUpdateCommadbar)
ON_COMMAND(IDM_WND_SOURCEINFO, OnWndSourceinfo)
ON_UPDATE_COMMAND_UI(IDM_WND_SOURCEINFO, OnUpdateWndSourceinfo)
ON_COMMAND(IDM_WND_DEBUG, OnWndDebug)
ON_UPDATE_COMMAND_UI(IDM_WND_DEBUG, OnUpdateWndDebug)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_DIALOGBARCLOSE,OnDockBarClose) /* 保留 */
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
CMainFrame::CMainFrame()
{
m_strFont.CreateFont(0,0,0,0,
FW_NORMAL,
FALSE,FALSE,FALSE,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_ROMAN,
"Fixedsys");
}
CMainFrame::~CMainFrame()
{
m_strFont.DeleteObject();
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar_main.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar_main.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
if (!m_wndToolBar_execute.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar_execute.LoadToolBar(IDR_TOOLBAR_EXECUTE))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
if (!m_wndToolBar3.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar3.LoadToolBar(IDR_TOOLBAR_MIDDLE))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
AddSearchCombo();
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1;
}
m_wndToolBar_main.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar_execute.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar3.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar_main);//,AFX_IDW_DOCKBAR_BOTTOM);
DockControlBar(&m_wndToolBar3,AFX_IDW_DOCKBAR_BOTTOM);
DockControlBarLeftOf(&m_wndToolBar_execute,&m_wndToolBar3);
AddDockBar();
/* 初始化各种条为可见 */
m_bCommandBar = TRUE;
m_bSourceInfo = TRUE;
m_bDebugInfo = TRUE;
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif
void CMainFrame::DockControlBarLeftOf(CToolBar *Bar, CToolBar *LeftOf)
{
CRect rect;
DWORD dw;
UINT n;
RecalcLayout(TRUE);
LeftOf->GetWindowRect(&rect);
rect.OffsetRect(1,0);
dw=LeftOf->GetBarStyle();
n = 0;
n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
DockControlBar(Bar,n,&rect);
}
void CMainFrame::AddDockBar()
{
if(!m_debugInfoBar .Create(this,&m_debugInfoDlg ,CString("Output") ,IDD_DEBUGINFO_DIALOG) ||
!m_sourceInfoBar.Create(this,&m_sourceInfoDlg,CString("Souece") ,IDD_SOURCE_DIALOG) ||
!m_debugOutInfoBar.Create(this,&m_debugOutInfoDlg,CString("Debug"),IDD_DEBUGOUTINFRODIALOG))
{
return;
}
m_debugInfoBar.SetBarStyle(m_debugInfoBar.GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
m_sourceInfoBar.SetBarStyle(m_debugInfoBar.GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
m_debugOutInfoBar.SetBarStyle(m_debugInfoBar.GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
m_sourceInfoBar.EnableDocking(CBRS_ALIGN_ANY);
m_debugInfoBar.EnableDocking(CBRS_ALIGN_ANY);
m_debugOutInfoBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_debugInfoBar,AFX_IDW_DOCKBAR_BOTTOM,NULL);
DockControlBar(&m_sourceInfoBar,AFX_IDW_DOCKBAR_LEFT,NULL);
DockControlBar(&m_debugOutInfoBar,AFX_IDW_DOCKBAR_BOTTOM,NULL);
m_debugInfoBar.SetAddStyleEx(CCoolDialogBar::BAR_NOMAX);
m_sourceInfoBar.SetAddStyleEx(CCoolDialogBar::BAR_NOMAX);
m_debugOutInfoBar.SetAddStyleEx(CCoolDialogBar::BAR_NOMAX);
ShowControlBar(&m_debugInfoBar , TRUE , FALSE);
ShowControlBar(&m_sourceInfoBar , TRUE , FALSE);
ShowControlBar(&m_debugOutInfoBar, FALSE, FALSE);
}
void CMainFrame::AddSearchCombo()
{
CRect rect;
m_wndToolBar_main.SetButtonInfo(15, ID_BTN_COMBOBOX, TBBS_SEPARATOR, 200) ;
m_wndToolBar_main.GetItemRect(15, &rect);
rect.top += 2;
rect.bottom += 100;
if (!m_cbSearchText.Create( WS_CHILD | CBS_DROPDOWN | WS_VISIBLE | WS_TABSTOP | CBS_AUTOHSCROLL ,
rect, &m_wndToolBar_main,
IDC_COMBO_SEARCHTEXT))
return;
m_wndToolBar3.SetButtonInfo(0, ID_SEARCHTEXT, TBBS_SEPARATOR, 200) ;
m_wndToolBar3.GetItemRect(0, &rect);
rect.top += 2;
if(!m_cbEditfileName.Create( WS_CHILD | CBS_DROPDOWN | WS_VISIBLE | WS_TABSTOP | CBS_AUTOHSCROLL ,
rect, &m_wndToolBar3,
IDC_COMBO_EDITFILENAME))
return;
m_cbSearchText.SetFont(&m_strFont);
m_cbEditfileName.SetFont(&m_strFont);
}
/* 消息转发函数 */
#include "plxcDoc.h"
void CMainFrame::MsgTransmitProc(LPACTION pAction)
{
CPlxcDoc *pDoc = (CPlxcDoc*)GetActiveView()->GetDocument();
if(pDoc == NULL)
return;
pDoc->MsgTransmitProc(pAction);
}
/* 隐藏“命令”工具条 */
void CMainFrame::OnCommadbar()
{
m_bCommandBar = !m_bCommandBar;
ShowControlBar(&m_wndToolBar3, m_bCommandBar, FALSE);
ShowControlBar(&m_wndToolBar_execute,m_bCommandBar, FALSE);
}
void CMainFrame::OnUpdateCommadbar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bCommandBar);
}
/* 隐藏源文件条 */
void CMainFrame::OnWndSourceinfo()
{
m_bSourceInfo = !m_bSourceInfo;
ShowControlBar(&m_sourceInfoBar, m_bSourceInfo, FALSE);
}
void CMainFrame::OnUpdateWndSourceinfo(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bSourceInfo);
// pCmdUI->Enable(GetCurrentDebugState());
}
/* 隐藏调试信息条 */
void CMainFrame::OnWndDebug()
{
m_bDebugInfo = !m_bDebugInfo;
ShowControlBar(&m_debugInfoBar, m_bDebugInfo, FALSE);
}
void CMainFrame::OnUpdateWndDebug(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bDebugInfo);
// pCmdUI->Enable(GetCurrentDebugState());
}
/* 是否开启调试信息输出条 */
void CMainFrame::ShowDebugOutInfo()
{
bool state = GetCurrentDebugState();
ShowControlBar(&m_debugOutInfoBar, state, FALSE);
}
/* 点击dock bar关闭的响应 */
void CMainFrame::OnDockBarClose(WPARAM wParam,LPARAM lParam)
{
if(wParam == IDD_DEBUGINFO_DIALOG)
{
this->PostMessage(WM_COMMAND,IDM_WND_DEBUG,0);
}else if(wParam == IDD_SOURCE_DIALOG)
{
this->PostMessage(WM_COMMAND,IDM_WND_SOURCEINFO,0);
}else
{
}
}
bool CMainFrame::GetCurrentDebugState()
{
CPlxcApp *pApp = (CPlxcApp*)AfxGetApp();
return pApp->GetDebugState();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -