📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Simulate.h"
//#include "SimulateView.h"
#include "MainFrm.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
//class CSimulateView;
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_SYSCOMMAND()
ON_WM_CREATE()
ON_WM_TIMECHANGE()
ON_COMMAND(IDM_SIMULATE, OnSimulate)
ON_COMMAND(IDM_PAUSE, OnPause)
ON_COMMAND(IDM_STOP, OnStop)
ON_COMMAND(IDM_SET, OnSet)
ON_COMMAND(IDM_HIDEOUTBAR, OnHideoutbar)
ON_COMMAND(IDM_CLEAREDIT, OnClearedit)
ON_COMMAND(IDM_OUTPUTBAR, OnOutputbar)
ON_COMMAND(IDM_WORKSPACEBAR, OnWorkspacebar)
ON_WM_CLOSE()
ON_COMMAND(IDM_MAIN, OnMain)
ON_COMMAND(IDM_HIDE, OnHide)
ON_COMMAND(ID_APP_EXIT, OnAppExit)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
ON_MESSAGE(WM_HOTKEY,OnHotKey)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
//UINT SimulateProc(LPVOID pParam);
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_strResultData=
"--------------------------------------------------------------欢迎使用超微弱发光聚光腔设计模拟系统!-------------------------------------------------------------\r\n\r\n使用说明:\r\n\r\n 适用操作系统:2K/XP/NT;\r\n\r\n 更多帮助,请按F1;\r\n\r\n 版权所有:203-01宿舍。请尊重本集体劳动成果,切勿反汇编本软件,否则,后果自负!欢迎自由传播本软件。";
m_bShow=true;
m_nSimulateNum=0;
m_pSimulateDoc=0;
m_pCurView=0;
m_nCurViewID=0;//当前视图为随机模拟中的0号
m_fCurLAxis=50;
m_bStop=true;
m_pMainFrame=0;
m_MaxRecord.nGoodPhotonCount=0;
m_nGoodPhotonCount=0;
m_nBadPhotonCount=0;
m_nDeadPhotonCount=0;
m_fGoodRate=0;
m_nIndex=0;
m_MaxRecord.fGoodRate=0;
m_MaxRecord.fBadRate=0;
m_MaxRecord.fDeadRate=0;
m_MaxRecord.fLAxis=0;
m_MaxRecord.fSAxis=0;
m_MaxRecord.nBadPhotonCount=0;
m_MaxRecord.nDeadPhotonCount=0;
m_MaxRecord.nGoodPhotonCount=0;
m_MaxRecord.nIndex=0;
m_nCurThreadNum=0;
m_nMaxThreadNum=50;
m_bIsUseFirst=true;
m_bIsPressOutlookItem=false;
m_nCurOutputViewID=0;
//-------------得到参数设置------------------
m_dlgSet.ApplySet(m_SetParam);
//参数结构封装
m_fLAxisAdd=m_SetParam.fLAxisAdd;
m_fLAxisFrom=m_SetParam.fLAxisFrom;
m_fObjRadius=m_SetParam.fObjRadius;
m_fSAxisAdd=m_SetParam.fSAxisAdd;
m_fSAxisFrom=m_SetParam.fSAxisFrom;
m_fShineIntensity=m_SetParam.fShineIntensity;
m_nAllPhoton=m_SetParam.nAllPhoton;
m_nReflectCount=m_SetParam.nReflectCount;
m_nObjSort=m_SetParam.nObjSort;
m_nRandomSimulateNum=m_SetParam.nRandomSimulateNum;
m_fError=m_SetParam.fError;
//-------------------------------------------
}
CMainFrame::~CMainFrame()
{
//---------------释放链表指针--------------------
SimulateViewList* p;
SimulateViewList* q;
p=this->m_pSimulateViewListHead;
while(p)
{
q=p;
free(q);
p=p->pNext;
}
//-----------------------------------------------
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
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
}
//--------------------------创建工具栏----------------------------------
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
}
// 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);
m_wndToolBar.SetButtonText(0,"模拟");
m_wndToolBar.SetButtonText(1,"暂停");
m_wndToolBar.SetButtonText(2,"停止");
m_wndToolBar.SetButtonText(4,"删除");
m_wndToolBar.SetButtonText(5,"清空");
m_wndToolBar.SetButtonText(7,"分析");
m_wndToolBar.SetButtonText(9,"设置");
m_wndToolBar.SetButtonText(11,"帮助");
m_wndToolBar.SetButtonText(13,"关于");
m_wndToolBar.SetButtonText(15,"退出");
m_wndToolBar.SetSizes(CSize(42,51),CSize(32,32));
//-----------------------------------------------------------------------------
//创建工作空间栏
//------------------------------------------------------------------------------
if( !m_wndWorkSpaceBar.Create(this, ID_VIEW_WORKSPACE,
_T("工作空间"), CSize(140,200), CBRS_LEFT ))
{
TRACE0("Failed to create dialog bar m_wndWorkSpaceBar\n");
return -1; // fail to create
}
// Define the image list to use with the tab control
m_wndWorkSpaceBar.EnableDockingOnSizeBar( CBRS_ALIGN_ANY );
EnableDockingSizeBar( CBRS_ALIGN_ANY );
DockSizeBar( &m_wndWorkSpaceBar );
//-------------------------------------------------------------------------------
//创建输出结果栏
//---------------------------------------------------------------------
if(!m_wndOutputBar.Create(this, ID_VIEW_OUTPUT,_T("输出"), CSize(310,180), CBRS_BOTTOM))
{
TRACE0("Failed to create mybar\n");
return -1; // fail to create
}
m_wndOutputBar.SetBarStyle(m_wndOutputBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_BOTTOM);
m_wndOutputBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDockingSizeBar(CBRS_ALIGN_ANY);
DockSizeBar(&m_wndOutputBar);
//显示输出信息
m_wndOutputBar.SetEditText(0,m_strResultData);
//-----------------------------------------------------------------------------
//--------------------------创建数据分析视图-----------------------------------
m_pAnalyseView=new CSimulateView;
m_pAnalyseView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1);
m_pAnalyseView->OnInitialUpdate();
//-----------------------------------------------------------------------------
//------------------建立链表并初始化--------------------
//初始化头节点:数据分析视图
m_pSimulateViewListHead=m_pSimulateViewList=(SimulateViewList*)malloc(sizeof(CSimulateView));
m_pSimulateViewList->pSimulateView=m_pSimulateViewListHead->pSimulateView=m_pAnalyseView;
m_pSimulateViewList->nIndex=m_pSimulateViewListHead->nIndex=-1;
//初始化第二个节点:随机模拟1
m_pSimulateViewList->pTail=m_pSimulateViewListHead->pTail=m_pSimulateViewList->pNext=m_pSimulateViewListHead->pNext=(SimulateViewList*)malloc(sizeof(CSimulateView));
m_pSimulateViewList->pNext->nIndex=m_pSimulateViewListHead->pNext->nIndex=0;
m_pSimulateViewList->pNext->pNext=m_pSimulateViewListHead->pNext->pNext=NULL;
//------------------------------------------------------
//------------添加托盘到任务栏-------------------
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=this->m_hWnd;
tnd.uID=IDR_MAINFRAME;
tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage=WM_ICON_NOTIFY;
tnd.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
strcpy(tnd.szTip,"☆★超微弱发光聚光腔设计模拟系统★☆");
Shell_NotifyIcon(NIM_ADD,&tnd);
m_bShow=true;
//-----------------------------------------------
//注册热键
RegisterHotKey(m_hWnd,0xB4EE,MOD_CONTROL | MOD_ALT | MOD_SHIFT,VK_F10);
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
void CMainFrame::OnTimeChange()
{
CFrameWnd::OnTimeChange();
// TODO: Add your message handler code here
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CFrameWnd::OnCreateClient(lpcs, pContext);
}
void CMainFrame::ChangeView(int nFolder,int nIndex)
{
CSimulateView* p;
if(!m_pSimulateDoc)
m_pSimulateDoc=(CSimulateDoc*)GetActiveDocument();
m_pCurView=(CSimulateView*)GetActiveView();
switch(nFolder)
{
case 0://随机模拟
if(!m_bIsPressOutlookItem)
{
m_pSimulateViewList->pNext->pSimulateView=m_pSimulateViewListHead->pNext->pSimulateView=m_pCurView;
}
if(nIndex==m_nCurViewID)
{
//使按标志为真
m_bIsPressOutlookItem=true;
return;
}
//查找当前视图在视图链表中的位置
p=this->SearchViewByIndex(nIndex,!m_bStop);
m_pSimulateDoc->AddView(p);
p->ShowWindow(true);
p->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
this->SetActiveView(p);
m_pSimulateViewList->pSimulateView=m_pCurView;
m_pSimulateViewList->nIndex=nIndex;
m_nCurViewID=nIndex;
m_pCurView->ShowWindow(false);
m_pCurView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
m_pSimulateDoc->RemoveView(m_pCurView);
break;
case 1://数据分析
if(!m_bIsPressOutlookItem)
{
m_pSimulateViewList->pNext->pSimulateView=m_pSimulateViewListHead->pNext->pSimulateView=m_pCurView;
}
//当前视图已为数据分析
if(m_nCurViewID==-1)
{
//使按标志为真
m_bIsPressOutlookItem=true;
return;
}
m_pSimulateDoc->AddView(m_pAnalyseView);
m_pAnalyseView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pAnalyseView->ShowWindow(true);
this->SetActiveView(m_pAnalyseView);
m_nCurViewID=-1;
m_pCurView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
m_pCurView->ShowWindow(false);
m_pSimulateDoc->RemoveView(m_pCurView);
break;
default:
break;
}
RecalcLayout();
}
void CMainFrame::ChangeOutputView(int nID)
{
if(nID==m_nCurOutputViewID)
return;
this->m_wndOutputBar.SelectTabView(nID);
m_nCurOutputViewID=nID;
}
void CMainFrame::OnSimulate()
{
// TODO: Add your command handler code here
//正在模拟
if(m_bStop==false)
return;
//-------------得到参数设置------------------
m_dlgSet.ApplySet(m_SetParam);
//参数结构封装
m_fLAxisAdd=m_SetParam.fLAxisAdd;
m_fLAxisFrom=m_SetParam.fLAxisFrom;
m_fObjRadius=m_SetParam.fObjRadius;
m_fSAxisAdd=m_SetParam.fSAxisAdd;
m_fSAxisFrom=m_SetParam.fSAxisFrom;
m_fShineIntensity=m_SetParam.fShineIntensity;
m_nAllPhoton=m_SetParam.nAllPhoton;
m_nReflectCount=m_SetParam.nReflectCount;
m_nObjSort=m_SetParam.nObjSort;
//-------------------------------------------
if(!m_bIsPressOutlookItem)
{
// this->ChangeView(1,0);
this->ChangeView(0,0);
}
/* CMenu* pMenu = GetMenu();
CMenu* pSub = pMenu->GetSubMenu(0);
pSub->EnableMenuItem(IDM_START, MF_GRAYED);
pSub->EnableMenuItem(IDM_STOP, MF_ENABLED);
m_wndToolBar.SendMessage(TB_SETSTATE, IDM_STOP, MAKELONG(TBSTATE_ENABLED,0));
m_wndToolBar.SendMessage(TB_SETSTATE, IDM_STOP, MAKELONG(TBSTATE_MARKED,0));
m_wndToolBar.SendMessage(TB_SETSTATE, IDM_START, MAKELONG(TBSTATE_INDETERMINATE,0));
*/ m_wndStatusBar.SetPaneText(0,"正在进行计算机模拟,请稍候...",true);
m_bStop=false;
DWORD dwThreadID;
DWORD (WINAPI CMainFrame:: *p1)() =SimulateProc;
DWORD (WINAPI *p2)(LPVOID) = NULL;
memcpy(&p2, &p1, sizeof(p1));
m_hThread = ::CreateThread(NULL, 0, p2, this, 0, &dwThreadID);
if(m_hThread == NULL)
{
MessageBox("创建线程时出现错误!","嗅探",MB_ICONINFORMATION);
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -