[Win32] add custom menu and custom windows message proc

This commit is contained in:
YuLei Liao 2012-09-02 04:38:52 +08:00
parent c86595ddde
commit d4c53d43b9
2 changed files with 36 additions and 2 deletions

View File

@ -89,6 +89,8 @@ CCEGLView::CCEGLView()
, m_hDC(NULL)
, m_hRC(NULL)
, m_lpfnAccelerometerKeyHook(NULL)
, m_menu(NULL)
, m_wndproc(NULL)
{
strcpy(m_szViewName, "Cocos2dxWin32");
}
@ -162,7 +164,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszMenuName = m_menu; //
wc.lpszClassName = kWindowClassName; // Set The Class Name
CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError());
@ -204,6 +206,8 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
BOOL bProcessed = FALSE;
switch (message)
{
case WM_LBUTTONDOWN:
@ -292,7 +296,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
else if (VK_ESCAPE == wParam)
{
// ESC input
CCDirector::sharedDirector()->end();
//CCDirector::sharedDirector()->end();
}
}
else if (wParam < 128)
@ -328,8 +332,19 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
break;
default:
if (m_wndproc)
{
m_wndproc(message, wParam, lParam, &bProcessed);
if (bProcessed) break;
}
return DefWindowProc(m_hWnd, message, wParam, lParam);
}
if (m_wndproc && !bProcessed)
{
m_wndproc(message, wParam, lParam, &bProcessed);
}
return 0;
}
@ -376,6 +391,16 @@ bool CCEGLView::enableRetina()
return true;
}
void CCEGLView::setMenuResource(LPCWSTR menu)
{
m_menu = menu;
}
void CCEGLView::setWndProc(CUSTOM_WND_PROC proc)
{
m_wndproc = proc;
}
HWND CCEGLView::getHWnd()
{
return m_hWnd;

View File

@ -32,6 +32,8 @@ THE SOFTWARE.
NS_CC_BEGIN
typedef LRESULT (*CUSTOM_WND_PROC)(UINT message, WPARAM wParam, LPARAM lParam, BOOL* pProcessed);
class CCEGL;
class CC_DLL CCEGLView : public CCEGLViewProtocol
@ -48,6 +50,10 @@ public:
virtual void setFrameSize(float width, float height);
virtual void setIMEKeyboardState(bool bOpen);
virtual bool enableRetina();
void setMenuResource(LPCWSTR menu);
void setWndProc(CUSTOM_WND_PROC proc);
private:
virtual bool Create(LPCTSTR pTitle, int w, int h);
bool initGL();
@ -77,6 +83,9 @@ private:
HDC m_hDC;
HGLRC m_hRC;
LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook;
LPCWSTR m_menu;
CUSTOM_WND_PROC m_wndproc;
};
NS_CC_END