📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "PlugSDI.h"
#include "MainFrm.h"
#include "resource.h"
#include "PlugInSelectDialog.h"
//#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Pointers to some of the PlugIn functions
typedef VOID (*PLUGINMSGHANDLER) (UINT, int, void*, AFX_CMDHANDLERINFO*);
typedef VOID (*PLUGINRESOURCE) (HICON*, CString*);
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_PLUG_LOADPLUGINS, OnPlugLoadPlugins)
ON_WM_CLOSE()
// ON_CONTROL_RANGE(BN_CLICKED, ID_BUTTON_PLUGIN_1, ID_BUTTON_PLUGIN_10, OnCallPlugInManager)
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()
: m_bIsPlugInLoaded(false),
m_pLoadedDLLs(NULL),
m_nNumberOfDLLs(0)
{
// TODO: add member initialization code here
#ifdef DEBUG
TRACE("Called CMainFrame::CMainFrame() method\n");
#endif
// No Plug-Ins currently loaded
// So all member variables initialized to NULL/FALSE
}
CMainFrame::~CMainFrame()
{
#ifdef DEBUG
TRACE("Called CMainFrame::~CMainFrame() method\n");
#endif
if (m_nNumberOfDLLs > 0)
{
// free the DLL's
delete []m_pLoadedDLLs;
m_pLoadedDLLs = NULL;
m_nNumberOfDLLs = 0;
m_bIsPlugInLoaded = FALSE;
m_szListDLLsCurrentlyLoaded.RemoveAll();
}
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
/* if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
#ifdef DEBUG
TRACE0("Failed to create toolbar\n");
#endif
return -1; // fail to create
}
if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
{
#ifdef DEBUG
TRACE0("Failed to create dialogbar\n");
#endif
return -1; // fail to create
}
if (!m_wndReBar.Create(this) ||
!m_wndReBar.AddBar(&m_wndToolBar) ||
!m_wndReBar.AddBar(&m_wndDlgBar))
{
#ifdef DEBUG
TRACE0("Failed to create rebar\n");
#endif
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
#ifdef DEBUG
TRACE0("Failed to create status bar\n");
#endif
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);
return 0;
*/
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))
{
#ifdef DEBUG
TRACE0("Failed to create toolbar\n");
#endif
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
#ifdef DEBUG
TRACE0("Failed to create status bar\n");
#endif
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_wndDlgBar.Create(this, IDD_PLUGIN_DIALOGBAR, CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE, ID_VIEW_PLUGIN_BAR)) { TRACE0("Failed to create dialog bar"); return -1; // fail to create } m_wndDlgBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndDlgBar);*/ return 0;
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
return m_wndSplitter.Create(this,
2, 2, // TODO: adjust the number of rows, columns
CSize(10, 10), // TODO: adjust the minimum pane size
pContext);
}
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.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE | WS_SYSMENU;
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::OnPlugLoadPlugins()
{
#ifdef DEBUG
TRACE("Called CMainFrame::OnPlugLoadPlugins() method\n");
#endif
CPlugInSelectDialog pDiag;
pDiag.DoModal();
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
#ifdef DEBUG
TRACE("Called CMainFrame::OnClose() method\n");
#endif
if (m_nNumberOfDLLs > 0)
{
// free the DLL's
delete []m_pLoadedDLLs ;
m_pLoadedDLLs = NULL ;
m_nNumberOfDLLs = 0 ;
}
CFrameWnd::OnClose();
}
// Used to pump message into DLLs
void CMainFrame::OnCallPlugInManager(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
#ifdef DEBUG
TRACE("Called CMainFrame::OnCallPlugInManager() method\n");
#endif
PLUGINMSGHANDLER fDLLfunction;
for (int nNumDlls = 0 ; nNumDlls < m_nNumberOfDLLs ; nNumDlls++)
{
if (m_pLoadedDLLs[nNumDlls].m_pDLLhInstance != NULL)
{
fDLLfunction = (PLUGINMSGHANDLER) GetProcAddress(m_pLoadedDLLs[nNumDlls].m_pDLLhInstance,"PlugInEventHandler");
if (fDLLfunction)
(fDLLfunction) (nID, nCode, pExtra, pHandlerInfo);
else
{
#ifdef DEBUG
TRACE("Function \"PlugInEventHandler()\"not found in DLL");
#endif
AfxMessageBox("ERROR: Could not find PlugInEventHandler function in Plug-In\nDLL corrupt or valid\nRe-Install Plug-In\nUn-Loading currently cloaded instance of this Plug-In");
m_pLoadedDLLs[nNumDlls].FreeDLL();
}
}
}
}
// Used to return the toolbar object
CToolBar* CMainFrame::GetToolBarObject(void)
{
#ifdef DEBUG
TRACE("Called CMainFrame::GetToolBarObject() method\n");
#endif
return &m_wndToolBar;
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
// If pHandlerInfo is NULL, then handle the message
if (pHandlerInfo == NULL)
{
if (m_bIsPlugInLoaded)
{
for (int nNumDlls = 0 ; nNumDlls < m_nNumberOfDLLs ; nNumDlls++)
{
if (m_pLoadedDLLs[nNumDlls].m_pDLLhInstance != NULL)
{
UINT nTempID = m_pLoadedDLLs[nNumDlls].GetToolBarButtonID();
if (nTempID == nID)
{
if (nCode == CN_UPDATE_COMMAND_UI)
{
// Update UI element state
((CCmdUI *) pExtra)->Enable(TRUE);
return TRUE;
}
if (nCode == CN_COMMAND)
{
#ifdef DEBUG
TRACE("Called CMainFrame::OnCmdMsg() method for CN_COMMAND\n");
#endif
// Handle WM_COMMAND Message
OnCallPlugInManager(nID, nCode, pExtra, pHandlerInfo);
// CString str;
// m_wndToolBar.GetWindowText(str);
// ::SendMessage(PLUGIN_TBBUTTON_CLICK, 10, 11);
// m_pLoadedDLLs[nNumDlls].pApp->PostThreadMessage(PLUGIN_TBBUTTON_CLICK, nID, 0);
return TRUE;
}
}
}
}
}
}
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -