removed unused files
This commit is contained in:
Родитель
f027610a56
Коммит
4d84b98cb2
|
@ -1,377 +0,0 @@
|
|||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "SampleRemoteWindowUWP.h"
|
||||
|
||||
#include "Common\DbgLog.h"
|
||||
#include "Common\Speech.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
#include <HolographicAppRemoting/Streamer.h>
|
||||
|
||||
#include <windows.graphics.directx.direct3d11.interop.h>
|
||||
|
||||
#include <winrt/Windows.ApplicationModel.Activation.h>
|
||||
#include <winrt/Windows.UI.Core.h>
|
||||
#include <winrt/Windows.ui.ViewManagement.h>
|
||||
|
||||
#define INITIAL_WINDOW_WIDTH 1280
|
||||
#define INITIAL_WINDOW_HEIGHT 720
|
||||
|
||||
#define TITLE_SEPARATOR L" | "
|
||||
|
||||
using namespace winrt::Windows::ApplicationModel;
|
||||
using namespace winrt::Windows::ApplicationModel::Activation;
|
||||
using namespace winrt::Windows::ApplicationModel::Core;
|
||||
using namespace winrt::Windows::Graphics::Display;
|
||||
using namespace winrt::Microsoft::Holographic::AppRemoting;
|
||||
using namespace winrt::Windows::UI::Core;
|
||||
using namespace winrt::Windows::UI::ViewManagement;
|
||||
|
||||
// The main function is only used to initialize our IFrameworkView class.
|
||||
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
|
||||
{
|
||||
winrt::init_apartment();
|
||||
CoreApplication::Run(winrt::make<SampleRemoteWindowUWPView>());
|
||||
}
|
||||
|
||||
SampleRemoteWindowUWP::SampleRemoteWindowUWP()
|
||||
{
|
||||
ApplicationView::PreferredLaunchViewSize(winrt::Windows::Foundation::Size(INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT));
|
||||
}
|
||||
|
||||
// The first method called when the IFrameworkView is being created.
|
||||
void SampleRemoteWindowUWP::Initialize(const CoreApplicationView& applicationView)
|
||||
{
|
||||
CoreApplication::Suspending({this, &SampleRemoteWindowUWP::OnSuspending});
|
||||
CoreApplication::Resuming({this, &SampleRemoteWindowUWP::OnResuming});
|
||||
|
||||
applicationView.Activated({this, &SampleRemoteWindowUWP::OnViewActivated});
|
||||
|
||||
m_main = std::make_shared<SampleRemoteMain>(weak_from_this());
|
||||
}
|
||||
|
||||
// Called when the CoreWindow object is created (or re-created).
|
||||
void SampleRemoteWindowUWP::SetWindow(const CoreWindow& window)
|
||||
{
|
||||
m_window = window;
|
||||
|
||||
window.SizeChanged({this, &SampleRemoteWindowUWP::OnWindowSizeChanged});
|
||||
window.VisibilityChanged({this, &SampleRemoteWindowUWP::OnVisibilityChanged});
|
||||
window.Closed({this, &SampleRemoteWindowUWP::OnWindowClosed});
|
||||
window.KeyDown({this, &SampleRemoteWindowUWP::OnKeyDown});
|
||||
}
|
||||
|
||||
// Initializes scene resources, or loads a previously saved app state.
|
||||
void SampleRemoteWindowUWP::Load(const winrt::hstring& entryPoint)
|
||||
{
|
||||
}
|
||||
|
||||
// This method is called after the window becomes active.
|
||||
void SampleRemoteWindowUWP::Run()
|
||||
{
|
||||
CoreWindow window = CoreWindow::GetForCurrentThread();
|
||||
window.Activate();
|
||||
|
||||
while (!m_windowClosed)
|
||||
{
|
||||
if (m_windowVisible)
|
||||
{
|
||||
CoreWindow::GetForCurrentThread().Dispatcher().ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
||||
|
||||
if (m_main)
|
||||
{
|
||||
if (const HolographicFrame& holographicFrame = m_main->Update())
|
||||
{
|
||||
m_main->Render(holographicFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreWindow::GetForCurrentThread().Dispatcher().ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Required for IFrameworkView.
|
||||
// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView
|
||||
// class is torn down while the app is in the foreground.
|
||||
void SampleRemoteWindowUWP::Uninitialize()
|
||||
{
|
||||
}
|
||||
|
||||
winrt::com_ptr<IDXGISwapChain1>
|
||||
SampleRemoteWindowUWP::CreateSwapChain(const winrt::com_ptr<ID3D11Device1>& device, const DXGI_SWAP_CHAIN_DESC1* desc)
|
||||
{
|
||||
winrt::com_ptr<IDXGIDevice3> dxgiDevice;
|
||||
device.as(dxgiDevice);
|
||||
|
||||
winrt::com_ptr<IDXGIAdapter> dxgiAdapter;
|
||||
winrt::check_hresult(dxgiDevice->GetAdapter(dxgiAdapter.put()));
|
||||
|
||||
winrt::com_ptr<IDXGIFactory4> dxgiFactory;
|
||||
winrt::check_hresult(dxgiAdapter->GetParent(__uuidof(dxgiFactory), dxgiFactory.put_void()));
|
||||
|
||||
winrt::com_ptr<IDXGISwapChain1> swapChain;
|
||||
winrt::check_hresult(dxgiFactory->CreateSwapChainForCoreWindow(
|
||||
device.get(), static_cast<::IUnknown*>(winrt::get_abi(m_window)), desc, nullptr, swapChain.put()));
|
||||
|
||||
return swapChain;
|
||||
}
|
||||
|
||||
winrt::Windows::Graphics::Holographic::HolographicSpace SampleRemoteWindowUWP::CreateHolographicSpace()
|
||||
{
|
||||
return HolographicSpace::CreateForCoreWindow(m_window);
|
||||
}
|
||||
|
||||
winrt::Windows::UI::Input::Spatial::SpatialInteractionManager SampleRemoteWindowUWP::CreateInteractionManager()
|
||||
{
|
||||
return winrt::Windows::UI::Input::Spatial::SpatialInteractionManager::GetForCurrentView();
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWP::SetWindowTitle(std::wstring title)
|
||||
{
|
||||
auto dispatcher = winrt::Windows::ApplicationModel::Core::CoreApplication::MainView().CoreWindow().Dispatcher();
|
||||
|
||||
auto doSetWindowTitle = [title]() {
|
||||
try
|
||||
{
|
||||
if (auto view = winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView())
|
||||
{
|
||||
view.Title(winrt::to_hstring(title.c_str()));
|
||||
}
|
||||
}
|
||||
catch (const winrt::hresult_error&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
if (dispatcher.HasThreadAccess())
|
||||
{
|
||||
doSetWindowTitle();
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatcher.RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, doSetWindowTitle);
|
||||
}
|
||||
}
|
||||
|
||||
// Application lifecycle event handlers.
|
||||
|
||||
void SampleRemoteWindowUWP::OnSuspending(const winrt::Windows::Foundation::IInspectable& sender, const SuspendingEventArgs& args)
|
||||
{
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWP::OnResuming(
|
||||
const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args)
|
||||
{
|
||||
// Restore any data or state that was unloaded on suspend. By default, data
|
||||
// and state are persisted when resuming from suspend. Note that this event
|
||||
// does not occur if the app was previously terminated.
|
||||
|
||||
// Insert your code here.
|
||||
}
|
||||
|
||||
// Window event handlers.
|
||||
|
||||
void SampleRemoteWindowUWP::OnWindowSizeChanged(
|
||||
const winrt::Windows::Foundation::IInspectable& sender, const WindowSizeChangedEventArgs& args)
|
||||
{
|
||||
winrt::Windows::Foundation::Size size = args.Size();
|
||||
m_main->OnResize(static_cast<int>(size.Width + 0.5f), static_cast<int>(size.Height + 0.5f));
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWP::OnVisibilityChanged(
|
||||
const winrt::Windows::Foundation::IInspectable& sender, const VisibilityChangedEventArgs& args)
|
||||
{
|
||||
m_windowVisible = args.Visible();
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWP::OnWindowClosed(const CoreWindow& window, const CoreWindowEventArgs& args)
|
||||
{
|
||||
m_windowClosed = true;
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWP::OnKeyDown(const CoreWindow& window, const KeyEventArgs& args)
|
||||
{
|
||||
int32_t key = static_cast<int32_t>(args.VirtualKey());
|
||||
if (key >= 0 && key <= 0xFF)
|
||||
{
|
||||
m_main->OnKeyPress(static_cast<char>(tolower(key)));
|
||||
}
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWP::OnViewActivated(CoreApplicationView const& sender, IActivatedEventArgs const& activationArgs)
|
||||
{
|
||||
using namespace winrt::Windows::ApplicationModel;
|
||||
using namespace Activation;
|
||||
using namespace Core;
|
||||
|
||||
SampleRemoteMain::Options options;
|
||||
options.hostname = L"127.0.0.1";
|
||||
options.port = 8265;
|
||||
|
||||
#if _M_ARM || _M_ARM64
|
||||
bool isStandalone = true;
|
||||
#else
|
||||
bool isStandalone = false;
|
||||
#endif
|
||||
|
||||
if (activationArgs != nullptr)
|
||||
{
|
||||
ActivationKind activationKind = activationArgs.Kind();
|
||||
if (activationKind == Activation::ActivationKind::Launch)
|
||||
{
|
||||
LaunchActivatedEventArgs launchArgs = activationArgs.as<LaunchActivatedEventArgs>();
|
||||
|
||||
std::vector<std::wstring> args;
|
||||
std::wistringstream stream(std::wstring(launchArgs.Arguments()));
|
||||
std::copy(
|
||||
std::istream_iterator<std::wstring, wchar_t>(stream),
|
||||
std::istream_iterator<std::wstring, wchar_t>(),
|
||||
std::back_inserter(args));
|
||||
|
||||
size_t argCount = args.size();
|
||||
for (size_t argIndex = 0; argIndex < argCount; ++argIndex)
|
||||
{
|
||||
const std::wstring& arg = args[argIndex];
|
||||
|
||||
if (arg.size() == 0)
|
||||
continue;
|
||||
|
||||
if (arg == L"-standalone")
|
||||
{
|
||||
isStandalone = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == L"-noStandalone")
|
||||
{
|
||||
isStandalone = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == L"-listen")
|
||||
{
|
||||
options.listen = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == L"-noautoreconnect")
|
||||
{
|
||||
options.autoReconnect = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == L"-ephemeralport")
|
||||
{
|
||||
options.ephemeralPort = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == L"-transportport")
|
||||
{
|
||||
if (argIndex + 1 < argCount)
|
||||
{
|
||||
std::wstring transportPortStr = args[argIndex + 1];
|
||||
try
|
||||
{
|
||||
options.transportPort = std::stoi(transportPortStr);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
// Ignore invalid transport port strings.
|
||||
}
|
||||
argIndex++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t colonPos = arg.find(L':');
|
||||
if (colonPos != std::wstring::npos)
|
||||
{
|
||||
std::wstring portStr = arg.substr(colonPos + 1);
|
||||
|
||||
options.hostname = arg.substr(0, colonPos);
|
||||
int32_t port = std::wcstol(portStr.c_str(), nullptr, 10);
|
||||
|
||||
// check for invalid port numbers
|
||||
if (port < 0 || port > 65535)
|
||||
{
|
||||
port = 0;
|
||||
}
|
||||
|
||||
options.port = port;
|
||||
}
|
||||
else
|
||||
{
|
||||
options.hostname = arg.c_str();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isStandalone)
|
||||
{
|
||||
|
||||
m_ipAddress = options.hostname;
|
||||
m_port = options.port;
|
||||
|
||||
m_main->ConfigureRemoting(options);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_main->InitializeStandalone();
|
||||
}
|
||||
|
||||
// Run() won't start until the CoreWindow is activated.
|
||||
sender.CoreWindow().Activate();
|
||||
}
|
||||
|
||||
SampleRemoteWindowUWPView::SampleRemoteWindowUWPView()
|
||||
{
|
||||
m_window = std::make_shared<SampleRemoteWindowUWP>();
|
||||
}
|
||||
|
||||
winrt::Windows::ApplicationModel::Core::IFrameworkView SampleRemoteWindowUWPView::CreateView()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWPView::Initialize(const winrt::Windows::ApplicationModel::Core::CoreApplicationView& applicationView)
|
||||
{
|
||||
m_window->Initialize(applicationView);
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWPView::SetWindow(const winrt::Windows::UI::Core::CoreWindow& window)
|
||||
{
|
||||
m_window->SetWindow(window);
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWPView::Load(const winrt::hstring& entryPoint)
|
||||
{
|
||||
m_window->Load(entryPoint);
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWPView::Run()
|
||||
{
|
||||
m_window->Run();
|
||||
}
|
||||
|
||||
void SampleRemoteWindowUWPView::Uninitialize()
|
||||
{
|
||||
m_window->Uninitialize();
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SampleRemoteMain.h"
|
||||
|
||||
#include "Common\DeviceResources.h"
|
||||
|
||||
#include <winrt/Microsoft.Holographic.AppRemoting.h>
|
||||
#include <winrt/Windows.ApplicationModel.Core.h>
|
||||
|
||||
// Main entry point for our app. Connects the app with the Windows shell and handles application lifecycle events.
|
||||
class SampleRemoteWindowUWP : public std::enable_shared_from_this<SampleRemoteWindowUWP>, public SampleRemoteMain::IWindow
|
||||
{
|
||||
public:
|
||||
SampleRemoteWindowUWP();
|
||||
|
||||
// IFrameworkView methods
|
||||
virtual void Initialize(const winrt::Windows::ApplicationModel::Core::CoreApplicationView& applicationView);
|
||||
virtual void SetWindow(const winrt::Windows::UI::Core::CoreWindow& window);
|
||||
virtual void Load(const winrt::hstring& entryPoint);
|
||||
virtual void Run();
|
||||
virtual void Uninitialize();
|
||||
|
||||
// SampleRemoteMain::IWindow methods.
|
||||
virtual winrt::com_ptr<IDXGISwapChain1>
|
||||
CreateSwapChain(const winrt::com_ptr<ID3D11Device1>& device, const DXGI_SWAP_CHAIN_DESC1* desc) override;
|
||||
|
||||
virtual winrt::Windows::Graphics::Holographic::HolographicSpace CreateHolographicSpace() override;
|
||||
|
||||
virtual winrt::Windows::UI::Input::Spatial::SpatialInteractionManager CreateInteractionManager() override;
|
||||
|
||||
virtual void SetWindowTitle(std::wstring title) override;
|
||||
|
||||
protected:
|
||||
// Application lifecycle event handlers.
|
||||
void OnSuspending(
|
||||
const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::ApplicationModel::SuspendingEventArgs& args);
|
||||
void OnResuming(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
|
||||
|
||||
// Activation handling
|
||||
void OnViewActivated(
|
||||
winrt::Windows::ApplicationModel::Core::CoreApplicationView const& sender,
|
||||
winrt::Windows::ApplicationModel::Activation::IActivatedEventArgs const& args);
|
||||
|
||||
// Window event handlers.
|
||||
void OnWindowSizeChanged(
|
||||
const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Core::WindowSizeChangedEventArgs& args);
|
||||
void OnVisibilityChanged(
|
||||
const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Core::VisibilityChangedEventArgs& args);
|
||||
void OnWindowClosed(const winrt::Windows::UI::Core::CoreWindow& window, const winrt::Windows::UI::Core::CoreWindowEventArgs& args);
|
||||
void OnKeyDown(const winrt::Windows::UI::Core::CoreWindow& window, const winrt::Windows::UI::Core::KeyEventArgs& args);
|
||||
|
||||
private:
|
||||
winrt::Windows::UI::Core::CoreWindow m_window = nullptr;
|
||||
std::shared_ptr<SampleRemoteMain> m_main;
|
||||
std::wstring m_ipAddress;
|
||||
int32_t m_port = 8265;
|
||||
bool m_windowClosed = false;
|
||||
bool m_windowVisible = true;
|
||||
};
|
||||
|
||||
class SampleRemoteWindowUWPView : public winrt::implements<
|
||||
SampleRemoteWindowUWPView,
|
||||
winrt::Windows::ApplicationModel::Core::IFrameworkViewSource,
|
||||
winrt::Windows::ApplicationModel::Core::IFrameworkView>
|
||||
{
|
||||
public:
|
||||
SampleRemoteWindowUWPView();
|
||||
|
||||
// IFrameworkViewSource methods.
|
||||
winrt::Windows::ApplicationModel::Core::IFrameworkView CreateView();
|
||||
|
||||
// IFrameworkView methods.
|
||||
virtual void Initialize(const winrt::Windows::ApplicationModel::Core::CoreApplicationView& applicationView);
|
||||
virtual void SetWindow(const winrt::Windows::UI::Core::CoreWindow& window);
|
||||
virtual void Load(const winrt::hstring& entryPoint);
|
||||
virtual void Run();
|
||||
virtual void Uninitialize();
|
||||
|
||||
private:
|
||||
std::shared_ptr<SampleRemoteWindowUWP> m_window;
|
||||
};
|
|
@ -1,378 +0,0 @@
|
|||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#include <pch.h>
|
||||
|
||||
#include <windows.graphics.holographic.h>
|
||||
#include <windows.ui.input.spatial.h>
|
||||
|
||||
#include <SampleRemoteWindowWin32.h>
|
||||
|
||||
#include <HolographicAppRemoting/Streamer.h>
|
||||
#include <HolographicSpaceInterop.h>
|
||||
#include <SpatialInteractionManagerInterop.h>
|
||||
|
||||
#include <Common/DbgLog.h>
|
||||
#include <DirectXColors.h>
|
||||
|
||||
#include <codecvt>
|
||||
#include <regex>
|
||||
|
||||
#include <shellapi.h>
|
||||
#include <windows.graphics.directx.direct3d11.interop.h>
|
||||
|
||||
#define WINDOWCLASSNAME L"SampleRemoteWindowWin32Class"
|
||||
|
||||
LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
static SampleRemoteWindowWin32* s_sampleHostWindow;
|
||||
|
||||
LRESULT result = 0;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
{
|
||||
CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lParam);
|
||||
s_sampleHostWindow = reinterpret_cast<SampleRemoteWindowWin32*>(cs->lpCreateParams);
|
||||
|
||||
RECT clientRect;
|
||||
GetClientRect(hWnd, &clientRect);
|
||||
|
||||
s_sampleHostWindow->OnResize(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
|
||||
result = 0;
|
||||
}
|
||||
break;
|
||||
case WM_WINDOWPOSCHANGED:
|
||||
{
|
||||
auto windowPos = reinterpret_cast<WINDOWPOS*>(lParam);
|
||||
if ((windowPos->flags & SWP_NOSIZE) == 0)
|
||||
{
|
||||
RECT clientRect;
|
||||
GetClientRect(hWnd, &clientRect);
|
||||
|
||||
s_sampleHostWindow->OnResize(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
|
||||
}
|
||||
result = 0;
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
{
|
||||
s_sampleHostWindow = nullptr;
|
||||
result = 0;
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
{
|
||||
DestroyWindow(hWnd);
|
||||
result = 0;
|
||||
}
|
||||
break;
|
||||
case WM_CHAR:
|
||||
{
|
||||
const int key = tolower(static_cast<int>(wParam));
|
||||
s_sampleHostWindow->OnKeyPress(static_cast<char>(key));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::wstring SplitHostnameAndPortString(const std::wstring& address, uint16_t& port)
|
||||
{
|
||||
static std::basic_regex<wchar_t> addressMatcher(L"(?:(\\[.*\\])|([^:]*))(?:[:](\\d+))?");
|
||||
std::match_results<typename std::wstring::const_iterator> results;
|
||||
if (std::regex_match(address, results, addressMatcher))
|
||||
{
|
||||
if (results[3].matched)
|
||||
{
|
||||
std::wstring portStr = results[3].str();
|
||||
port = static_cast<uint16_t>(std::wcstol(portStr.c_str(), nullptr, 10));
|
||||
}
|
||||
|
||||
return (results[1].matched) ? results[1].str() : results[2].str();
|
||||
}
|
||||
else
|
||||
{
|
||||
return address;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void SampleRemoteWindowWin32::Initialize()
|
||||
{
|
||||
m_main = std::make_shared<SampleRemoteMain>(weak_from_this());
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::InitializeHwnd(HWND hWnd)
|
||||
{
|
||||
m_hWnd = hWnd;
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::ConfigureRemoting(const SampleRemoteMain::Options& options)
|
||||
{
|
||||
m_main->ConfigureRemoting(options);
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::Connect()
|
||||
{
|
||||
m_main->InitializeRemoteContextAndConnectOrListen();
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::InitializeStandalone()
|
||||
{
|
||||
m_main->InitializeStandalone();
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::Tick()
|
||||
{
|
||||
if (const HolographicFrame& holographicFrame = m_main->Update())
|
||||
{
|
||||
m_main->Render(holographicFrame);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::OnKeyPress(char key)
|
||||
{
|
||||
m_main->OnKeyPress(key);
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::OnResize(int width, int height)
|
||||
{
|
||||
m_main->OnResize(width, height);
|
||||
}
|
||||
|
||||
winrt::com_ptr<IDXGISwapChain1>
|
||||
SampleRemoteWindowWin32::CreateSwapChain(const winrt::com_ptr<ID3D11Device1>& device, const DXGI_SWAP_CHAIN_DESC1* desc)
|
||||
{
|
||||
winrt::com_ptr<IDXGIDevice1> dxgiDevice;
|
||||
device.as(dxgiDevice);
|
||||
|
||||
winrt::com_ptr<IDXGIAdapter> dxgiAdapter;
|
||||
winrt::check_hresult(dxgiDevice->GetAdapter(dxgiAdapter.put()));
|
||||
|
||||
winrt::com_ptr<IDXGIFactory2> dxgiFactory;
|
||||
winrt::check_hresult(dxgiAdapter->GetParent(__uuidof(IDXGIFactory2), dxgiFactory.put_void()));
|
||||
|
||||
winrt::check_hresult(dxgiFactory->MakeWindowAssociation(m_hWnd, DXGI_MWA_NO_ALT_ENTER));
|
||||
|
||||
winrt::com_ptr<IDXGISwapChain1> swapChain = nullptr;
|
||||
winrt::check_hresult(dxgiFactory->CreateSwapChainForHwnd(device.get(), m_hWnd, desc, nullptr, nullptr, swapChain.put()));
|
||||
|
||||
return swapChain;
|
||||
}
|
||||
|
||||
void SampleRemoteWindowWin32::SetWindowTitle(std::wstring title)
|
||||
{
|
||||
if (m_hWnd)
|
||||
{
|
||||
if (!SetWindowTextW(m_hWnd, title.c_str()))
|
||||
{
|
||||
winrt::check_hresult(HRESULT_FROM_WIN32(GetLastError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
winrt::Windows::Graphics::Holographic::HolographicSpace SampleRemoteWindowWin32::CreateHolographicSpace()
|
||||
{
|
||||
// Use WinRT factory to create the holographic space.
|
||||
// See https://docs.microsoft.com/en-us/windows/win32/api/holographicspaceinterop/
|
||||
winrt::com_ptr<IHolographicSpaceInterop> holographicSpaceInterop =
|
||||
winrt::get_activation_factory<HolographicSpace, IHolographicSpaceInterop>();
|
||||
|
||||
winrt::com_ptr<ABI::Windows::Graphics::Holographic::IHolographicSpace> spHolographicSpace;
|
||||
winrt::check_hresult(holographicSpaceInterop->CreateForWindow(
|
||||
m_hWnd, __uuidof(ABI::Windows::Graphics::Holographic::IHolographicSpace), winrt::put_abi(spHolographicSpace)));
|
||||
|
||||
return spHolographicSpace.as<HolographicSpace>();
|
||||
}
|
||||
|
||||
winrt::Windows::UI::Input::Spatial::SpatialInteractionManager SampleRemoteWindowWin32::CreateInteractionManager()
|
||||
{
|
||||
using namespace winrt::Windows::UI::Input::Spatial;
|
||||
|
||||
// Use WinRT factory to create the spatial interaction manager.
|
||||
// See https://docs.microsoft.com/en-us/windows/win32/api/spatialinteractionmanagerinterop/
|
||||
winrt::com_ptr<ISpatialInteractionManagerInterop> spatialInteractionManagerInterop =
|
||||
winrt::get_activation_factory<SpatialInteractionManager, ISpatialInteractionManagerInterop>();
|
||||
|
||||
winrt::com_ptr<ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager> spSpatialInteractionManager;
|
||||
winrt::check_hresult(spatialInteractionManagerInterop->GetForWindow(
|
||||
m_hWnd, __uuidof(ABI::Windows::UI::Input::Spatial::ISpatialInteractionManager), winrt::put_abi(spSpatialInteractionManager)));
|
||||
|
||||
return spSpatialInteractionManager.as<SpatialInteractionManager>();
|
||||
}
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd)
|
||||
{
|
||||
winrt::init_apartment();
|
||||
|
||||
SampleRemoteMain::Options options;
|
||||
|
||||
bool isStandalone = false;
|
||||
bool noUserWait = false;
|
||||
|
||||
LPWSTR* args;
|
||||
int argCount;
|
||||
args = CommandLineToArgvW(GetCommandLineW(), &argCount);
|
||||
for (int argIndex = 1; argIndex < argCount; ++argIndex)
|
||||
{
|
||||
if (wcslen(args[argIndex]) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::wstring arg = args[argIndex];
|
||||
if (arg[0] == '-')
|
||||
{
|
||||
std::wstring param = arg.substr(1);
|
||||
std::transform(param.begin(), param.end(), param.begin(), ::tolower);
|
||||
|
||||
if (param == L"listen")
|
||||
{
|
||||
options.listen = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param == L"standalone")
|
||||
{
|
||||
isStandalone = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param == L"nouserwait")
|
||||
{
|
||||
noUserWait = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param == L"noautoreconnect")
|
||||
{
|
||||
options.autoReconnect = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param == L"ephemeralport")
|
||||
{
|
||||
options.ephemeralPort = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param == L"transportport")
|
||||
{
|
||||
if (argIndex + 1 < argCount)
|
||||
{
|
||||
std::wstring transportPortStr = args[argIndex + 1];
|
||||
try
|
||||
{
|
||||
options.transportPort = std::stoi(transportPortStr);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
// Ignore invalid transport port strings.
|
||||
}
|
||||
argIndex++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
options.hostname = SplitHostnameAndPortString(arg, options.port);
|
||||
}
|
||||
|
||||
std::shared_ptr<SampleRemoteWindowWin32> sampleRemoteWindow = std::make_shared<SampleRemoteWindowWin32>();
|
||||
sampleRemoteWindow->Initialize();
|
||||
|
||||
WNDCLASSEXW wcex = {};
|
||||
wcex.cbSize = sizeof(wcex);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = wndProc;
|
||||
wcex.hInstance = 0;
|
||||
wcex.hIcon = LoadIcon(0, IDI_APPLICATION);
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = static_cast<HBRUSH>(GetStockObject(NULL_BRUSH));
|
||||
wcex.lpszClassName = WINDOWCLASSNAME;
|
||||
RegisterClassExW(&wcex);
|
||||
|
||||
RECT rc = {0, 0, INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT};
|
||||
AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
|
||||
|
||||
std::wstring windowName = TITLE_TEXT;
|
||||
|
||||
HWND hWnd = CreateWindowW(
|
||||
WINDOWCLASSNAME,
|
||||
windowName.c_str(),
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
rc.right - rc.left,
|
||||
rc.bottom - rc.top,
|
||||
nullptr,
|
||||
nullptr,
|
||||
0,
|
||||
sampleRemoteWindow.get());
|
||||
|
||||
RECT clientRect;
|
||||
GetClientRect(hWnd, &clientRect);
|
||||
|
||||
sampleRemoteWindow->InitializeHwnd(hWnd);
|
||||
|
||||
if (!isStandalone)
|
||||
{
|
||||
sampleRemoteWindow->ConfigureRemoting(options);
|
||||
if (noUserWait)
|
||||
{
|
||||
sampleRemoteWindow->Connect();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleRemoteWindow->InitializeStandalone();
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, SW_SHOWNORMAL);
|
||||
bool quit = false;
|
||||
while (!quit)
|
||||
{
|
||||
MSG msg = {0};
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
sampleRemoteWindow->Tick();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Unhandeled exception during tick, exit program
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SampleRemoteMain.h>
|
||||
|
||||
class SampleRemoteWindowWin32 : public std::enable_shared_from_this<SampleRemoteWindowWin32>, public SampleRemoteMain::IWindow
|
||||
{
|
||||
public:
|
||||
void Initialize();
|
||||
|
||||
void InitializeHwnd(HWND hWnd);
|
||||
|
||||
void ConfigureRemoting(const SampleRemoteMain::Options& options);
|
||||
void Connect();
|
||||
|
||||
void InitializeStandalone();
|
||||
|
||||
void Tick();
|
||||
|
||||
void OnKeyPress(char key);
|
||||
void OnResize(int width, int height);
|
||||
|
||||
virtual winrt::com_ptr<IDXGISwapChain1>
|
||||
CreateSwapChain(const winrt::com_ptr<ID3D11Device1>& device, const DXGI_SWAP_CHAIN_DESC1* desc) override;
|
||||
|
||||
virtual winrt::Windows::Graphics::Holographic::HolographicSpace CreateHolographicSpace() override;
|
||||
|
||||
virtual winrt::Windows::UI::Input::Spatial::SpatialInteractionManager CreateInteractionManager() override;
|
||||
|
||||
virtual void SetWindowTitle(std::wstring title) override;
|
||||
|
||||
private:
|
||||
HWND m_hWnd = 0;
|
||||
|
||||
std::shared_ptr<SampleRemoteMain> m_main;
|
||||
};
|
Загрузка…
Ссылка в новой задаче