【发布时间】:2015-12-25 19:38:46
【问题描述】:
我已经为具有文档/视图架构的 SDI MFC 应用程序创建了项目。
现在,我想将主窗口和棋盘分开(我正在尝试编写棋盘游戏)。我想将板子放在子窗口中,以便进一步轻量级将它们居中取决于父(主)窗口的大小。
实际上我已经这样做了,但现在我有一个问题 - 我还想等待来自鼠标的消息。
class CGameView {
// ...
CGameView()
{
childWnd = new CWnd;
}
~CGameView()
{
delete childWnd;
}
void CGameView::OnSize(UINT nType, int cx, int cy) {
CGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)
return;
// I bind the height of child window with height of parent
RECT rcClient;
GetClientRect(&rcClient);
rcClient.left = 0;
rcClient.right = pDoc->getWidth();
childWnd->MoveWindow(&rcClient);
childWnd->CenterWindow();
return;
}
int CGameView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)
return -1;
childWnd->Create(NULL, NULL, WS_CHILD | WS_VISIBLE,
CRect(0, 0, pDoc->getWidth(), pDoc->getHeight()), this, 0);
return 0;
}
void CGameView::OnDraw(CDC* pDC)
{
CGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rcClient;
GetClientRect(&rcClient);
CClientDC cdc(childWnd);
// The pOffScreen contains the bitmap that I just copy to specified CDC
pOffScreen->print(&cdc, &rcClient);
}
}
?我非常关心我做孩子窗口的方式的正确性。 ?现在,我不知道如何通过我的子窗口漂亮地监听鼠标消息?
【问题讨论】: