I try to integrate cocos2d to mfc.
and i have successfully display the cocos2d in mfc view.
but displayed screen is some clipping.
and system touch position is some different from your touch position.
what’s the problems?
AppDelegate.cpp -> applicationDidFinishLaunching()
// link mfc view.
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("My Game");
CLevelView* pView = CLevelView::sView;
if (pView->GetSafeHwnd() != nullptr)
std::cout << "get view handle success." << std::endl;
else
std::cout << "failed getting handle." << std::endl;
::SetParent(glview->getWin32Window(), pView->m_hWnd);
DWORD style = ::GetWindowLong(glview->getWin32Window(), GWL_STYLE);
style &= ~(WS_POPUP | WS_CAPTION | WS_BORDER);
style |= (WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE);
::SetWindowLong(glview->getWin32Window(), GWL_STYLE, style);
director->setOpenGLView(glview);
}
ChildView.cpp ->> OnSize(UINT nType, int cx, int cy)
default mfc onsize message handler.
CWnd::OnSize(nType, cx, cy);
// TODO:
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if (glview != nullptr)
{
printf("ChildView size %d, %d\n", cx, cy);
::MoveWindow(glview->getWin32Window(), 0, 0, cx, cy, true);
glview->setFrameSize(cx, cy);
//glview->setDesignResolutionSize(cx, cy, ResolutionPolicy::NO_BORDER);
cocos2d::Size designsize = glview->getDesignResolutionSize();
glview->setDesignResolutionSize(designsize.width, designsize.height, ResolutionPolicy::SHOW_ALL);
}
The rest of the code is the same.
