Demonstrate using Windows 10 WRL API and GameBar API

This commit is contained in:
Ted John 2016-10-28 23:33:52 +01:00
parent a29bf9912b
commit 7ac0fa1316
5 changed files with 92 additions and 1 deletions

View File

@ -167,6 +167,7 @@
<ClCompile Include="src\platform\posix.c" />
<ClCompile Include="src\platform\shared.c" />
<ClCompile Include="src\platform\windows.c" />
<ClCompile Include="src\platform\WindowsAPI.cpp" />
<ClCompile Include="src\rct1.c" />
<ClCompile Include="src\rct1\S4Importer.cpp" />
<ClCompile Include="src\rct1\Tables.cpp" />
@ -537,7 +538,7 @@
<ProjectGuid>{D24D94F6-2A74-480C-B512-629C306CE92F}</ProjectGuid>
<RootNamespace>openrct2</RootNamespace>
<ProjectName>openrct2</ProjectName>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

View File

@ -439,6 +439,10 @@ static void openrct2_loop()
platform_draw();
if (wrl_is_gamebar_visible()) {
printf("game bar is visible\n");
}
fps++;
if (SDL_GetTicks() - secondTick >= 1000) {
fps = 0;

View File

@ -0,0 +1,73 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include <SDL_platform.h>
#ifdef __WINDOWS__
#include <windows.foundation.h>
#include <windows.gaming.ui.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
#pragma comment(lib, "runtimeobject.lib")
using namespace ABI::Windows::Gaming::UI;
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Details;
using namespace Microsoft::WRL::Wrappers;
static bool _wrlInitialised;
static ComPtr<IGameBarStatics> _gameBar;
extern "C"
{
void wrl_initialise()
{
if (SUCCEEDED(Initialize(RO_INIT_MULTITHREADED)))
{
_wrlInitialised = true;
// Get a GameBar instance
GetActivationFactory(HStringReference(RuntimeClass_Windows_Gaming_UI_GameBar).Get(), &_gameBar);
}
}
void wrl_dispose()
{
if (_wrlInitialised)
{
_gameBar = nullptr;
Uninitialize();
}
}
bool wrl_is_gamebar_visible()
{
if (_gameBar != nullptr)
{
boolean value;
if (SUCCEEDED(_gameBar->get_Visible(&value)))
{
return value != 0;
}
}
return false;
}
}
#endif

View File

@ -213,6 +213,11 @@ datetime64 platform_get_datetime_now_utc();
// This function cannot be marked as 'static', even though it may seem to be,
// as it requires external linkage, which 'static' prevents
__declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
void wrl_initialise();
void wrl_dispose();
bool wrl_is_gamebar_visible();
#endif // __WINDOWS__
#if defined(__LINUX__) || defined(__MACOSX__)

View File

@ -61,6 +61,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
{
_dllModule = hInstance;
wrl_initialise();
int argc;
char ** argv = (char**)windows_get_command_line_args(&argc);
int runGame = cmdline_run((const char **)argv, argc);
@ -75,6 +77,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
openrct2_launch();
}
wrl_dispose();
return gExitCode;
}
@ -86,11 +90,15 @@ int main(int argc, char *argv[])
HINSTANCE hInstance = GetModuleHandle(NULL);
_dllModule = hInstance;
wrl_initialise();
int runGame = cmdline_run((const char **)argv, argc);
if (runGame == 1) {
openrct2_launch();
}
wrl_dispose();
return gExitCode;
}