PkyMouseParam GetMouseParamWParam(WPARAM wParam)
{
#define PKY_HAVE_FLAG(arg) (( wParam & arg ) == arg)
	PkyMouseParam ret = {};
	ret.LButton = PKY_HAVE_FLAG(MK_LBUTTON);
	ret.RButton = PKY_HAVE_FLAG(MK_RBUTTON);
	ret.shift = PKY_HAVE_FLAG(MK_SHIFT);
	ret.ctrl = PKY_HAVE_FLAG(MK_CONTROL);
	ret.MButton = PKY_HAVE_FLAG(MK_MBUTTON);
	ret.X1Button = GET_XBUTTON_WPARAM(wParam) == XBUTTON1;
	ret.X2Button = GET_XBUTTON_WPARAM(wParam) == XBUTTON2;
	ret.alt = !!(::GetKeyState(VK_MENU) & 0x8000);
#undef PKY_HAVE_FLAG
	return ret;
}
Beispiel #2
0
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
#ifndef WINCE
	switch (pMsg->message) {
	case WM_XBUTTONUP:
		{
			// IntelliMouseのサイドキーボタン
			switch (GET_XBUTTON_WPARAM(pMsg->wParam)) {
			case XBUTTON1:
				// first X button
				OnBackButton();
				return TRUE;
			case XBUTTON2:
				// second X button
				OnForwardButton();
				return TRUE;
			}
		}
		break;
	}
#endif

#ifdef WINCE
	// WM Standard 端末でESC/BACKキーで前のアプリに戻ってしまうのを防ぐ
	if (pMsg->message == WM_HOTKEY) {
		if (HIWORD(pMsg->lParam )== VK_TBACK) {
			SHSendBackToFocusWindow(WM_HOTKEY, pMsg->wParam, pMsg->lParam);
			return TRUE;
		}
	}
#endif

	return CFrameWnd::PreTranslateMessage(pMsg);
}
Beispiel #3
0
	const bool	CWindow::TryGetMouseVirtualButton(const uint32 uMsg, const WPARAM wParam, Window::VirtualKey& uKeyOut){
		switch (uMsg)
		{
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_LBUTTONDBLCLK:	
			uKeyOut = Window::VirtualKey::LBUTTON;	
			return true;

		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_RBUTTONDBLCLK:
			uKeyOut = Window::VirtualKey::RBUTTON;
			return true;

		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_MBUTTONDBLCLK:
			uKeyOut = Window::VirtualKey::MBUTTON;
			return true;

		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
		case WM_XBUTTONDBLCLK:
			switch (GET_XBUTTON_WPARAM(wParam))
			{
			case 0x01:	uKeyOut = Window::VirtualKey::XBUTTON1;	return true;
			case 0x02:	uKeyOut = Window::VirtualKey::XBUTTON2;	return true;
			default:
				return false;
			}

		default:
			return false;
		}
	}
Beispiel #4
0
MouseEvent::MouseEvent(const MSG& msg) {
	POINT pt = { GET_X_LPARAM( msg.lParam ), GET_Y_LPARAM( msg.lParam ) };
	::ClientToScreen(msg.hwnd, &pt);

	pos = ScreenCoordinate(Point(pt));

	DWORD keys;
	if(msg.message == WM_XBUTTONDOWN || msg.message == WM_XBUTTONUP || msg.message == WM_XBUTTONDBLCLK) {
		keys = GET_KEYSTATE_WPARAM(msg.wParam);

		DWORD button = GET_XBUTTON_WPARAM(msg.wParam);
		ButtonPressed = (
			XBUTTON1 & button ? MouseEvent::X1 : (
				XBUTTON2 & button ? MouseEvent::X2 : MouseEvent::OTHER
			)
		);
	} else {
		keys = msg.wParam;

		// These might be an issue when porting to Windows CE since CE does only support LEFT and RIGHT (or something...)
		ButtonPressed = (
			MK_LBUTTON & keys ? MouseEvent::LEFT : (
				MK_RBUTTON & keys ? MouseEvent::RIGHT : (
					MK_MBUTTON & keys ? MouseEvent::MIDDLE : (
						MK_XBUTTON1 & keys ? MouseEvent::X1 : (
							MK_XBUTTON2 & keys ? MouseEvent::X2 : MouseEvent::OTHER
						)
					)
				)
			)
		);
	}

	isControlPressed = keys & MK_CONTROL;
	isShiftPressed = keys & MK_SHIFT;
}
Beispiel #5
0
        LRESULT CALLBACK Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        {
            Win32Window* wnd = reinterpret_cast<Win32Window*>(::GetWindowLongPtr(hWnd, GWLP_USERDATA));

            static const unsigned int MOUSEEVENTF_FROMTOUCH = 0xff515700;

            switch (message)
            {
            case WM_KEYDOWN:
                if (wnd->eventHandler)
                {
                    Key key = VirtualToXliKey(wParam);
                    if (key != KeyUnknown && wnd->eventHandler->OnKeyDown(wnd, key))
                        return 0;
                    /*
                    else
                    TranslateMessage(&msg);
                    */
                }
                break;

            case WM_KEYUP:
                if (wnd->eventHandler)
                {
                    Key key = VirtualToXliKey(wParam);
                    if (key != KeyUnknown && wnd->eventHandler->OnKeyUp(wnd, key))
                        return 0;
                }
                break;

            case WM_CHAR:
                if (wnd->eventHandler && wnd->eventHandler->OnTextInput(wnd, (String)(char)(unsigned char)(int)wParam))
                    return 0;

                break;

            case WM_MOUSEMOVE:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseMove(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))))
                    return 0;

                break;
                // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646265(v=vs.85).aspx
                /*
            case WM_MOUSELEAVE:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseMove(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))))
                    return 0;

                break;
                */
            case WM_MBUTTONDOWN:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseDown(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), MouseButtonMiddle))
                    return 0;

                break;

            case WM_MBUTTONUP:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseUp(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), MouseButtonMiddle))
                    return 0;

                break;

            case WM_LBUTTONDOWN:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseDown(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), MouseButtonLeft))
                    return 0;

                break;

            case WM_LBUTTONUP:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseUp(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), MouseButtonLeft))
                    return 0;

                break;

            case WM_RBUTTONDOWN:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseDown(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), MouseButtonRight))
                    return 0;

                break;

            case WM_RBUTTONUP:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseUp(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), MouseButtonRight))
                    return 0;

                break;

            case WM_MOUSEWHEEL:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseWheel(wnd, Vector2i(0, GET_WHEEL_DELTA_WPARAM(wParam))))
                    return 0;

                break;

            case WM_MOUSEHWHEEL:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseWheel(wnd, Vector2i(GET_WHEEL_DELTA_WPARAM(wParam), 0)))
                    return 0;

                break;

            case WM_XBUTTONDOWN:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseDown(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), GET_XBUTTON_WPARAM(wParam) == XBUTTON1 ? MouseButtonX1 : MouseButtonX2))
                    return 0;

                break;

            case WM_XBUTTONUP:
                if (wnd->eventHandler && wnd->eventHandler->OnMouseUp(wnd, Vector2i(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), GET_XBUTTON_WPARAM(wParam) == XBUTTON1 ? MouseButtonX1 : MouseButtonX2))
                    return 0;

                break;

            case WM_TOUCH:
                if (wnd->eventHandler)
                {
                    int numInputs = LOWORD(wParam);

                    if (numInputs)
                    {
                        PTOUCHINPUT touchPoints = (PTOUCHINPUT)alloca(numInputs * sizeof(TOUCHINPUT));

                        if (GetTouchInputInfo((HTOUCHINPUT)lParam, numInputs, touchPoints, sizeof(TOUCHINPUT)))
                        {
                            for (int i = 0; i < numInputs; i++)
                            {
                                TOUCHINPUT ti = touchPoints[i];

                                if (ti.dwFlags & TOUCHEVENTF_DOWN)
                                    wnd->eventHandler->OnTouchDown(wnd, Vector2((float)ti.x / 100.0f, (float)ti.y / 100.0f), ti.dwID);

                                if (ti.dwFlags & TOUCHEVENTF_MOVE)
                                    wnd->eventHandler->OnTouchMove(wnd, Vector2((float)ti.x / 100.0f, (float)ti.y / 100.0f), ti.dwID);

                                if (ti.dwFlags & TOUCHEVENTF_UP)
                                    wnd->eventHandler->OnTouchUp(wnd, Vector2((float)ti.x / 100.0f, (float)ti.y / 100.0f), ti.dwID);
                            }

                            CloseTouchInputHandle((HTOUCHINPUT)lParam);
                        }
                        else
                        {
                            Error->WriteLine("WARNING: Error reading touchpoint info.");
                        }

                        return 0;
                    }
                }
                break;

            case WM_SIZE:
                if (wnd->eventHandler)
                {
                    wnd->eventHandler->OnSizeChanged(wnd);
                    return 0;
                }

                break;

            case WM_CLOSE:
                if (wnd->eventHandler)
                {
                    if (wnd->eventHandler->OnClosing(wnd))
                        return 0;
                }

                DestroyWindow(hWnd);
                break;

            case WM_QUIT:
                wnd->closed = true;
                if (wnd->eventHandler)
                {
                    wnd->eventHandler->OnClosed(wnd);
                    return 0;
                }

                break;

            case WM_DESTROY:
                PostQuitMessage(0);

                wnd->closed = true;
                if (wnd->eventHandler)
                {
                    wnd->eventHandler->OnClosed(wnd);
                    return 0;
                }

                break;
            }

            return DefWindowProc(hWnd, message, wParam, lParam);
        }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc = ::GetDC(hWnd);

	switch (message)
	{
    case WM_XBUTTONDOWN:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            if (XBUTTON1 == GET_XBUTTON_WPARAM(wParam))
            {
                ::TextOut(hdc, 0, 0, _T("按下了鼠标扩展键(一)"), (INT)_tcslen(_T("按下了鼠标扩展键(一)")));
            }
            else if (XBUTTON2 == GET_XBUTTON_WPARAM(wParam))
            {
                ::TextOut(hdc, 0, 0, _T("按下了鼠标扩展键(二)"), (INT)_tcslen(_T("按下了鼠标扩展键(二)")));
            }
            else
            {
                ::TextOut(hdc, 0, 0, _T("按下了鼠标扩展键(未知)"), (INT)_tcslen(_T("按下了鼠标扩展键(未知)")));
            }
        }break;
    case WM_XBUTTONUP:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            if (XBUTTON1 == GET_XBUTTON_WPARAM(wParam))
            {
                ::TextOut(hdc, 0, 0, _T("松开了鼠标扩展键(一)"), (INT)_tcslen(_T("按下了鼠标扩展键(一)")));
            }
            else if (XBUTTON2 == GET_XBUTTON_WPARAM(wParam))
            {
                ::TextOut(hdc, 0, 0, _T("松开了鼠标扩展键(二)"), (INT)_tcslen(_T("按下了鼠标扩展键(二)")));
            }
            else
            {
                ::TextOut(hdc, 0, 0, _T("松开了鼠标扩展键(未知)"), (INT)_tcslen(_T("按下了鼠标扩展键(未知)")));
            }
        }break;
    case WM_LBUTTONDOWN:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            ::TextOut(hdc, 0, 0, _T("按下了鼠标左键"), (INT)_tcslen(_T("按下了鼠标左键")));
        }break;
    case WM_LBUTTONUP:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            ::TextOut(hdc, 0, 0, _T("松开了鼠标左键"), (INT)_tcslen(_T("松开了鼠标左键")));
        }break;
    case WM_RBUTTONDOWN:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            ::TextOut(hdc, 0, 0, _T("按下了鼠标右键"), (INT)_tcslen(_T("按下了鼠标右键")));
        }break;
    case WM_RBUTTONUP:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            ::TextOut(hdc, 0, 0, _T("松开了鼠标右键"), (INT)_tcslen(_T("松开了鼠标右键")));
        }break;
    case WM_MBUTTONDOWN:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            ::TextOut(hdc, 0, 0, _T("按下了鼠标中键"), (INT)_tcslen(_T("按下了鼠标中键")));
        }break;
    case WM_MBUTTONUP:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            ::TextOut(hdc, 0, 0, _T("松开了鼠标中键"), (INT)_tcslen(_T("松开了鼠标中键")));
        }break;
    case WM_MOUSEWHEEL:
        {
            ::TextOut(hdc, 0, 0, _T("                                                            "), (INT)_tcslen(_T("                                                            ")));
            short nWheel = ((signed short)(HIWORD(wParam))) / WHEEL_DELTA;
            if (nWheel > 0)
            {
                ::TextOut(hdc, 0, 0, _T("鼠标滚轮上滚"), (INT)_tcslen(_T("鼠标滚轮上滚")));
            }
            else if (nWheel < 0)
            {
                ::TextOut(hdc, 0, 0, _T("鼠标滚轮下滚"), (INT)_tcslen(_T("鼠标滚轮下滚")));
            }
            else
            {
                ::TextOut(hdc, 0, 0, _T("鼠标滚轮咋啦?"), (INT)_tcslen(_T("鼠标滚轮咋啦?")));
            }
        }break;
    case WM_PAINT:
        {
            hdc = ::BeginPaint(hWnd, &ps);
            ::EndPaint(hWnd, &ps);
        }break;
	case WM_DESTROY:
        {
            ::PostQuitMessage(0);
        }break;
	default:
        return ::DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Beispiel #7
0
static LRESULT CALLBACK muiWindowMessageProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	muiWindow *pWnd;
	if (uMsg == WM_CREATE) {
		pWnd = (muiWindow *)((LPCREATESTRUCT)lParam)->lpCreateParams;
		SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pWnd);
		pWnd->_SetWindowHandle(hwnd);
	} else {
		pWnd = (muiWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
	}

	if (pWnd) switch (uMsg) {

	case WM_PAINT: {
		PAINTSTRUCT ps;

		HDC hdc = BeginPaint(hwnd, &ps);
		if (!hdc) break;

		pWnd->OnPaint(hdc, ps.rcPaint);

		EndPaint(hwnd, &ps);
	}	return 0;

	case WM_ERASEBKGND: 
		return TRUE;

	case WM_COMMAND:
		pWnd->OnCommand(LOWORD(wParam), HIWORD(wParam), (HWND)lParam); 
		return 0;

	case WM_NOTIFY:
		return pWnd->OnNotify((int)wParam, (NMHDR *)lParam);

	case WM_MOUSEMOVE:
		pWnd->OnMouseMove({ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }, wParam);
		break;

	case WM_MOUSEHOVER:
		pWnd->OnMouseHover();
		return 0;

	case WM_MOUSELEAVE:
		pWnd->OnMouseLeave();
		break;

	case WM_SETCURSOR:
		pWnd->OnSetCursor((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
		return true;

	case WM_SETFOCUS:
		pWnd->OnSetFocus((HWND)wParam);
		return 0;

	case WM_KILLFOCUS:
		pWnd->OnLostFocus((HWND)wParam);
		return 0;

	case WM_LBUTTONDOWN:
	case WM_LBUTTONUP:
	case WM_RBUTTONDOWN:
	case WM_RBUTTONUP:
	case WM_MBUTTONDOWN:
	case WM_MBUTTONUP:
	case WM_XBUTTONDOWN:
	case WM_XBUTTONUP: {

		int nButton;
		switch (uMsg) {
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
			nButton = 0;
			break;
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
			nButton = 1;
			break;
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
			nButton = 2;
			break;
		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
			switch (GET_XBUTTON_WPARAM(wParam)) {
			case XBUTTON1:
				nButton = 3;
				break;
			case XBUTTON2:
				nButton = 4;
				break;
			default:
				return 0;
			}
			break;
		default:
			nButton = 0;
			break;
		}

		bool bDown;
		switch (uMsg) {
		case WM_LBUTTONDOWN:
		case WM_RBUTTONDOWN:
		case WM_MBUTTONDOWN:
		case WM_XBUTTONDOWN:
			bDown = true;
			break;
		default:
			bDown = false;
			break;
		}

		pWnd->OnMouseButton(nButton, bDown ? muiWindow::eButtonDown : muiWindow::eButtonUp, { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }, GET_KEYSTATE_WPARAM(wParam));
	}	break;

	case WM_LBUTTONDBLCLK:
	case WM_RBUTTONDBLCLK:
	case WM_MBUTTONDBLCLK:
	case WM_XBUTTONDBLCLK: {

		int nButton;
		switch (uMsg) {
		case WM_LBUTTONDBLCLK:
		case WM_NCLBUTTONDBLCLK:
			nButton = 0;
			break;
		case WM_RBUTTONDBLCLK:
		case WM_NCRBUTTONDBLCLK:
			nButton = 1;
			break;
		case WM_MBUTTONDBLCLK:
		case WM_NCMBUTTONDBLCLK:
			nButton = 2;
			break;
		case WM_XBUTTONDBLCLK:
		case WM_NCXBUTTONDBLCLK:
			switch (GET_XBUTTON_WPARAM(wParam)) {
			case XBUTTON1:
				nButton = 3;
				break;
			case XBUTTON2:
				nButton = 4;
				break;
			default:
				return 0;
			}
		}

		pWnd->OnMouseButton(nButton, muiWindow::eButtonDoubleClick, { GET_X_LPARAM(lParam), (int)GET_Y_LPARAM(lParam) }, GET_KEYSTATE_WPARAM(wParam));
	}	break;

	case WM_NCLBUTTONDOWN:
	case WM_NCLBUTTONUP:
	case WM_NCRBUTTONDOWN:
	case WM_NCRBUTTONUP:
	case WM_NCMBUTTONDOWN:
	case WM_NCMBUTTONUP:
	case WM_NCXBUTTONDOWN:
	case WM_NCXBUTTONUP: {

		int nButton;
		switch (uMsg) {
		case WM_NCLBUTTONDOWN:
		case WM_NCLBUTTONUP:
			nButton = 0;
			break;
		case WM_NCRBUTTONDOWN:
		case WM_NCRBUTTONUP:
			nButton = 1;
			break;
		case WM_NCMBUTTONDOWN:
		case WM_NCMBUTTONUP:
			nButton = 2;
			break;
		case WM_NCXBUTTONDOWN:
		case WM_NCXBUTTONUP:
			switch (GET_XBUTTON_WPARAM(wParam)) {
			case XBUTTON1:
				nButton = 3;
				break;
			case XBUTTON2:
				nButton = 4;
				break;
			default:
				return 0;
			}
		default:
			nButton = 0;
			break;
		}

		bool bDown;
		switch (uMsg) {
		case WM_NCLBUTTONDOWN:
		case WM_NCRBUTTONDOWN:
		case WM_NCMBUTTONDOWN:
		case WM_NCXBUTTONDOWN:
			bDown = true;
			break;
		default:
			bDown = false;
			break;
		}

		POINT pt;
		pt.x = GET_X_LPARAM(lParam);
		pt.y = GET_Y_LPARAM(lParam);
		::ScreenToClient(hwnd, &pt);

		pWnd->OnMouseButton(nButton, bDown ? muiWindow::eButtonDownNC : muiWindow::eButtonUpNC, { pt.x, pt.y }, 0);
	}	break;

	case WM_NCLBUTTONDBLCLK:
	case WM_NCRBUTTONDBLCLK:
	case WM_NCMBUTTONDBLCLK:
	case WM_NCXBUTTONDBLCLK: {

		int nButton;
		switch (uMsg) {
		case WM_NCLBUTTONDBLCLK:
			nButton = 0;
			break;
		case WM_NCRBUTTONDBLCLK:
			nButton = 1;
			break;
		case WM_NCMBUTTONDBLCLK:
			nButton = 2;
			break;
		case WM_NCXBUTTONDBLCLK:
			switch (GET_XBUTTON_WPARAM(wParam)) {
			case XBUTTON1:
				nButton = 3;
				break;
			case XBUTTON2:
				nButton = 4;
				break;
			default:
				return 0;
			}
		}

		POINT pt;
		pt.x = GET_X_LPARAM(lParam);
		pt.y = GET_Y_LPARAM(lParam);
		::ScreenToClient(hwnd, &pt);

		pWnd->OnMouseButton(nButton, muiWindow::eButtonDoubleClickNC, { pt.x, pt.y }, 0);
	}	break;

	case WM_MOUSEWHEEL:
		pWnd->OnMouseWheel((int)SHORT(HIWORD(wParam)), { (int)GET_X_LPARAM(lParam), (int)GET_Y_LPARAM(lParam) }, LOWORD(wParam));
		return 0;

	case WM_CONTEXTMENU: {
		pWnd->CloseAllPopups();

		muiCoord xy;
		xy.x = GET_X_LPARAM(lParam);
		xy.y = GET_Y_LPARAM(lParam);
		int nButton = 1;
		if ((xy.x < 0) || (xy.y < 0)) {
			muiGetCursorPos(xy);
			nButton = VK_MENU;
		}

		pWnd->OnContextMenu(xy, nButton);
	}	return 0;

	case WM_ACTIVATE:
		pWnd->OnActivate((HWND)lParam, wParam != WA_INACTIVE);
		break;

	case WM_ACTIVATEAPP:
		pWnd->OnActivateApp(wParam != FALSE);
		break;

	case WM_MOUSEACTIVATE:
		return pWnd->IsNoActivate() ? MA_NOACTIVATE : MA_ACTIVATE;

	case WM_KEYDOWN:
	case WM_SYSKEYDOWN:
		pWnd->OnKey((int)wParam, true, (lParam & (KF_REPEAT<<16)) != 0, (lParam & (KF_ALTDOWN<<16)) != 0);
		return 0;

	case WM_KEYUP:
	case WM_SYSKEYUP:
		pWnd->OnKey((int)wParam, false, false, (lParam & (KF_ALTDOWN<<16)) != 0);
		return 0;

	case WM_WINDOWPOSCHANGING:
		if (pWnd->OnPosChanging((WINDOWPOS *)lParam))
			return 0;
		break;

	case WM_WINDOWPOSCHANGED:
		if (pWnd->OnPosChanged((WINDOWPOS *)lParam))
			return 0;
		break;

	case WM_SIZING:
		if (pWnd->OnSizing(wParam, (RECT *)lParam))
			return TRUE;
		break;

	case WM_SIZE:
		pWnd->OnSize(wParam, { LOWORD(lParam), HIWORD(lParam) });
		return 0;

	case WM_MOVING:
		if (pWnd->OnMoving((RECT *)lParam))
			return TRUE;
		break;

	case WM_MOVE:
		pWnd->OnMove({ (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam) });
		return 0;

	case WM_TIMER:
		pWnd->OnTimer(wParam);
		return 0;

	case WM_HSCROLL:
		pWnd->OnScroll(false, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
		return 0;
	case WM_VSCROLL:
		pWnd->OnScroll(true, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
		return 0;

	case WM_CREATE:
		pWnd->OnCreate();
		return 0;

	case WM_DESTROY:
		pWnd->OnDestroy();
		SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)NULL);
		return 0;

	case WM_CLOSE:
		pWnd->Close();
		return 0;

	case WM_HELP:
		pWnd->OnHelp((HELPINFO *)lParam);
		return true;

	case WM_DROPFILES:
		pWnd->OnDropFiles((HANDLE)wParam);
        return 0;

	default: {
		int rv = -1234;
		pWnd->OnMessage(uMsg, wParam, lParam, rv);
		if (rv != -1234) return rv;
	}	break;	
	}

	/*if (pDwmDefWindowProc) {
		LRESULT lResult;
		if ((*pDwmDefWindowProc)(hwnd, uMsg, wParam, lParam, &lResult))
			return lResult;
	}*/

	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Beispiel #8
0
// Window callback function (handles window messages)
//
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
                                   WPARAM wParam, LPARAM lParam)
{
    _GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtrW(hWnd, 0);
    if (!window)
    {
        switch (uMsg)
        {
            case WM_NCCREATE:
            {
                CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam;
                SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
                break;
            }

            case WM_DEVICECHANGE:
            {
                if (wParam == DBT_DEVNODES_CHANGED)
                {
                    _glfwInputMonitorChange();
                    return TRUE;
                }

                break;
            }
        }

        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
    }

    switch (uMsg)
    {
        case WM_SETFOCUS:
        {
            if (window->cursorMode == GLFW_CURSOR_DISABLED)
                _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED);

            _glfwInputWindowFocus(window, GLFW_TRUE);
            return 0;
        }

        case WM_KILLFOCUS:
        {
            if (window->cursorMode == GLFW_CURSOR_DISABLED)
                _glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL);

            if (window->monitor && window->autoIconify)
                _glfwPlatformIconifyWindow(window);

            _glfwInputWindowFocus(window, GLFW_FALSE);
            return 0;
        }

        case WM_SYSCOMMAND:
        {
            switch (wParam & 0xfff0)
            {
                case SC_SCREENSAVE:
                case SC_MONITORPOWER:
                {
                    if (window->monitor)
                    {
                        // We are running in full screen mode, so disallow
                        // screen saver and screen blanking
                        return 0;
                    }
                    else
                        break;
                }

                // User trying to access application menu using ALT?
                case SC_KEYMENU:
                    return 0;
            }
            break;
        }

        case WM_CLOSE:
        {
            _glfwInputWindowCloseRequest(window);
            return 0;
        }

        case WM_CHAR:
        case WM_SYSCHAR:
        case WM_UNICHAR:
        {
            const GLFWbool plain = (uMsg != WM_SYSCHAR);

            if (uMsg == WM_UNICHAR && wParam == UNICODE_NOCHAR)
            {
                // WM_UNICHAR is not sent by Windows, but is sent by some
                // third-party input method engine
                // Returning TRUE here announces support for this message
                return TRUE;
            }

            _glfwInputChar(window, (unsigned int) wParam, getKeyMods(), plain);
            return 0;
        }

        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
        case WM_KEYUP:
        case WM_SYSKEYUP:
        {
            const int key = translateKey(wParam, lParam);
            const int scancode = (lParam >> 16) & 0x1ff;
            const int action = ((lParam >> 31) & 1) ? GLFW_RELEASE : GLFW_PRESS;
            const int mods = getKeyMods();

            if (key == _GLFW_KEY_INVALID)
                break;

            if (action == GLFW_RELEASE && wParam == VK_SHIFT)
            {
                // Release both Shift keys on Shift up event, as only one event
                // is sent even if both keys are released
                _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, action, mods);
                _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, action, mods);
            }
            else if (wParam == VK_SNAPSHOT)
            {
                // Key down is not reported for the Print Screen key
                _glfwInputKey(window, key, scancode, GLFW_PRESS, mods);
                _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
            }
            else
                _glfwInputKey(window, key, scancode, action, mods);

            break;
        }

        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
        case WM_MBUTTONDOWN:
        case WM_XBUTTONDOWN:
        case WM_LBUTTONUP:
        case WM_RBUTTONUP:
        case WM_MBUTTONUP:
        case WM_XBUTTONUP:
        {
            int button, action;

            if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP)
                button = GLFW_MOUSE_BUTTON_LEFT;
            else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP)
                button = GLFW_MOUSE_BUTTON_RIGHT;
            else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP)
                button = GLFW_MOUSE_BUTTON_MIDDLE;
            else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1)
                button = GLFW_MOUSE_BUTTON_4;
            else
                button = GLFW_MOUSE_BUTTON_5;

            if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN ||
                uMsg == WM_MBUTTONDOWN || uMsg == WM_XBUTTONDOWN)
            {
                action = GLFW_PRESS;
                SetCapture(hWnd);
            }
            else
            {
                action = GLFW_RELEASE;
                ReleaseCapture();
            }

            _glfwInputMouseClick(window, button, action, getKeyMods());

            if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP)
                return TRUE;

            return 0;
        }

        case WM_MOUSEMOVE:
        {
            const int x = GET_X_LPARAM(lParam);
            const int y = GET_Y_LPARAM(lParam);

            if (window->cursorMode == GLFW_CURSOR_DISABLED)
            {
                if (_glfw.cursorWindow != window)
                    break;

                _glfwInputCursorMotion(window,
                                       x - window->win32.cursorPosX,
                                       y - window->win32.cursorPosY);
            }
            else
                _glfwInputCursorMotion(window, x, y);

            window->win32.cursorPosX = x;
            window->win32.cursorPosY = y;

            if (!window->win32.cursorTracked)
            {
                TRACKMOUSEEVENT tme;
                ZeroMemory(&tme, sizeof(tme));
                tme.cbSize = sizeof(tme);
                tme.dwFlags = TME_LEAVE;
                tme.hwndTrack = window->win32.handle;
                TrackMouseEvent(&tme);

                window->win32.cursorTracked = GLFW_TRUE;
                _glfwInputCursorEnter(window, GLFW_TRUE);
            }

            return 0;
        }

        case WM_MOUSELEAVE:
        {
            window->win32.cursorTracked = GLFW_FALSE;
            _glfwInputCursorEnter(window, GLFW_FALSE);
            return 0;
        }

        case WM_MOUSEWHEEL:
        {
            _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
            return 0;
        }

        case WM_MOUSEHWHEEL:
        {
            // This message is only sent on Windows Vista and later
            // NOTE: The X-axis is inverted for consistency with OS X and X11.
            _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0);
            return 0;
        }

        case WM_SIZE:
        {
            if (_glfw.cursorWindow == window)
            {
                if (window->cursorMode == GLFW_CURSOR_DISABLED)
                    updateClipRect(window);
            }

            if (!window->win32.iconified && wParam == SIZE_MINIMIZED)
            {
                window->win32.iconified = GLFW_TRUE;
                if (window->monitor)
                    leaveFullscreenMode(window);

                _glfwInputWindowIconify(window, GLFW_TRUE);
            }
            else if (window->win32.iconified &&
                     (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED))
            {
                window->win32.iconified = GLFW_FALSE;
                if (window->monitor)
                    enterFullscreenMode(window);

                _glfwInputWindowIconify(window, GLFW_FALSE);
            }

            _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
            _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
            return 0;
        }

        case WM_MOVE:
        {
            if (_glfw.cursorWindow == window)
            {
                if (window->cursorMode == GLFW_CURSOR_DISABLED)
                    updateClipRect(window);
            }

            // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
            // those macros do not handle negative window positions correctly
            _glfwInputWindowPos(window,
                                GET_X_LPARAM(lParam),
                                GET_Y_LPARAM(lParam));
            return 0;
        }

        case WM_SIZING:
        {
            if (window->win32.numer == GLFW_DONT_CARE ||
                window->win32.denom == GLFW_DONT_CARE)
            {
                break;
            }

            applyAspectRatio(window, (int) wParam, (RECT*) lParam);
            return TRUE;
        }

        case WM_GETMINMAXINFO:
        {
            int xoff, yoff;
            MINMAXINFO* mmi = (MINMAXINFO*) lParam;

            getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
                              0, 0, &xoff, &yoff);

            if (window->win32.minwidth != GLFW_DONT_CARE &&
                window->win32.minheight != GLFW_DONT_CARE)
            {
                mmi->ptMinTrackSize.x = window->win32.minwidth + xoff;
                mmi->ptMinTrackSize.y = window->win32.minheight + yoff;
            }

            if (window->win32.maxwidth != GLFW_DONT_CARE &&
                window->win32.maxheight != GLFW_DONT_CARE)
            {
                mmi->ptMaxTrackSize.x = window->win32.maxwidth + xoff;
                mmi->ptMaxTrackSize.y = window->win32.maxheight + yoff;
            }

            return 0;
        }

        case WM_PAINT:
        {
            _glfwInputWindowDamage(window);
            break;
        }

        case WM_ERASEBKGND:
        {
            return TRUE;
        }

        case WM_SETCURSOR:
        {
            if (_glfw.cursorWindow == window && LOWORD(lParam) == HTCLIENT)
            {
                if (window->cursorMode == GLFW_CURSOR_HIDDEN ||
                    window->cursorMode == GLFW_CURSOR_DISABLED)
                {
                    SetCursor(NULL);
                    return TRUE;
                }
                else if (window->cursor)
                {
                    SetCursor(window->cursor->win32.handle);
                    return TRUE;
                }
            }

            break;
        }

        case WM_DPICHANGED:
        {
            RECT* rect = (RECT*) lParam;
            SetWindowPos(window->win32.handle,
                         HWND_TOP,
                         rect->left,
                         rect->top,
                         rect->right - rect->left,
                         rect->bottom - rect->top,
                         SWP_NOACTIVATE | SWP_NOZORDER);
            break;
        }

        case WM_DROPFILES:
        {
            HDROP drop = (HDROP) wParam;
            POINT pt;
            int i;

            const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0);
            char** paths = calloc(count, sizeof(char*));

            // Move the mouse to the position of the drop
            DragQueryPoint(drop, &pt);
            _glfwInputCursorMotion(window, pt.x, pt.y);

            for (i = 0;  i < count;  i++)
            {
                const UINT length = DragQueryFileW(drop, i, NULL, 0);
                WCHAR* buffer = calloc(length + 1, sizeof(WCHAR));

                DragQueryFileW(drop, i, buffer, length + 1);
                paths[i] = _glfwCreateUTF8FromWideStringWin32(buffer);

                free(buffer);
            }

            _glfwInputDrop(window, count, (const char**) paths);

            for (i = 0;  i < count;  i++)
                free(paths[i]);
            free(paths);

            DragFinish(drop);
            return 0;
        }
    }

    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
Beispiel #9
0
static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	void *data;
	DWORD which;
	uintptr_t heldButtons = (uintptr_t) wParam;
	LRESULT lResult;

	data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult);
	if (data == NULL)
		return lResult;
	switch (uMsg) {
	case WM_PAINT:
		paintArea(hwnd, data);
		return 0;
	case WM_ERASEBKGND:
		// don't draw a background; we'll do so when painting
		// this is to make things flicker-free; see http://msdn.microsoft.com/en-us/library/ms969905.aspx
		return 1;
	case WM_HSCROLL:
		scrollArea(hwnd, data, wParam, SB_HORZ);
		return 0;
	case WM_VSCROLL:
		scrollArea(hwnd, data, wParam, SB_VERT);
		return 0;
	case WM_SIZE:
		adjustAreaScrollbars(hwnd, data);
		return 0;
	case WM_ACTIVATE:
		// don't keep the double-click timer running if the user switched programs in between clicks
		areaResetClickCounter(data);
		return 0;
	case WM_MOUSEMOVE:
		areaMouseEvent(hwnd, data, 0, FALSE, heldButtons, lParam);
		return 0;
	case WM_LBUTTONDOWN:
		SetFocus(hwnd);
		areaMouseEvent(hwnd, data, 1, FALSE, heldButtons, lParam);
		return 0;
	case WM_LBUTTONUP:
		areaMouseEvent(hwnd, data, 1, TRUE, heldButtons, lParam);
		return 0;
	case WM_MBUTTONDOWN:
		SetFocus(hwnd);
		areaMouseEvent(hwnd, data, 2, FALSE, heldButtons, lParam);
		return 0;
	case WM_MBUTTONUP:
		areaMouseEvent(hwnd, data, 2, TRUE, heldButtons, lParam);
		return 0;
	case WM_RBUTTONDOWN:
		SetFocus(hwnd);
		areaMouseEvent(hwnd, data, 3, FALSE, heldButtons, lParam);
		return 0;
	case WM_RBUTTONUP:
		areaMouseEvent(hwnd, data, 3, TRUE, heldButtons, lParam);
		return 0;
	case WM_XBUTTONDOWN:
		SetFocus(hwnd);
		// values start at 1; we want them to start at 4
		which = (DWORD) GET_XBUTTON_WPARAM(wParam) + 3;
		heldButtons = (uintptr_t) GET_KEYSTATE_WPARAM(wParam);
		areaMouseEvent(hwnd, data, which, FALSE, heldButtons, lParam);
		return TRUE;		// XBUTTON messages are different!
	case WM_XBUTTONUP:
		which = (DWORD) GET_XBUTTON_WPARAM(wParam) + 3;
		heldButtons = (uintptr_t) GET_KEYSTATE_WPARAM(wParam);
		areaMouseEvent(hwnd, data, which, TRUE, heldButtons, lParam);
		return TRUE;
	case msgAreaKeyDown:
		return (LRESULT) areaKeyEvent(data, FALSE, wParam, lParam);
	case msgAreaKeyUp:
		return (LRESULT) areaKeyEvent(data, TRUE, wParam, lParam);
	case msgAreaSizeChanged:
		adjustAreaScrollbars(hwnd, data);
		repaintArea(hwnd, NULL);		// this calls for an update
		return 0;
	case msgAreaGetScroll:
		getScrollPos(hwnd, (int *) wParam, (int *) lParam);
		return 0;
	case msgAreaRepaint:
		repaintArea(hwnd, (RECT *) lParam);
		return 0;
	case msgAreaRepaintAll:
		repaintArea(hwnd, NULL);
		return 0;
	default:
		return DefWindowProcW(hwnd, uMsg, wParam, lParam);
	}
	xmissedmsg("Area", "areaWndProc()", uMsg);
	return 0;			// unreached
}
Beispiel #10
0
LRESULT CALLBACK EventHandler::_wndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
                                        LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_SHOWWINDOW:
    {
        SizeEvent sizeEvent;
        _getWindowSize(hWnd, sizeEvent);

        EventType type = wParam == TRUE ? EVENT_WINDOW_SHOW : EVENT_WINDOW_HIDE;

        if (_window->processEvent(type, sizeEvent))
            return TRUE;
        break;
    }

    case WM_CREATE:
    case WM_SIZE:
    case WM_MOVE:
    case WM_WINDOWPOSCHANGED:
    {
        SizeEvent sizeEvent;
        _getWindowSize(hWnd, sizeEvent);
        const bool hasArea = (sizeEvent.w > 0 && sizeEvent.h > 0);
        const PixelViewport& pvp = _window->getPixelViewport();

        // No show/hide events on Win32?: Emulate.
        EventType type;
        if (!hasArea && pvp.hasArea())
            type = EVENT_WINDOW_HIDE;
        else if (hasArea && !pvp.hasArea())
            type = EVENT_WINDOW_SHOW;
        else
            type = EVENT_WINDOW_RESIZE;

        if (_window->processEvent(type, sizeEvent))
            return TRUE;
        break;
    }

    case WM_CLOSE:
    case WM_DESTROY:
    {
        if (_window->processEvent(EVENT_WINDOW_CLOSE))
            return TRUE;
        break;
    }

    case WM_PAINT:
    {
        if (GetUpdateRect(hWnd, 0, false) == 0) // No 'expose'
            return DefWindowProc(hWnd, uMsg, wParam, lParam);

        if (_window->processEvent(EVENT_WINDOW_EXPOSE))
            return TRUE;
        break;
    }

    case WM_MOUSEMOVE:
    {
        _syncButtonState(wParam);

        PointerEvent pointerEvent;
        pointerEvent.x = GET_X_LPARAM(lParam);
        pointerEvent.y = GET_Y_LPARAM(lParam);
        pointerEvent.buttons = _buttonState;

        _computePointerDelta(EVENT_WINDOW_POINTER_MOTION, pointerEvent);
        if (_window->processEvent(EVENT_WINDOW_POINTER_MOTION, pointerEvent))
            return TRUE;
        break;
    }

    case WM_LBUTTONDOWN:
        if (_mouseButtonPress(PTR_BUTTON1, lParam))
            return TRUE;
        break;

    case WM_RBUTTONDOWN:
        if (_mouseButtonPress(PTR_BUTTON2, lParam))
            return TRUE;
        break;

    case WM_MBUTTONDOWN:
        if (_mouseButtonPress(PTR_BUTTON3, lParam))
            return TRUE;
        break;

    case WM_XBUTTONDOWN:
    {
        const PointerButton button =
            GET_XBUTTON_WPARAM(wParam) & XBUTTON1 ? PTR_BUTTON4 : PTR_BUTTON5;
        _syncButtonState(GET_XBUTTON_WPARAM(wParam));
        if (_mouseButtonPress(button, lParam))
            return TRUE;
        break;
    }

    case WM_LBUTTONUP:
        if (_mouseButtonRelease(PTR_BUTTON1, lParam))
            return TRUE;
        break;

    case WM_RBUTTONUP:
        if (_mouseButtonRelease(PTR_BUTTON2, lParam))
            return TRUE;
        break;

    case WM_MBUTTONUP:
        if (_mouseButtonRelease(PTR_BUTTON3, lParam))
            return TRUE;
        break;

    case WM_XBUTTONUP:
    {
        const PointerButton button =
            GET_XBUTTON_WPARAM(wParam) & XBUTTON1 ? PTR_BUTTON4 : PTR_BUTTON5;
        _syncButtonState(GET_XBUTTON_WPARAM(wParam));
        if (_mouseButtonRelease(button, lParam))
            return TRUE;
        break;
    }

    case WM_MOUSEWHEEL:
    {
        PointerEvent pointerEvent;
        pointerEvent.x = GET_X_LPARAM(lParam);
        pointerEvent.y = GET_Y_LPARAM(lParam);
        pointerEvent.buttons = _buttonState;
        pointerEvent.modifiers = _getKeyModifiers();
        pointerEvent.yAxis = _getWheelDelta(wParam);
        pointerEvent.button = PTR_BUTTON_NONE;
        _computePointerDelta(EVENT_WINDOW_POINTER_WHEEL, pointerEvent);
        if (_window->processEvent(EVENT_WINDOW_POINTER_WHEEL, pointerEvent))
            return TRUE;
        break;
    }

#ifdef WM_MOUSEHWHEEL // only available on vista or later
    case WM_MOUSEHWHEEL:
    {
        PointerEvent pointerEvent;
        pointerEvent.x = GET_X_LPARAM(lParam);
        pointerEvent.y = GET_Y_LPARAM(lParam);
        pointerEvent.buttons = _buttonState;
        pointerEvent.modifiers = _getKeyModifiers();
        pointerEvent.xAxis = _getWheelDelta(wParam);
        pointerEvent.button = PTR_BUTTON_NONE;
        _computePointerDelta(EVENT_WINDOW_POINTER_WHEEL, pointerEvent);
        if (_window->processEvent(EVENT_WINDOW_POINTER_WHEEL, pointerEvent))
            return TRUE;
        break;
    }
#endif

    case WM_SYSKEYDOWN:
    case WM_KEYDOWN:
    {
        KeyEvent keyEvent;
        keyEvent.key = _getKey(lParam, wParam);
        keyEvent.modifiers = _getKeyModifiers();
        if (_window->processEvent(EVENT_KEY_PRESS, keyEvent))
            return TRUE;
        break;
    }

    case WM_SYSKEYUP:
    case WM_KEYUP:
    {
        KeyEvent keyEvent;
        keyEvent.key = _getKey(lParam, wParam);
        keyEvent.modifiers = _getKeyModifiers();
        if (_window->processEvent(EVENT_KEY_RELEASE, keyEvent))
            return TRUE;
        break;
    }

    case WM_SYSCOMMAND:
        switch (wParam)
        {
        case SC_MONITORPOWER:
        case SC_SCREENSAVE:
            if (lParam >= 0) // request off
            {
                if (_window->processEvent(EVENT_WINDOW_SCREENSAVER))
                    return TRUE;
                break;
            }
        // else no break; fall through
        default:
            _window->processEvent(EVENT_UNKNOWN);
            LBVERB << "Unhandled system command 0x" << std::hex << wParam
                   << std::dec << std::endl;
            break;
        }
        break;
#ifdef EQUALIZER_USE_MAGELLAN
    case WM_INPUT:
        _magellanEventHandler(lParam);
        break;
#endif

    default:
        _window->processEvent(EVENT_UNKNOWN);
        LBVERB << "Unhandled message 0x" << std::hex << uMsg << std::dec
               << std::endl;
        break;
    }

    return CallWindowProc(_prevWndProc, hWnd, uMsg, wParam, lParam);
}
Beispiel #11
0
LRESULT __stdcall Hooks::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch( uMsg )
	{
		case WM_LBUTTONDOWN:
			G::PressedKeys[ VK_LBUTTON ] = true;
			break;
		case WM_LBUTTONUP:
			G::PressedKeys[ VK_LBUTTON ] = false;
			break;
		case WM_RBUTTONDOWN:
			G::PressedKeys[ VK_RBUTTON ] = true;
			break;
		case WM_RBUTTONUP:
			G::PressedKeys[ VK_RBUTTON ] = false;
			break;
		case WM_MBUTTONDOWN:
			G::PressedKeys[ VK_MBUTTON ] = true;
			break;
		case WM_MBUTTONUP:
			G::PressedKeys[ VK_MBUTTON ] = false;
			break;
		case WM_XBUTTONDOWN:
		{
			UINT button = GET_XBUTTON_WPARAM( wParam );
			if( button == XBUTTON1 )
			{
				G::PressedKeys[ VK_XBUTTON1 ] = true;
			}
			else if( button == XBUTTON2 )
			{
				G::PressedKeys[ VK_XBUTTON2 ] = true;
			}
			break;
		}
		case WM_XBUTTONUP:
		{
			UINT button = GET_XBUTTON_WPARAM( wParam );
			if( button == XBUTTON1 )
			{
				G::PressedKeys[ VK_XBUTTON1 ] = false;
			}
			else if( button == XBUTTON2 )
			{
				G::PressedKeys[ VK_XBUTTON2 ] = false;
			}
			break;
		}
		case WM_KEYDOWN:
			G::PressedKeys[ wParam ] = true;
			break;
		case WM_KEYUP:
			G::PressedKeys[ wParam ] = false;
			break;
		case WM_SYSKEYDOWN:
			if (wParam == VK_MENU)
				G::PressedKeys[VK_MENU] = true;
			break;
		case WM_SYSKEYUP:
			if (wParam == VK_MENU)
				G::PressedKeys[VK_MENU] = false;
			break;
		default: break;
	}

	OpenMenu();

	if( G::d3dinit && Vars.Menu.Opened && ImGui_ImplDX9_WndProcHandler( hWnd, uMsg, wParam, lParam ) )
		return true;

	return CallWindowProc( oldWindowProc, hWnd, uMsg, wParam, lParam );
}
Beispiel #12
0
// Process Win32 mouse/keyboard inputs.
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds.
// PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag.
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    if (ImGui::GetCurrentContext() == NULL)
        return 0;

    ImGuiIO& io = ImGui::GetIO();
    switch (msg)
    {
    case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
    case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK:
    case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK:
    case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK:
    {
        int button = 0;
        if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) { button = 0; }
        if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; }
        if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; }
        if (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONDBLCLK) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; }
        if (!ImGui::IsAnyMouseDown() && ::GetCapture() == NULL)
            ::SetCapture(hwnd);
        io.MouseDown[button] = true;
        return 0;
    }
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
    case WM_MBUTTONUP:
    case WM_XBUTTONUP:
    {
        int button = 0;
        if (msg == WM_LBUTTONUP) { button = 0; }
        if (msg == WM_RBUTTONUP) { button = 1; }
        if (msg == WM_MBUTTONUP) { button = 2; }
        if (msg == WM_XBUTTONUP) { button = (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) ? 3 : 4; }
        io.MouseDown[button] = false;
        if (!ImGui::IsAnyMouseDown() && ::GetCapture() == hwnd)
            ::ReleaseCapture();
        return 0;
    }
    case WM_MOUSEWHEEL:
        io.MouseWheel += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
        return 0;
    case WM_MOUSEHWHEEL:
        io.MouseWheelH += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
        return 0;
    case WM_KEYDOWN:
    case WM_SYSKEYDOWN:
        if (wParam < 256)
            io.KeysDown[wParam] = 1;
        return 0;
    case WM_KEYUP:
    case WM_SYSKEYUP:
        if (wParam < 256)
            io.KeysDown[wParam] = 0;
        return 0;
    case WM_CHAR:
        // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
        if (wParam > 0 && wParam < 0x10000)
            io.AddInputCharacter((unsigned short)wParam);
        return 0;
    case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor())
            return 1;
        return 0;
    case WM_DEVICECHANGE:
        if ((UINT)wParam == DBT_DEVNODES_CHANGED)
            g_WantUpdateHasGamepad = true;
        return 0;
    }
    return 0;
}
Beispiel #13
0
LRESULT CALLBACK EventHandler::_wndProc( HWND hWnd, UINT uMsg, WPARAM wParam,
					 LPARAM lParam )
{
    WindowEvent event;
    event.uMsg   = uMsg;
    event.wParam = wParam;
    event.lParam = lParam;
    event.time = _window->getConfig()->getTime();

    eq::Window* const window = _window->getWindow();

    LONG result = 0;
    switch( uMsg )
    {
        case WM_SHOWWINDOW:
            if( wParam == TRUE )
                event.type = Event::WINDOW_SHOW;
            else
                event.type = Event::WINDOW_HIDE;

            _getWindowSize( hWnd, event.resize );
            break;

        case WM_CREATE:
        case WM_SIZE:
        case WM_MOVE:
        case WM_WINDOWPOSCHANGED:
        {
            _getWindowSize( hWnd, event.resize );
            const bool hasArea = (event.resize.w >0 && event.resize.h > 0);
            const PixelViewport& pvp = window->getPixelViewport();

            // No show/hide events on Win32?: Emulate.
            if( !hasArea && pvp.hasArea( ))
                event.type = Event::WINDOW_HIDE;
            else if( hasArea && !pvp.hasArea( ))
                event.type = Event::WINDOW_SHOW;
            else
                event.type = Event::WINDOW_RESIZE;
            break;
        }

        case WM_CLOSE:
        case WM_DESTROY:
            event.type = Event::WINDOW_CLOSE;
            break;

        case WM_PAINT:
        {
            if( GetUpdateRect( hWnd, 0, false ) == 0 ) // No 'expose'
                return DefWindowProc( hWnd, uMsg, wParam, lParam );

            event.type = Event::WINDOW_EXPOSE;
            break;
        }

        case WM_MOUSEMOVE:
        {
            _syncButtonState( wParam );

            event.type = Event::WINDOW_POINTER_MOTION;
            event.pointerMotion.x = GET_X_LPARAM( lParam );
            event.pointerMotion.y = GET_Y_LPARAM( lParam );
            event.pointerMotion.buttons = _buttonState;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;
        }

        case WM_LBUTTONDOWN:
            _buttonState |= PTR_BUTTON1;
            event.type = Event::WINDOW_POINTER_BUTTON_PRESS;
            event.pointerButtonPress.x       = GET_X_LPARAM( lParam );
            event.pointerButtonPress.y       = GET_Y_LPARAM( lParam );
            event.pointerButtonPress.buttons = _buttonState;
            event.pointerButtonPress.button  = PTR_BUTTON1;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;

        case WM_MBUTTONDOWN:
            _buttonState |= PTR_BUTTON2;
            event.type = Event::WINDOW_POINTER_BUTTON_PRESS;
            event.pointerButtonPress.x       = GET_X_LPARAM( lParam );
            event.pointerButtonPress.y       = GET_Y_LPARAM( lParam );
            event.pointerButtonPress.buttons = _buttonState;
            event.pointerButtonPress.button  = PTR_BUTTON2;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;

        case WM_RBUTTONDOWN:
            _buttonState |= PTR_BUTTON3;
            event.type = Event::WINDOW_POINTER_BUTTON_PRESS;
            event.pointerButtonPress.x       = GET_X_LPARAM( lParam );
            event.pointerButtonPress.y       = GET_Y_LPARAM( lParam );
            event.pointerButtonPress.buttons = _buttonState;
            event.pointerButtonPress.button  = PTR_BUTTON3;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;

        case WM_XBUTTONDOWN:
            event.type = Event::WINDOW_POINTER_BUTTON_PRESS;
            event.pointerButtonPress.x       = GET_X_LPARAM( lParam );
            event.pointerButtonPress.y       = GET_Y_LPARAM( lParam );

            if( GET_XBUTTON_WPARAM( wParam ) & XBUTTON1 )
                event.pointerButtonRelease.button = PTR_BUTTON4;
            else
                event.pointerButtonRelease.button = PTR_BUTTON5;

            _buttonState |= event.pointerButtonPress.button;
            _syncButtonState( GET_KEYSTATE_WPARAM( wParam ));
            event.pointerButtonPress.buttons = _buttonState;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            result = TRUE;
            break;

        case WM_LBUTTONUP:
            _buttonState &= ~PTR_BUTTON1;
            event.type = Event::WINDOW_POINTER_BUTTON_RELEASE;
            event.pointerButtonRelease.x       = GET_X_LPARAM( lParam );
            event.pointerButtonRelease.y       = GET_Y_LPARAM( lParam );
            event.pointerButtonRelease.buttons = _buttonState;
            event.pointerButtonRelease.button  = PTR_BUTTON1;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;

        case WM_MBUTTONUP:
            _buttonState &= ~PTR_BUTTON2;
            event.type = Event::WINDOW_POINTER_BUTTON_RELEASE;
            event.pointerButtonRelease.x       = GET_X_LPARAM( lParam );
            event.pointerButtonRelease.y       = GET_Y_LPARAM( lParam );
            event.pointerButtonRelease.buttons = _buttonState;
            event.pointerButtonRelease.button  = PTR_BUTTON2;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;

        case WM_RBUTTONUP:
            _buttonState &= ~PTR_BUTTON3;
            event.type = Event::WINDOW_POINTER_BUTTON_RELEASE;
            event.pointerButtonRelease.x       = GET_X_LPARAM( lParam );
            event.pointerButtonRelease.y       = GET_Y_LPARAM( lParam );
            event.pointerButtonRelease.buttons = _buttonState;
            event.pointerButtonRelease.button  = PTR_BUTTON3;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            break;

        case WM_XBUTTONUP:
            event.type = Event::WINDOW_POINTER_BUTTON_RELEASE;
            event.pointerButtonRelease.x       = GET_X_LPARAM( lParam );
            event.pointerButtonRelease.y       = GET_Y_LPARAM( lParam );

            if( GET_XBUTTON_WPARAM( wParam ) & XBUTTON1 )
                event.pointerButtonRelease.button = PTR_BUTTON4;
            else
                event.pointerButtonRelease.button = PTR_BUTTON5;

            _buttonState &= ~event.pointerButtonRelease.button;
            _syncButtonState( GET_KEYSTATE_WPARAM( wParam ));
            event.pointerButtonRelease.buttons =_buttonState;

            _computePointerDelta( window, event );
            _getRenderContext( window, event );
            result = TRUE;
            break;

        case WM_MOUSEWHEEL:
            event.type = Event::WINDOW_POINTER_WHEEL;
            event.pointerWheel.x     = GET_X_LPARAM( lParam );
            event.pointerWheel.y     = GET_Y_LPARAM( lParam );
            event.pointerWheel.buttons = _buttonState;
            event.pointerWheel.xAxis = _getWheelDelta( wParam );
            break;

#ifdef WM_MOUSEHWHEEL // only available on vista or later
        case WM_MOUSEHWHEEL:
            event.type = Event::WINDOW_POINTER_WHEEL;
            event.pointerWheel.x     = GET_X_LPARAM( lParam );
            event.pointerWheel.y     = GET_Y_LPARAM( lParam );
            event.pointerWheel.buttons = _buttonState;
            event.pointerWheel.yAxis = _getWheelDelta( wParam );
            break;
#endif

        case WM_SYSKEYDOWN:
        case WM_KEYDOWN:
            event.type = Event::KEY_PRESS;
            event.keyPress.key = _getKey( lParam, wParam );
            break;

        case WM_SYSKEYUP:
        case WM_KEYUP:
            event.type = Event::KEY_RELEASE;
            event.keyRelease.key = _getKey( lParam, wParam );
            break;

        case WM_SYSCOMMAND:
            switch( wParam )
            {
                case SC_MONITORPOWER:
                case SC_SCREENSAVE:
                    if( lParam >= 0 ) // request off
                    {
                        event.type = Event::WINDOW_SCREENSAVER;
                        break;
                    }
                    // else no break; fall through
                default:
                    event.type = Event::UNKNOWN;
                    LBVERB << "Unhandled system command 0x" << std::hex
                           << wParam  << std::dec << std::endl;
                    break;
            }
            break;
#ifdef EQUALIZER_USE_MAGELLAN
        case WM_INPUT:
            _magellanEventHandler( lParam );
            break;
#endif
        default:
            event.type = Event::UNKNOWN;
            LBVERB << "Unhandled message 0x" << std::hex << uMsg << std::dec
                   << std::endl;
            break;
    }
    
    LBASSERT( window->getID() != 0 );
    event.originator = window->getID();
    event.serial = window->getSerial();

    if( _window->processEvent( event ))
        return result;

    return CallWindowProc( _prevWndProc, hWnd, uMsg, wParam, lParam );
}