?? mfcappadapter.cpp
字號:
// MfcAppAdapter.cpp
/*
* Copyright (c) 2005 Alexey Shalnov
* All Rights Reserved
*
* http://home.arcor.de/alexeyshalnov/home/
*/
#include "stdafx.h"
#include "MfcAppAdapter.h"
#include "Hosting/IApplication.h"
using namespace AS::MfcHost2;
////////////////////////////////////////////////////////////////
MfcAppAdapter::MfcAppAdapter()
{
}
MfcAppAdapter^ MfcAppAdapter::CreateInstance(IWndManager^ wndManager)
{
ASSERT(wndManager);
//we use only one instance
if(Instance==nullptr)
{
Instance = gcnew MfcAppAdapter();
if(!Instance->AttachApplication(wndManager))
{
delete Instance;
Instance = nullptr;
}
}
ASSERT(Instance!=nullptr);
return Instance;
}
IFramework* MfcAppAdapter::GetFramework()
{
return (IFramework*)MfcAppAdapter::m_pIFrameworkImpl;
}
// Command messages transmition
bool MfcAppAdapter::OnCmdMsg(MfcCommand commandID)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
int nID = (int)commandID;
bool result = false;
CMDIFrameWnd* pMainFrame = dynamic_cast <CMDIFrameWnd*>(AfxGetMainWnd());
if(pMainFrame != NULL)
result = pMainFrame->OnCmdMsg(nID, CN_COMMAND, NULL, NULL) != FALSE;
return result;
}
// initialisation of Legacy MFC application
bool MfcAppAdapter::AttachApplication(IWndManager^ wndManager)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
bool retval = false;
IApplication* pApp = dynamic_cast<IApplication*>(AfxGetApp());
// We can host the application with IApplication interface only!!!
ASSERT(pApp!=NULL);
if(pApp!=NULL)
{
m_pWndManager = wndManager;
HWND externframe = (HWND)(wndManager->GetExternFrame()).ToInt32();
MfcAppAdapter::m_pIFrameworkImpl = new IFrameworkImpl(externframe);
if (::IsWindow(externframe))
{
try
{
if(pApp->AttachApplication(MfcAppAdapter::GetFramework())==TRUE)
retval = true;
}
catch(...){}
}
}
return retval;
}
// Close Legacy MFC application
MfcAppAdapter::~MfcAppAdapter()
{
this->!MfcAppAdapter();
}
MfcAppAdapter::!MfcAppAdapter()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
try
{
IApplication* pApp = dynamic_cast<IApplication*>(AfxGetApp());
if(pApp!=NULL)
pApp->DetachApplication();
}
finally
{
delete MfcAppAdapter::m_pIFrameworkImpl;
MfcAppAdapter::m_pIFrameworkImpl = NULL;
Instance=nullptr;
}
}
/////////////////////////////////////////////////////////////////////////////
// IFramework
// Connect the Legacy MFC application with WinForms Framework
IFrameworkImpl::IFrameworkImpl(HWND ExternFrameHwnd)
{
m_ExternFrameHwnd = ExternFrameHwnd;
}
HWND IFrameworkImpl::GetExternFrame() {return m_ExternFrameHwnd;};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -