📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "TestForm.h"
#include "TestFormView.h"
#include "PeDialogBase.h"
#include "MotorDlgBase.h"
//#include "DrawDlgBase.h"
#include "MainFrm.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_COMMAND(ID_SAVE, OnSave)
ON_COMMAND(ID_OPEN, OnOpen)
ON_MESSAGE(WM_TREEBAR_HIT,OnTreebarhit) //点击树型选项所发消息
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
//AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//AfxGetApp()->LoadIcon(IDI_ICON1);
}
CMainFrame::~CMainFrame()
{
}
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
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
////--------------------------------------------------------////
if(!m_CtrlBar.Create("功能管理框",this, CSize(200,200),TRUE,123))
{
TRACE("Failed to create mybar\n");
return -1;
// fail to create
}
m_CtrlBar.SetBarStyle(m_CtrlBar.GetBarStyle()|
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_CtrlBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_CtrlBar,AFX_IDW_DOCKBAR_LEFT);
////--------------------------------------------------------////
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
//////////////////////////////////////////////
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
//获得客户区窗口大小
GetClientRect(&m_rectClient);
int high = m_rectClient.Height();
int wide = m_rectClient.Width();
m_wndSplitter1.CreateStatic(this, //父窗口指针
2,1, //行数,列数
WS_CHILD|WS_VISIBLE); //窗口风格
m_wndSplitter2.CreateStatic(&m_wndSplitter1, //父窗口是第一次切分的窗口
1,2, //将这个窗口分成一行两列
WS_CHILD|WS_VISIBLE, //窗口风格
m_wndSplitter1.IdFromRowCol(0,0)); //获得新切分窗口是上次分割的第一行第一列窗口
//m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(MotorDlgBase),CSize(410,50),pContext);
m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(MotorDlgBase),CSize(410,50),pContext);
m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(PeDialogBase),CSize(480,50),pContext);
m_wndSplitter1.CreateView(1,0,RUNTIME_CLASS(CTestFormView),CSize(890,60),pContext);
//high=(int)high*1.5;
m_wndSplitter1.SetRowInfo(0,high*2,0); //设定第一次分割的窗口第一行窗口的大小
m_wndSplitter2.SetColumnInfo(0,wide*2,0);
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}
void CMainFrame::OnTreebarhit(WPARAM wParam, LPARAM lParam)
{
//CCreateContext* pContext;
//MessageBox("123");
//获得应用类句柄
CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
//获得客户区窗口大小
GetClientRect(&m_rectClient);
int high = m_rectClient.Height();
int wide = m_rectClient.Width();
//变换窗口标志
BOOL changflag = FALSE;
//调试标志
BOOL debugflag = FALSE;
int itemnumber = (int)wParam;
pApp->m_nHitNumber = itemnumber;//树型控件点击编号
switch(itemnumber)
{
case 0x000: //启动界面
pApp->pMotorDlgBase->MotorSwitchView(0);
changflag = TRUE;
//MessageBox("0x000");
pApp->pMotorDlgBase->Invalidate();
break;
//////////////////////////////////
case 0x010: //试验项目
pApp->pMotorDlgBase->MotorSwitchView(9);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
//MessageBox("12");
break;
case 0x020: //试验帮助系统
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
//MessageBox("12");
break;
case 0x030: //设备调试
pApp->pMotorDlgBase->MotorSwitchView(11);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x040: //系统设置
pApp->pMotorDlgBase->MotorSwitchView(12);
changflag = TRUE;
break;
//////////////////////////////////
case 0x011: //效率试验
pApp->pMotorDlgBase->MotorSwitchView(1);
pApp->pPeDialogBase->PESwitchView(0);
pApp->pCTestFormView->DrawSwitchView(1);
break;
case 0x012: //超载试验
pApp->pMotorDlgBase->MotorSwitchView(2);
pApp->pPeDialogBase->PESwitchView(0);
pApp->pCTestFormView->DrawSwitchView(2);
break;
case 0x013: //传动精度试验
pApp->pMotorDlgBase->MotorSwitchView(3);
pApp->pPeDialogBase->PESwitchView(1);
pApp->pCTestFormView->DrawSwitchView(3);
break;
case 0x014: //过度过程试验
pApp->pMotorDlgBase->MotorSwitchView(4);
pApp->pPeDialogBase->PESwitchView(0);
pApp->pCTestFormView->DrawSwitchView(4);
//MessageBox("过度过程试验");
break;
case 0x015: //启动力矩试验
pApp->pMotorDlgBase->MotorSwitchView(5);
pApp->pPeDialogBase->PESwitchView(1);
pApp->pCTestFormView->DrawSwitchView(5);
break;
case 0x016: //空程回差试验
pApp->pMotorDlgBase->MotorSwitchView(6);
pApp->pPeDialogBase->PESwitchView(1);
pApp->pCTestFormView->DrawSwitchView(6);
break;
case 0x017: //刚度及回差试验
//SetActivePage(IDD_ENCODERDIALOG);
pApp->pMotorDlgBase->MotorSwitchView(7);
pApp->pPeDialogBase->PESwitchView(1);
pApp->pCTestFormView->DrawSwitchView(7);
break;
//////////////////////////////////
case 0x021: //效率试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x022: //超载试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x023: //传动精度试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x024: //过度过程试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x025: //启动力矩试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x026: //空程回差试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
case 0x027: //刚度及回差试验帮助
pApp->pMotorDlgBase->MotorSwitchView(10);
pApp->pMotorDlgBase->Invalidate();
changflag = TRUE;
break;
/////////////////////////////////////
case 0x031: //伺服电机调试
pApp->pMotorDlgBase->MotorSwitchView(8);
changflag = TRUE;
//MessageBox("1");
break;
case 0x032: //效率仪调试
pApp->pPeDialogBase->PESwitchView(0);
changflag = TRUE;
debugflag = TRUE;
//MessageBox("2");
break;
case 0x033: //编码器调试
pApp->pPeDialogBase->PESwitchView(1);
changflag = TRUE;
debugflag = TRUE;
//MessageBox("3");
break;
/////////////////////////////////////
case 0x041: //试验设置
pApp->pMotorDlgBase->MotorSwitchView(12);
changflag = TRUE;
break;
default:
pApp->pMotorDlgBase->MotorSwitchView(0);
changflag = TRUE;
//MessageBox("0x000");
pApp->pMotorDlgBase->Invalidate();
break;
}
if (changflag ==TRUE)//窗口需要变化
{
if (debugflag )//处于调试状态
{
m_wndSplitter1.SetRowInfo(0,high,0);
m_wndSplitter2.SetColumnInfo(0,0,0);
}
else//处于调试以外的状态
{
m_wndSplitter1.SetRowInfo(0,high,0);
m_wndSplitter2.SetColumnInfo(0,wide,0);
}
}
else//窗口无需变化
{
//high = (int) (high*0.39);
m_wndSplitter1.SetRowInfo(0,high*38/100,0);
m_wndSplitter2.SetColumnInfo(0,wide*39/100,0);
}
m_wndSplitter1.RecalcLayout();
m_wndSplitter2.RecalcLayout();
}
//保存数据
void CMainFrame::OnSave()
{
// TODO: Add your command handler code here
CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -