|
// ChildFrm.cpp: CChildFrame 类的实现
|
//
|
|
#include "pch.h"
|
#include "framework.h"
|
#include "MFCMView.h"
|
|
#include "ChildFrm.h"
|
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#endif
|
|
// CChildFrame
|
|
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWndEx)
|
|
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWndEx)
|
ON_COMMAND(ID_FILE_CLOSE, &CChildFrame::OnFileClose)
|
ON_WM_SETFOCUS()
|
ON_WM_CREATE()
|
END_MESSAGE_MAP()
|
|
// CChildFrame 构造/析构
|
|
CChildFrame::CChildFrame() noexcept
|
{
|
// TODO: 在此添加成员初始化代码
|
}
|
|
CChildFrame::~CChildFrame()
|
{
|
}
|
|
|
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
|
{
|
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式
|
if( !CMDIChildWndEx::PreCreateWindow(cs) )
|
return FALSE;
|
|
cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
|
| FWS_ADDTOTITLE | WS_THICKFRAME;
|
|
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
|
cs.lpszClass = AfxRegisterWndClass(0);
|
return TRUE;
|
}
|
|
// CChildFrame 诊断
|
|
#ifdef _DEBUG
|
void CChildFrame::AssertValid() const
|
{
|
CMDIChildWndEx::AssertValid();
|
}
|
|
void CChildFrame::Dump(CDumpContext& dc) const
|
{
|
CMDIChildWndEx::Dump(dc);
|
}
|
#endif //_DEBUG
|
|
// CChildFrame 消息处理程序
|
void CChildFrame::OnFileClose()
|
{
|
// 若要关闭框架,只需发送 WM_CLOSE,
|
// 这相当于从系统菜单中选择关闭。
|
SendMessage(WM_CLOSE);
|
}
|
|
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
{
|
if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
|
return -1;
|
|
// 创建一个视图以占用框架的工作区
|
if (!m_wndView.Create(nullptr, nullptr, AFX_WS_DEFAULT_VIEW,
|
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, nullptr))
|
{
|
TRACE0("未能创建视图窗口\n");
|
return -1;
|
}
|
|
return 0;
|
}
|
|
void CChildFrame::OnSetFocus(CWnd* pOldWnd)
|
{
|
CMDIChildWndEx::OnSetFocus(pOldWnd);
|
|
m_wndView.SetFocus();
|
}
|
|
BOOL CChildFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
|
{
|
// 让视图第一次尝试该命令
|
if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
|
return TRUE;
|
|
// 否则,执行默认处理
|
return CMDIChildWndEx::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
|
}
|