📄 cppmdi.cpp
字号:
/******************************************************************************/
/***** Copyright 2004-2004, Analytical Graphics, Incorporated. *****/
/******************************************************************************/
// MDI CPP.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "CPPMDI.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "CPPMDIDoc.h"
#include "CPPMDIVOView.h"
#include "CPPMDI2DView.h"
#include "agstkxapplication.h"
#include "agexeccmdresult.h"
#include "STKAppSink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCPPMDIApp
BEGIN_MESSAGE_MAP(CCPPMDIApp, CWinApp)
//{{AFX_MSG_MAP(CCPPMDIApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCPPMDIApp construction
CCPPMDIApp::CCPPMDIApp()
: m_VODocTemplate(NULL),
m_2DDocTemplate(NULL)
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCPPMDIApp object
CCPPMDIApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CCPPMDIApp initialization
BOOL CCPPMDIApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
SetRegistryKey(_T("AGI"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
if( !AfxOleInit() )
{
return FALSE;
}
if (!m_STKApplication.CreateDispatch("STKX.Application"))
{
TRACE0("Failed to create STK Application\n");
return FALSE;
}
// m_STKAppSink is the object that will response to events (such as "OnScenarioNew") sent
// by the STK/X Application object
LPUNKNOWN pUnkSink = m_STKAppSink.GetIDispatch(FALSE);
AfxConnectionAdvise(m_STKApplication, DIID_IAgSTKXApplicationEvents, pUnkSink, FALSE, &m_dwCookie);
if (!AfxInitRichEdit())
return FALSE;
// Register two document templates. One for the VO window and the other
// for the 2D window. Note that they both have the same document.
m_VODocTemplate = new CMultiDocTemplate( // VO Window
IDR_3DMENU,
RUNTIME_CLASS(CCPPMDIDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CCPPMDIVOView));
AddDocTemplate(m_VODocTemplate);
m_2DDocTemplate = new CMultiDocTemplate( // 2D Window
IDR_2DMENU,
RUNTIME_CLASS(CCPPMDIDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CCPPMDI2DView));
AddDocTemplate(m_2DDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Create the Message Viewer window
m_MsgViewDlg.Create(IDD_MESSAGE_VIEWER, pMainFrame);
m_MsgViewDlg.SetParent(pMainFrame);
m_MsgViewDlg.ShowWindow(SW_SHOWNORMAL);
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // do not create any child windows on startup
ParseCommandLine(cmdInfo);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
int CCPPMDIApp::ExitInstance()
{
LPUNKNOWN pUnkSink = m_STKAppSink.GetIDispatch(FALSE);
AfxConnectionUnadvise(m_STKApplication, DIID_IAgSTKXApplicationEvents, pUnkSink, FALSE, m_dwCookie);
m_STKApplication.ReleaseDispatch();
#if _MSC_VER >= 1300 //VC7 and upper
AfxOleTerm();
#endif
return CWinApp::ExitInstance();
}
// SendCommand
// sends a connect command to the VO control
// Returns
// true - if command was executed successfully
// false - if command failed, a message box is also displayed with the error
// Note
// if the command returns any text, it is displayed in a message box
bool CCPPMDIApp::SendSTKCommand(LPCTSTR command)
{
CWaitCursor wait; // show wait cursor while executing command
bool ret = true;
try
{
CAgExecCmdResult rVal = m_STKApplication.ExecuteCommand(command);
if(rVal.GetCount() > 0) // Display text returned, if any
{
COleVariant var = rVal.GetItem(0);
wait.Restore();
MessageBox(NULL,
CString(var.bstrVal),
"ExecuteCommand() return",
MB_OK | MB_ICONEXCLAMATION);
}
}
// Display a message box telling the user the command failed
catch(...)
{
wait.Restore();
MessageBox(NULL,
"Command \"" + CString(command) + "\" failed.",
"ExecuteCommand() failed",
MB_OK | MB_ICONEXCLAMATION);
ret = false;
}
return ret;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnViewNew2dWindow();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CCPPMDIApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/******************************************************************************/
/***** Copyright 2004-2004, Analytical Graphics, Incorporated. *****/
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -