在CCLayer.h中
添加成员方法
virtual void processWin32KeyPress(UINT message, WPARAM wParam, LPARAM lParam) {}
CCEGLView_win32.h中添加
私有成员变量
CCLayer *m_pLayWin32Key;
并增加函数
void SetWin32KeyLayer(CCLayer *pLayer)
{
m_pLayWin32Key = pLayer;
}
同时,在CCEGLView::WindowProc函数中,增加这一行
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(NULL != m_pLayWin32Key)
{
m_pLayWin32Key->processWin32KeyPress(message, wParam, lParam);
}
......(原有的,略)
}
改造CCEGLView构造函数
CCEGLView::CCEGLView()
: m_bCaptured(false)
, m_bOrientationReverted(false)
, m_bOrientationInitVertical(false)
, m_pDelegate(NULL)
, m_pEGL(NULL)
,m_pLayWin32Key(NULL) //增加这一行
, m_hWnd(NULL)
, m_eInitOrientation(CCDeviceOrientationPortrait)
, m_fScreenScaleFactor(1.0f)
, m_lpfnAccelerometerKeyHook(NULL)
{
m_pTouch = new CCTouch;
m_pSet = new CCSet;
m_tSizeInPoints.cx = m_tSizeInPoints.cy = 0;
SetRectEmpty(&m_rcViewPort);
}
使用方法
HelloWorld(.h文件)中增加成员函数
virtual void processWin32KeyPress(UINT message, WPARAM wParam, LPARAM lParam);
在.ccp中的构造函数中,增加
void HelloWorld::processWin32KeyPress(UINT message, WPARAM wParam, LPARAM lParam)
{
//此处与其他win32程序类似
}
同时增加
CCDirector::sharedDirector()->getOpenGLView()->SetWin32KeyLayer(this);
否则没响应.
抛砖引玉,希望各位指点批评。