Example #1
0
void CCEGLView::setTouch(void* systemData)
{
	s3ePointerEvent* event =(s3ePointerEvent*)systemData;
    int id = 0;
    float x = (float)event->m_x;
    float y = (float)event->m_y;
	switch (event->m_Pressed)
	{
	case S3E_POINTER_STATE_DOWN :
		m_bCaptured = true;
        handleTouchesBegin(1, &id, &x, &y);
		break;
	case S3E_POINTER_STATE_UP :
		if (m_bCaptured)
		{
			handleTouchesEnd(1, &id, &x, &y);
			m_bCaptured = false;
		}
		break;
	}
}
Example #2
0
void EGLView::HandleMouseEvent(const pp::MouseInputEvent* event)
{
    pp::Point pos = event->GetPosition();
    float x = pos.x();
    float y = pos.y();
    int touchID = 1;

    // Clamp event position to be within cocos2dx window size
    Size frame_size = getFrameSize();
    float max_y = frame_size.height;
    float max_x = frame_size.width;

    if (x < 0)
      x = 0;
    if (y < 0)
      y = 0;
    if (y > max_y)
      y = max_y;
    if (x > max_x)
      x = max_x;

    switch (event->GetType())
    {
        case PP_INPUTEVENT_TYPE_MOUSEDOWN:
            handleTouchesBegin(1, &touchID, &x, &y);
            bIsMouseDown = true;
            break;
        case PP_INPUTEVENT_TYPE_MOUSEUP:
            handleTouchesEnd(1, &touchID, &x, &y);
            bIsMouseDown = false;
            break;
        case PP_INPUTEVENT_TYPE_MOUSEMOVE:
            if (bIsMouseDown)
                handleTouchesMove(1, &touchID, &x, &y);
            break;
        default:
            break;
    }
}
Example #3
0
void CCEGLView::setMultiTouch(void* systemData)
{
	s3ePointerTouchEvent* event =(s3ePointerTouchEvent*)systemData;
    int id = (int)event->m_TouchID;
    float x = (float)event->m_x;
    float y = (float)event->m_y;

	switch (event->m_Pressed)
	{
        case S3E_POINTER_STATE_DOWN:
            {
                handleTouchesBegin(1, &id, &x, &y);
            }
            break;
            
        case S3E_POINTER_STATE_UP:
            {
                handleTouchesEnd(1, &id, &x, &y);
            }
            break;
	}
}
Example #4
0
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    BOOL bProcessed = FALSE;

    switch (message)
    {
    case WM_LBUTTONDOWN:
#if(_MSC_VER >= 1600)
        // Don't process message generated by Windows Touch
        if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */

        if (m_pDelegate && MK_LBUTTON == wParam)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            CCPoint pt(point.x, point.y);
            pt.x /= m_fFrameZoomFactor;
            pt.y /= m_fFrameZoomFactor;
            CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
            if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
            {
                m_bCaptured = true;
                SetCapture(m_hWnd);
                int id = 0;
                handleTouchesBegin(1, &id, &pt.x, &pt.y);
            }
        }
        break;

    case WM_MOUSEMOVE:
#if(_MSC_VER >= 1600)
        // Don't process message generated by Windows Touch
        if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */
        if (MK_LBUTTON == wParam && m_bCaptured)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            CCPoint pt(point.x, point.y);
            int id = 0;
            pt.x /= m_fFrameZoomFactor;
            pt.y /= m_fFrameZoomFactor;
            handleTouchesMove(1, &id, &pt.x, &pt.y);
        }
        break;

    case WM_LBUTTONUP:
#if(_MSC_VER >= 1600)
        // Don't process message generated by Windows Touch
        if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */
        if (m_bCaptured)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            CCPoint pt(point.x, point.y);
            int id = 0;
            pt.x /= m_fFrameZoomFactor;
            pt.y /= m_fFrameZoomFactor;
            handleTouchesEnd(1, &id, &pt.x, &pt.y);

            ReleaseCapture();
            m_bCaptured = false;
        }
        break;
#if(_MSC_VER >= 1600)
    case WM_TOUCH:
		{
            BOOL bHandled = FALSE;
            UINT cInputs = LOWORD(wParam);
            PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
            if (pInputs)
            {
                if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
                {
                    for (UINT i=0; i < cInputs; i++)
                    {
                        TOUCHINPUT ti = pInputs[i];
                        POINT input;
                        input.x = TOUCH_COORD_TO_PIXEL(ti.x);
                        input.y = TOUCH_COORD_TO_PIXEL(ti.y);
                        ScreenToClient(m_hWnd, &input);
                        CCPoint pt(input.x, input.y);
                        CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
                        if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
                        {
                            pt.x /= m_fFrameZoomFactor;
                            pt.y /= m_fFrameZoomFactor;

                            if (ti.dwFlags & TOUCHEVENTF_DOWN)
                                handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
                            else if (ti.dwFlags & TOUCHEVENTF_MOVE)
                                handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
                            else if (ti.dwFlags & TOUCHEVENTF_UP)
                                handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
                         }
                     }
                     bHandled = TRUE;
                 }
                 delete [] pInputs;
             }
             if (bHandled)
             {
                 s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam);
             }
		}
      break;
#endif /* #if(_MSC_VER >= 1600) */
    case WM_SIZE:
        switch (wParam)
        {
        case SIZE_RESTORED:
            CCApplication::sharedApplication()->applicationWillEnterForeground();
            break;
        case SIZE_MINIMIZED:
            CCApplication::sharedApplication()->applicationDidEnterBackground();
            break;
        }
        break;
    case WM_KEYDOWN:
        if (wParam == VK_F1 || wParam == VK_F2)
        {
            CCDirector* pDirector = CCDirector::sharedDirector();
            if (GetKeyState(VK_LSHIFT) < 0 ||  GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
                pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
        }
        if ( m_lpfnAccelerometerKeyHook!=NULL )
        {
            (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
        }
        break;
    case WM_KEYUP:
        if ( m_lpfnAccelerometerKeyHook!=NULL )
        {
            (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
        }
        break;
    case WM_CHAR:
        {
            if (wParam < 0x20)
            {
                if (VK_BACK == wParam)
                {
                    CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
                }
                else if (VK_RETURN == wParam)
                {
                    CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
                }
                else if (VK_TAB == wParam)
                {
                    // tab input
                }
                else if (VK_ESCAPE == wParam)
                {
                    // ESC input
                    //CCDirector::sharedDirector()->end();
                }
            }
            else if (wParam < 128)
            {
                // ascii char
                CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1);
            }
            else
            {
                char szUtf8[8] = {0};
                int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL);
                CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
            }
            if ( m_lpfnAccelerometerKeyHook!=NULL )
            {
                (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
            }
        }
        break;
    case WM_PAINT:
        PAINTSTRUCT ps;
        BeginPaint(m_hWnd, &ps);
        EndPaint(m_hWnd, &ps);
        break;

    case WM_CLOSE:
        CCDirector::sharedDirector()->end();
        break;

    case WM_DESTROY:
        destroyGL();
        PostQuitMessage(0);
        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;
}
Example #5
0
bool CCEGLView::handleEvents()
{
	bps_event_t*    event = NULL;
	mtouch_event_t  mtouch_event;
	int				touch_id = 0;
	int				val = 0;
	int				rc = 0;
	int 			domain = 0;
	char 			buf[4] = {0};

	for (;;)
	{
		rc = bps_get_event(&event, 1);
		assert(rc == BPS_SUCCESS);

		// break if no more events
		if (event == NULL)
			break;

		domain = bps_event_get_domain(event);

		if (domain == navigator_get_domain())
		{
			switch (bps_event_get_code(event))
			{
				case NAVIGATOR_SWIPE_DOWN:
					CCDirector::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
					break;

				case NAVIGATOR_EXIT:
					// exit the application
				//	release();
					end();
					break;

				case NAVIGATOR_WINDOW_INACTIVE:
					if (m_isWindowActive)
					{
						CCApplication::sharedApplication()->applicationDidEnterBackground();
						m_isWindowActive = false;
					}
					break;

				case NAVIGATOR_WINDOW_ACTIVE:
					if (!m_isWindowActive)
					{
						CCApplication::sharedApplication()->applicationWillEnterForeground();
						m_isWindowActive = true;
					}
					break;

				case NAVIGATOR_WINDOW_STATE:
				{
					switch(navigator_event_get_window_state(event))
					{
						case NAVIGATOR_WINDOW_FULLSCREEN:
							if (!m_isWindowActive)
							{
								CCApplication::sharedApplication()->applicationWillEnterForeground();
								m_isWindowActive = true;
							}
							break;
						case NAVIGATOR_WINDOW_THUMBNAIL:
							if (m_isWindowActive)
							{
								CCApplication::sharedApplication()->applicationDidEnterBackground();
								m_isWindowActive = false;
							}
							break;
					}
					break;
				}

				default:
					break;
			}
		}
		else if (domain == screen_get_domain())
		{
			m_screenEvent = screen_event_get_event(event);
			rc = screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_TYPE, &val);
			if (rc || val == SCREEN_EVENT_NONE)
				break;

			float x, y;

			switch (val)
			{
				case SCREEN_EVENT_CLOSE:
					fprintf(stderr, "SCREEN CLOSE EVENT!\n");
					break;

				case SCREEN_EVENT_MTOUCH_RELEASE:
					screen_get_mtouch_event(m_screenEvent, &mtouch_event, 0);
					touch_id = mtouch_event.contact_id;
					x = mtouch_event.x;
					y = mtouch_event.y;

					handleTouchesEnd(1, &touch_id, &x, &y);

					break;

				case SCREEN_EVENT_MTOUCH_TOUCH:
					screen_get_mtouch_event(m_screenEvent, &mtouch_event, 0);
					touch_id = mtouch_event.contact_id;
					x = mtouch_event.x;
					y = mtouch_event.y;

					handleTouchesBegin(1, &touch_id, &x, &y);

					break;

				case SCREEN_EVENT_MTOUCH_MOVE:
					screen_get_mtouch_event(m_screenEvent, &mtouch_event, 0);
					touch_id = mtouch_event.contact_id;
					x = mtouch_event.x;
					y = mtouch_event.y;

					handleTouchesMove(1, &touch_id, &x, &y);

					break;

				case SCREEN_EVENT_POINTER:
					{
						int buttons = 0;
						int pair_[2] = {0};
						float pair[2] = {0.0f};
						static bool mouse_pressed = false;

						// this is a mouse move event, it is applicable to a device with a usb mouse or simulator
						screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
						screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, pair_);
						pair[0] = (float)pair_[0];
						pair[1] = (float)pair_[1];
						if (buttons & SCREEN_LEFT_MOUSE_BUTTON)
						{
							if (mouse_pressed)
							{
								handleTouchesMove(1, &touch_id, &pair[0], &pair[1]);
							}
							else
							{
								// Left mouse button is pressed
								mouse_pressed = true;

								handleTouchesBegin(1, &touch_id, &pair[0], &pair[1]);
							}
						}
						else
						{
							if (mouse_pressed)
							{
								mouse_pressed = false;
								handleTouchesEnd(1, &touch_id, &pair[0], &pair[1]);
							}
						}
					}
					break;

				case SCREEN_EVENT_KEYBOARD:
					screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &val);
					if (val & KEY_DOWN)
					{
						screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_KEY_SYM, &val);

						if (val >= ' ' && val < '~')
						{
							buf[0] = val;
							buf[1]=  '\0';
							CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(buf, 1);
						}
						else
						{
							val = val - 0xf000;
							buf[0] = val;
							buf[1]=  '\0';

							switch (val)
							{
								case 8: // backspace
									//		CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
									CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
									break;

								default:
									CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(buf, 1);
									break;
							}
						}
					}

					break;

				default:
					break;
			}
		}
        else if (domain == sensor_get_domain())
        {
            if (bps_event_get_code(event) == SENSOR_ACCELEROMETER_READING)
            {
            	struct timespec time_struct;
            	long current_time;
                float x, y, z;

                clock_gettime(CLOCK_REALTIME, &time_struct);
                current_time = time2millis(&time_struct);

                sensor_event_get_xyz(event, &x, &y, &z);
                CCDirector::sharedDirector()->getAccelerometer()->update(current_time, -x, -y, z);
            }
        }
	}

	return true;
}
Example #6
0
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    BOOL bProcessed = FALSE;

    switch (message)
    {
    case WM_LBUTTONDOWN:
        if (m_pDelegate && MK_LBUTTON == wParam)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
            CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
            if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
            {
                m_bCaptured = true;
                SetCapture(m_hWnd);
                int id = 0;
                pt.x *= m_windowTouchScaleX;
                pt.y *= m_windowTouchScaleY;
                handleTouchesBegin(1, &id, &pt.x, &pt.y);
            }
        }
        break;

    case WM_MOUSEMOVE:
        if (MK_LBUTTON == wParam && m_bCaptured)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
            int id = 0;
            pt.x *= m_windowTouchScaleX;
            pt.y *= m_windowTouchScaleY;
            handleTouchesMove(1, &id, &pt.x, &pt.y);
        }
        break;

    case WM_LBUTTONUP:
        if (m_bCaptured)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
            int id = 0;
            pt.x *= m_windowTouchScaleX;
            pt.y *= m_windowTouchScaleY;
            handleTouchesEnd(1, &id, &pt.x, &pt.y);

            ReleaseCapture();
            m_bCaptured = false;
        }
        break;
    case WM_SIZE:
        switch (wParam)
        {
        case SIZE_RESTORED:
            CCApplication::sharedApplication()->applicationWillEnterForeground();
            break;
        case SIZE_MINIMIZED:
            CCApplication::sharedApplication()->applicationDidEnterBackground();
            break;
        }
        break;
    case WM_KEYDOWN:
        if (wParam == VK_F1 || wParam == VK_F2)
        {
            CCDirector* pDirector = CCDirector::sharedDirector();
            if (GetKeyState(VK_LSHIFT) < 0 ||  GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
                pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
        }
        if ( m_lpfnAccelerometerKeyHook!=NULL )
        {
            (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
        }
        break;
    case WM_KEYUP:
        if ( m_lpfnAccelerometerKeyHook!=NULL )
        {
            (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
        }
        break;
    case WM_CHAR:
        {
            if (wParam < 0x20)
            {
                if (VK_BACK == wParam)
                {
                    CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
                }
                else if (VK_RETURN == wParam)
                {
                    CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
                }
                else if (VK_TAB == wParam)
                {
                    // tab input
                }
                else if (VK_ESCAPE == wParam)
                {
                    // ESC input
                    //CCDirector::sharedDirector()->end();
                }
            }
            else if (wParam < 128)
            {
                // ascii char
                CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1);
            }
            else
            {
                char szUtf8[8] = {0};
                int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL);
                CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
            }
            if ( m_lpfnAccelerometerKeyHook!=NULL )
            {
                (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
            }
        }
        break;
    case WM_PAINT:
        PAINTSTRUCT ps;
        BeginPaint(m_hWnd, &ps);
        EndPaint(m_hWnd, &ps);
        break;

    case WM_CLOSE:
        CCDirector::sharedDirector()->end();
        break;

    case WM_DESTROY:
        destroyGL();
        PostQuitMessage(0);
        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;
}
Example #7
0
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    BOOL bProcessed = FALSE;
	//CCLog("wParam:%d", wParam);
    switch (message)
    {
        case WM_MOUSEWHEEL:
#if(_MSC_VER >= 1600)
		// Don't process message generated by Windows Touch
		if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */

		if (m_pDelegate)
		{
			POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
			ScreenToClient(m_hWnd, &point);
			DPoint pt(point.x, point.y);
			pt.x /= m_fFrameZoomFactor;
			pt.y /= m_fFrameZoomFactor;
			DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
			float zDelta = (short)HIWORD(wParam);
			if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp))
			{
				m_bCaptured = true;
				SetCapture(m_hWnd);

				CrossApp::CAEvent* event = new CrossApp::CAEvent();
				event->setEventType(CrossApp::EventType::middleMouseEvent);
				handleScrollWheel(pt.x, pt.y, 0, zDelta, event);
				event->release();
			}
		}
		break;

        case WM_MOUSEMOVE:
#if(_MSC_VER >= 1600)
            // Don't process message generated by Windows Touch
            if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */
            if (MK_LBUTTON == wParam && m_bCaptured)
            {
                POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
                DPoint pt(point.x, point.y);
                int id = 0;
                pt.x /= m_fFrameZoomFactor;
                pt.y /= m_fFrameZoomFactor;
                
                CrossApp::CAEvent* event = new CrossApp::CAEvent();
                event->setEventType(CrossApp::EventType::leftMouseEvent);
                handleTouchesMove(1, &id, &pt.x, &pt.y, event);
                event->release();
                
                event = new CrossApp::CAEvent();
                event->setEventType(CrossApp::EventType::movedMouseEvent);
                handleMouseMoved(pt.x, pt.y, event);
                event->release();
            }
            break;
            
	case WM_MBUTTONDOWN:
#if(_MSC_VER >= 1600)
		// Don't process message generated by Windows Touch
		if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */

		if (m_pDelegate && MK_MBUTTON == wParam)
		{
			POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
			DPoint pt(point.x, point.y);
			pt.x /= m_fFrameZoomFactor;
			pt.y /= m_fFrameZoomFactor;
			DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
			if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp))
			{
				m_bCaptured = true;
				SetCapture(m_hWnd);
				int id = 0;

				CrossApp::CAEvent* event = new CrossApp::CAEvent();
				event->setEventType(CrossApp::EventType::middleMouseEvent);
				handleOtherMouseDown(1, &id, &pt.x, &pt.y, event);
				event->release();
			}
		}
		break;

	case WM_MBUTTONUP:
#if(_MSC_VER >= 1600)
		// Don't process message generated by Windows Touch
		if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */

		if (m_pDelegate)
		{
			POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
			DPoint pt(point.x, point.y);
			pt.x /= m_fFrameZoomFactor;
			pt.y /= m_fFrameZoomFactor;
			DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
			if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp))
			{
				m_bCaptured = true;
				SetCapture(m_hWnd);
				int id = 0;

				CrossApp::CAEvent* event = new CrossApp::CAEvent();
				event->setEventType(CrossApp::EventType::middleMouseEvent);
				handleOtherMouseUp(1,&id, &pt.x, &pt.y, event);
				event->release();
			}
		}
		break;
            
    case WM_LBUTTONDOWN:
#if(_MSC_VER >= 1600)
        // Don't process message generated by Windows Touch
        if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */

        if (m_pDelegate && MK_LBUTTON == wParam)
        {
            POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
            DPoint pt(point.x, point.y);
            pt.x /= m_fFrameZoomFactor;
            pt.y /= m_fFrameZoomFactor;
            DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
            if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp))
            {
                m_bCaptured = true;
                SetCapture(m_hWnd);
                int id = 0;

				CrossApp::CAEvent* event = new CrossApp::CAEvent();
				event->setEventType(CrossApp::EventType::leftMouseEvent);
				handleTouchesBegin(1, &id, &pt.x, &pt.y, event);
				event->release();
            }
        }
        break;
            
        case WM_LBUTTONUP:
#if(_MSC_VER >= 1600)
            // Don't process message generated by Windows Touch
            if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */
            if (m_bCaptured)
            {
                POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
                DPoint pt(point.x, point.y);
                int id = 0;
                pt.x /= m_fFrameZoomFactor;
                pt.y /= m_fFrameZoomFactor;
                
                CrossApp::CAEvent* event = new CrossApp::CAEvent();
                event->setEventType(CrossApp::EventType::leftMouseEvent);
                handleTouchesEnd(1, &id, &pt.x, &pt.y, event);
                event->release();
                
                ReleaseCapture();
                m_bCaptured = false;
            }
            break;
            
        case WM_RBUTTONDOWN:
#if(_MSC_VER >= 1600)
            // Don't process message generated by Windows Touch
            if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */
            
            if (m_pDelegate && MK_RBUTTON == wParam)
            {
                POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
                DPoint pt(point.x, point.y);
                pt.x /= m_fFrameZoomFactor;
                pt.y /= m_fFrameZoomFactor;
                DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
                if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp))
                {
                    m_bCaptured = true;
                    SetCapture(m_hWnd);
                    int id = 0;
                    
                    CrossApp::CAEvent* event = new CrossApp::CAEvent();
                    event->setEventType(CrossApp::EventType::rightMouseEvent);
                    handleTouchesBegin(1, &id, &pt.x, &pt.y, event);
                    event->release();
                }
            }
            break;
            
        case WM_RBUTTONUP:
#if(_MSC_VER >= 1600)
            // Don't process message generated by Windows Touch
            if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
#endif /* #if(_MSC_VER >= 1600) */
            if (m_bCaptured)
            {
                POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
                DPoint pt(point.x, point.y);
                int id = 0;
                pt.x /= m_fFrameZoomFactor;
                pt.y /= m_fFrameZoomFactor;
                
                CrossApp::CAEvent* event = new CrossApp::CAEvent();
                event->setEventType(CrossApp::EventType::rightMouseEvent);
                handleTouchesEnd(1, &id, &pt.x, &pt.y, event);
                event->release();
                
                ReleaseCapture();
                m_bCaptured = false;
            }
            break;
            
#if(_MSC_VER >= 1600)
    case WM_TOUCH:
		{
            BOOL bHandled = FALSE;
            UINT cInputs = LOWORD(wParam);
            PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
            if (pInputs)
            {
                if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
                {
                    for (UINT i=0; i < cInputs; i++)
                    {
                        TOUCHINPUT ti = pInputs[i];
                        POINT input;
                        input.x = TOUCH_COORD_TO_PIXEL(ti.x);
                        input.y = TOUCH_COORD_TO_PIXEL(ti.y);
                        ScreenToClient(m_hWnd, &input);
                        DPoint pt(input.x, input.y);
                        DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
                        if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp))
                        {
                            pt.x /= m_fFrameZoomFactor;
                            pt.y /= m_fFrameZoomFactor;

							CrossApp::CAEvent* event = new CrossApp::CAEvent();
							event->setEventType(CrossApp::EventType::leftMouseEvent);

                            if (ti.dwFlags & TOUCHEVENTF_DOWN)
                                handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event);
                            else if (ti.dwFlags & TOUCHEVENTF_MOVE)
                                handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event);
                            else if (ti.dwFlags & TOUCHEVENTF_UP)
                                handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event);

							event->release();
                         }
                     }
                     bHandled = TRUE;
                 }
                 delete [] pInputs;
             }
             if (bHandled)
             {
                 s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam);
             }
		}
      break;
#endif /* #if(_MSC_VER >= 1600) */
	case WM_SIZE:
	{
					static int oldWidth = 0, oldHeight = 0, windowState = 0;
					switch (wParam)
					{
					case SIZE_RESTORED:
					{
										  if (windowState == 2)
										  {
											  CCApplication::sharedApplication()->applicationWillEnterForeground();
											  
										  }
										  else if (windowState == 1)
										  {
											  this->setFrameSize(oldWidth, oldHeight);
											  CCApplication::sharedApplication()->applicationDidExitFullScreen();
										  }
										  windowState = 0;
					}
						break;
					case SIZE_MAXIMIZED:
					{
										   if (windowState == 2)
										   {
											   CCApplication::sharedApplication()->applicationWillEnterForeground();
										   }
										   else if (windowState == 0)
										   {
											   oldWidth = m_obScreenSize.width * 2;
											   oldHeight = m_obScreenSize.height * 2;
											   RECT rt;
											   SystemParametersInfo(SPI_GETWORKAREA, 0, &rt, 0);    // 获得工作区大小 
											   int w = (rt.right - rt.left) * 2;
											   int h = (rt.bottom - rt.top - 24) * 2;
											   this->setFrameSize(w, h);
											   CCApplication::sharedApplication()->applicationDidToggleFullScreen();
										   }
										   windowState = 1;
					}
						break;
					case SIZE_MINIMIZED:
					{
										   CCApplication::sharedApplication()->applicationDidEnterBackground();
										   windowState = 2;
					}
						break;
					}
	}
		break;
    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_F1:
            if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
                CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
            break;
        case VK_F2:
            if (GetKeyState(VK_LSHIFT) < 0 ||  GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
                CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
            break;
        case VK_ESCAPE:
			CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
            break;
        case VK_LEFT:
            CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveBackward();
            break;
        case VK_RIGHT:
            CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveForward();
            break;
		case VK_UP:
			CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveUp();
			break;
		case VK_DOWN:
			CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveDown();
			break;

        case 'C':
        case 'X':
            if (GetKeyState(VK_CONTROL) < 0)
                {
                    if (wParam == 'C')
                    {
                    CAIMEDispatcher::sharedDispatcher()->dispatchCopyToClipboard();
                    }
                    else
                    {
                    CAIMEDispatcher::sharedDispatcher()->dispatchCutToClipboard();
                    }
            }
            break;
        case 'V':
            if (GetKeyState(VK_CONTROL) < 0)
			{
				CAIMEDispatcher::sharedDispatcher()->dispatchPasteFromClipboard();
            }
            break;
        case 'A':
            if (GetKeyState(VK_CONTROL) < 0)
            {
                CAIMEDispatcher::sharedDispatcher()->dispatchSelectAll();
            }
            break;

        default:
            break;
        }

        if ( m_lpfnAccelerometerKeyHook!=NULL )
        {
            (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
        }
        break;
    case WM_KEYUP:
        if ( m_lpfnAccelerometerKeyHook!=NULL )
        {
            (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
        }
        break;
    case WM_CHAR:
        {
            if (wParam < 0x20)
            {
                if (VK_BACK == wParam)
                {
                    CAIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
                }
                else if (VK_RETURN == wParam)
                {
                    CAIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
                }
                else if (VK_TAB == wParam)
                {
                    // tab input
                }
                else if (VK_ESCAPE == wParam)
                {
                    // ESC input
                    //CCDirector::sharedDirector()->end();
                }
            }
            else if (wParam < 128)
            {
                // ascii char
                CAIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1);
            }
            else
            {
                char szUtf8[8] = {0};
                int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL);
                CAIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
            }
            if ( m_lpfnAccelerometerKeyHook!=NULL )
            {
                (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
            }
        }
        break;
    case WM_PAINT:
        PAINTSTRUCT ps;
        BeginPaint(m_hWnd, &ps);
        EndPaint(m_hWnd, &ps);
        break;

    case WM_CLOSE:
		CAApplication::getApplication()->end();
        break;

    case WM_DESTROY:
        destroyGL();
        PostQuitMessage(0);
        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;
}