📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Wsn.h"
#include "MainFrm.h"
#include "GraphView.h"
#include "MsgView.h"
#include "ParaView.h"
#include "RestView.h"
#include "DrawGraph.h"
#include "InitParameter.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_INIT_PARA, OnInitPara)
ON_COMMAND(ID_CTR_START, OnCtrStart)
//}}AFX_MSG_MAP
ON_MESSAGE(UM_GRAPH,OnGraph)
ON_MESSAGE(UM_PARAVIEW,OnParaview)
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
}
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);
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
cs.cx=800;
cs.cy=600;
cs.style&=~FWS_ADDTOTITLE;
cs.style=WS_OVERLAPPEDWINDOW;
cs.lpszName="无线传感器模拟程序";
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_HELP);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=AfxGetInstanceHandle();
wndcls.lpfnWndProc=::DefWindowProc;
wndcls.lpszClassName="bitch";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
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
BOOL bresult=m_wndsplitterv.CreateStatic(this,1,2);
ASSERT(bresult);
m_wndsplitterh.CreateStatic(&m_wndsplitterv,3,1,WS_CHILD | WS_VISIBLE,m_wndsplitterv.IdFromRowCol(0,1));
m_wndsplitterv.CreateView(0,0,RUNTIME_CLASS(CGraphView),CSize(600,600),pContext);
m_wndsplitterh.CreateView(0,0,RUNTIME_CLASS(CParaView),CSize(100,100),pContext);
m_wndsplitterh.CreateView(1,0,RUNTIME_CLASS(CRestView),CSize(100,100),pContext);
m_wndsplitterh.CreateView(2,0,RUNTIME_CLASS(CMsgView),CSize(100,100),pContext);
//设置窗格的初始化的大小
m_wndsplitterv.SetRowInfo(0,500,0);
m_bcreatesplitter=true;
//激活sceneview使得其可以接受命令消息
m_wndsplitterv.SetActivePane(0,0,NULL);
return bresult;
}
void CMainFrame::OnInitPara()
{
// TODO: Add your command handler code here
MessageBox("main");
CInitParameter dlg;
this->Invalidate();
if(IDOK==dlg.DoModal())
{
m_datasize = dlg.m_datasize;
m_rectlenth = dlg.m_rectlenth;
m_rectwidth = dlg.m_rectwidth;
m_hcellnum = dlg.m_hcellnum;
m_vcellnum = dlg.m_vcellnum;
m_initnode_energy = dlg.m_initnode_energy;
m_sink_position = dlg.m_sink_position;
m_node_num = dlg.m_node_num;
m_Binitpar_set = TRUE;
}
UpdateData();
}
void CMainFrame::OnCtrStart()
{
// TODO: Add your command handler code here
m_wndsplitterv.SetActivePane(0,0,NULL);
PostMessage(UM_GRAPH);
if(m_Binitpar_set == TRUE)
{
CDC *pDC;
pDC = GetDC();
CDrawGraph::DrawCoordinates(pDC,m_rectlenth,m_rectwidth,m_hcellnum,m_vcellnum);
}
else
{
MessageBox("请先设置初始参数!");
}
}
void CMainFrame::OnGraph()
{
MessageBox("onGraph");
//m_wndsplitterh.SetActivePane(0,0,NULL);
PostMessage(UM_PARAVIEW);
}
void CMainFrame::OnParaview()
{
MessageBox("onParaview");
CClientDC dc(this);
dc.TextOut(612,72,"sdfsdf");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -