From c3f655ff7ad02bb7c9c5e0f82b8854e90eecce2a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 29 Mar 2018 23:26:33 -0700 Subject: Fixed issue with Win32 MessageProc() not checking if g_pTheApp is null --- Common/NativeApp/src/Win32/WinMain.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Common/NativeApp') diff --git a/Common/NativeApp/src/Win32/WinMain.cpp b/Common/NativeApp/src/Win32/WinMain.cpp index 6b53082..ff6b3b2 100644 --- a/Common/NativeApp/src/Win32/WinMain.cpp +++ b/Common/NativeApp/src/Win32/WinMain.cpp @@ -109,9 +109,12 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) // Called every time the NativeNativeAppBase receives a message LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) { - auto res = g_pTheApp->HandleWin32Message(wnd, message, wParam, lParam); - if (res != 0) - return res; + if(g_pTheApp) + { + auto res = g_pTheApp->HandleWin32Message(wnd, message, wParam, lParam); + if (res != 0) + return res; + } switch (message) { -- cgit v1.2.3 From f3ac2ce9dc0ae329ac2deeed96f038e0c8e07330 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 31 Mar 2018 20:55:13 -0700 Subject: Implemented switching to fullscreen on shift+enter in UWP --- Common/NativeApp/src/UWP/App.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ Common/NativeApp/src/UWP/App.h | 8 +++++-- 2 files changed, 53 insertions(+), 2 deletions(-) (limited to 'Common/NativeApp') diff --git a/Common/NativeApp/src/UWP/App.cpp b/Common/NativeApp/src/UWP/App.cpp index 6767b49..e0af485 100644 --- a/Common/NativeApp/src/UWP/App.cpp +++ b/Common/NativeApp/src/UWP/App.cpp @@ -103,6 +103,12 @@ void App::SetWindow(CoreWindow^ window) window->Closed += ref new TypedEventHandler(this, &App::OnWindowClosed); + window->KeyDown += + ref new TypedEventHandler(this, &App::OnKeyDown); + + window->KeyUp += + ref new TypedEventHandler(this, &App::OnKeyUp); + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); currentDisplayInformation->DpiChanged += @@ -243,6 +249,47 @@ void App::OnDisplayContentsInvalidated(DisplayInformation^ sender, Object^ args) GetDeviceResources()->ValidateDevice(); } +void App::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args) +{ + auto Key = args->VirtualKey; + switch(Key) + { + case VirtualKey::Escape: + CoreApplication::Exit(); + break; + + case VirtualKey::Enter: + if(m_bShiftPressed) + { + auto applicationView = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView(); + if (applicationView->IsFullScreenMode) + { + applicationView->ExitFullScreenMode(); + } + else + { + applicationView->TryEnterFullScreenMode(); + } + } + break; + + case VirtualKey::Shift: + m_bShiftPressed = true; + break; + } +} + +void App::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args) +{ + auto Key = args->VirtualKey; + switch (Key) + { + case VirtualKey::Shift: + m_bShiftPressed = false; + break; + } +} + std::shared_ptr App::GetDeviceResources() { if (m_deviceResources != nullptr && m_deviceResources->IsDeviceRemoved()) diff --git a/Common/NativeApp/src/UWP/App.h b/Common/NativeApp/src/UWP/App.h index b480a52..1b09441 100644 --- a/Common/NativeApp/src/UWP/App.h +++ b/Common/NativeApp/src/UWP/App.h @@ -57,11 +57,15 @@ namespace SampleApp void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + private: std::shared_ptr GetDeviceResources(); std::unique_ptr m_Main; std::shared_ptr m_deviceResources; - bool m_windowClosed; - bool m_windowVisible; + bool m_windowClosed = false; + bool m_windowVisible = false; + bool m_bShiftPressed = false; }; } -- cgit v1.2.3