Esempio n. 1
0
bool ff::ViewWindow::Deactivate(bool hide)
{
	assertRetVal(IsValid(), true);

	if (_active)
	{
		_active = false;
#if !METRO_APP
		if (hide)
		{
			SetWindowPos(Handle(), HWND_TOP, RectInt(0, 0, 0, 0), SWP_HIDEWINDOW | SWP_NOOWNERZORDER);
		}

		if (_mainWindow != nullptr)
		{
			HWND child = GetChildWindow();
			if (child && ff::IsAncestor(child, Handle()))
			{
				_mainWindow->HideSharedViewTarget();
			}
		}
#endif
		OnDeactivated();
	}

	return true;
}
void RunableThreads::Join()
{
    while (!_hThreads.empty()) 
    {
        std::set<HANDLE> threads_left;

        for (std::set<HANDLE>::iterator cur_thread = _hThreads.begin(), last = _hThreads.end(); cur_thread != last; ++cur_thread)
        {
            DWORD rc = ::WaitForSingleObject(*cur_thread, THREAD_TIMEOUT_IN_MSEC);
            if (rc == WAIT_OBJECT_0) 
            {
                ::CloseHandle(*cur_thread); // necessary with _beginthreadex
            }
            else if (rc == WAIT_TIMEOUT) 
            {
                if (_activated)
                    threads_left.insert(*cur_thread); // wait again
                else
                    ::CloseHandle(*cur_thread);
            }
            else 
            {
                // this shouldn't happen... try to close the handle and hope
                // for the best!
                ::CloseHandle(*cur_thread); // necessary with _beginthreadex
            }
        }
        std::swap(threads_left, _hThreads);
    }

    OnDeactivated();
}
Esempio n. 3
0
	LRESULT WndProcFunc::WndProc(HWND wnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		auto app = Application::InstancePtr();

		POINT pt;
		RECT rt;
		int key = 0;
		Vec2I size, pos;
		GetCursorPos(&pt);
		ScreenToClient(wnd, &pt);
		Vec2F cursorPos = Vec2F((float)pt.x, (float)-pt.y);

		if (app->mRender)
			cursorPos -= Vec2F(Math::Round(app->mRender->mResolution.x*0.5f),
							   Math::Round(-app->mRender->mResolution.y*0.5f));

		float wheelDelta;

		if (app->IsReady())
		{
			switch (uMsg)
			{
			case WM_LBUTTONDOWN:
			SetCapture(app->mHWnd);
			app->mInput->OnCursorPressed(cursorPos);
			break;

			case WM_LBUTTONUP:
			app->mInput->OnCursorReleased();
			ReleaseCapture();
			break;

			case WM_RBUTTONDOWN:
			SetCapture(app->mHWnd);
			app->mInput->OnAltCursorPressed(cursorPos);
			break;

			case WM_RBUTTONUP:
			app->mInput->OnAltCursorReleased();
			ReleaseCapture();
			break;

			case WM_MBUTTONDOWN:
			SetCapture(app->mHWnd);
			app->mInput->OnAlt2CursorPressed(cursorPos);
			break;

			case WM_MBUTTONUP:
			app->mInput->OnAlt2CursorReleased();
			ReleaseCapture();
			break;

			case WM_KEYDOWN:
			key = (int)wParam;
			app->mInput->OnKeyPressed(key);
			break;

			case WM_KEYUP:
			app->mInput->OnKeyReleased((int)wParam);
			break;

			case WM_MOUSEMOVE:
			app->mInput->OnCursorMoved(cursorPos, 0);
			app->mInput->GetCursor()->delta -= app->mCursorCorrectionDelta;
			app->mCursorCorrectionDelta = Vec2F();
			break;

			case WM_MOUSEWHEEL:
			wheelDelta = GET_WHEEL_DELTA_WPARAM(wParam);
			app->mInput->OnMouseWheel(wheelDelta);
			break;

			case WM_ACTIVATEAPP:
			case WM_ENABLE:
			if (wParam == TRUE)
			{
				app->mActive = true;
				app->OnActivated();
				app->onActivated.Invoke();
				o2Events.OnApplicationActivated();
			}
			else
			{
				app->mActive = false;
				app->OnDeactivated();
				app->onDeactivated.Invoke();
				o2Events.OnApplicationDeactivated();
			}
			break;

			case WM_SIZE:
			GetWindowRect(app->mHWnd, &rt);
			size.x = rt.right - rt.left; size.y = rt.bottom - rt.top;

			if (size.x > 0 && size.y > 0 && size != app->mWindowedSize)
			{
				app->mWindowedSize = size;
				app->mRender->OnFrameResized();
				app->onResizing.Invoke();
				app->OnResizing();
				o2Events.OnApplicationSized();
			}
			app->ProcessFrame();

			break;

			case WM_MOVE:
			GetWindowRect(app->mHWnd, &rt);
			pos.x = rt.left; pos.y = rt.top;

			if (pos.x < 10000 && pos.y < 10000 && pos != app->mWindowedPos)
			{
				app->mWindowedPos = pos;
				app->OnMoved();
				app->onMoving.Invoke();
			}
			break;

			case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
			break;
			}
		}

		return DefWindowProc(wnd, uMsg, wParam, lParam);
	}
Esempio n. 4
0
LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	static bool s_in_sizemove = false;
	static bool s_in_suspend = false;
	static bool s_minimized = false;

	auto game = reinterpret_cast<Game*>(GetWindowLongPtr(window, GWLP_USERDATA));

	// process messages accordingly
	switch (message)
	{
		case WM_PAINT:
			hdc = BeginPaint(window, &ps);
			EndPaint(window, &ps);
			break;

		case WM_SIZE:
			if (wParam == SIZE_MINIMIZED)
			{
				if (!s_minimized)
				{
					s_minimized = true;
					if (!s_in_suspend && game)
						game->OnSuspending();
					s_in_suspend = true;
				}
			}
			else if (s_minimized)
			{
				s_minimized = false;
				if (s_in_suspend && game)
					game->OnResuming();
				s_in_suspend = false;
			}
			else if (!s_in_sizemove && game)
			{
				game->OnWindowSizeChanged(LOWORD(lParam), HIWORD(lParam));
			}
			break;

		case WM_ENTERSIZEMOVE:
			s_in_sizemove = true;
			break;

		case WM_EXITSIZEMOVE:
			s_in_sizemove = false;
			if (game)
			{
				GetClientRect(window, &rc);

				game->OnWindowSizeChanged(rc.right - rc.left, rc.bottom - rc.top);
			}
			break;

		case WM_GETMINMAXINFO:
		{
			auto info = reinterpret_cast<MINMAXINFO*>(lParam);
			info->ptMinTrackSize.x = 1920;
			info->ptMinTrackSize.y = 1080;
		}
		break;

		case WM_ACTIVATEAPP:
			if (game)
			{
				if (wParam)
				{
					game->OnActivated();
					game->MouseProcess(message, wParam, lParam);
					game->KeyboardProcess(message, wParam, lParam);
				}
				else
				{
					game->OnDeactivated();
				}
			}
			break;

		case WM_POWERBROADCAST:
			switch (wParam)
			{
				case PBT_APMQUERYSUSPEND:
					if (!s_in_suspend && game)
						game->OnSuspending();
					s_in_suspend = true;
					return true;

				case PBT_APMRESUMESUSPEND:
					if (!s_minimized)
					{
						if (s_in_suspend && game)
							game->OnResuming();
						s_in_suspend = false;
					}
					return true;
			}
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		case WM_INPUT:
		case WM_MOUSEMOVE:
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_MOUSEWHEEL:
		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
		case WM_MOUSEHOVER:
			game->MouseProcess(message, wParam, lParam);
			break;

		case WM_KEYDOWN:
		case WM_SYSKEYDOWN:
		case WM_KEYUP:
		case WM_SYSKEYUP:
			game->KeyboardProcess(message, wParam, lParam);
			break;

		case WM_CHAR:
			game->CharactersInput(wParam);
			break;
		}
		return DefWindowProc(window, message, wParam, lParam);
}