Switch from C++/CX to standard C++ for WinRT

This commit is contained in:
UnknownShadow200 2024-10-16 21:56:53 +11:00
parent 9ad3f97efb
commit ec2993933c
2 changed files with 42 additions and 43 deletions

View File

@ -20,18 +20,12 @@
#include <shellapi.h> #include <shellapi.h>
#include <wincrypt.h> #include <wincrypt.h>
using namespace Windows::ApplicationModel; #include <winrt/Windows.Foundation.h>
using namespace Windows::ApplicationModel::Core; #include <winrt/Windows.System.h>
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Devices::Input; using namespace winrt;
using namespace Windows::Graphics::Display;
using namespace Windows::Foundation; using namespace Windows::Foundation;
using namespace Windows::System; using namespace Windows::System;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::Security::Cryptography;
using namespace Windows::Security::Cryptography::DataProtection;
using namespace Platform;
static HANDLE heap; static HANDLE heap;
const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION; const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION;
@ -532,11 +526,11 @@ cc_result Process_StartOpen(const cc_string* args) {
cc_winstring raw; cc_winstring raw;
Platform_EncodeString(&raw, args); Platform_EncodeString(&raw, args);
auto str = ref new String(UWP_STRING(&raw)); auto str = hstring(UWP_STRING(&raw));
auto uri = ref new Uri(str); auto uri = Uri(str);
auto options = ref new Windows::System::LauncherOptions(); auto options = Windows::System::LauncherOptions();
options->TreatAsUntrusted = true; options.TreatAsUntrusted(true);
Windows::System::Launcher::LaunchUriAsync(uri, options); Windows::System::Launcher::LaunchUriAsync(uri, options);
return 0; return 0;
} }

View File

@ -1,4 +1,16 @@
#include "../../src/Core.h" #include "../../src/Core.h"
#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.Devices.Input.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Graphics.Display.h>
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Windows.System.h>
#include <winrt/Windows.UI.Core.h>
using namespace winrt;
using namespace Windows::ApplicationModel; using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core; using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation; using namespace Windows::ApplicationModel::Activation;
@ -8,7 +20,6 @@ using namespace Windows::Foundation;
using namespace Windows::System; using namespace Windows::System;
using namespace Windows::UI::Core; using namespace Windows::UI::Core;
using namespace Windows::UI::Input; using namespace Windows::UI::Input;
using namespace Platform;
#include "../../src/_WindowBase.h" #include "../../src/_WindowBase.h"
#include "../../src/String.h" #include "../../src/String.h"
@ -192,56 +203,50 @@ void Window_DisableRawMouse(void) {
void OpenFileDialog(void) { void OpenFileDialog(void) {
auto picker = ref new Windows::Storage::Pickers::FileOpenPicker(); auto picker = Windows::Storage::Pickers::FileOpenPicker();
picker->FileTypeFilter->Append(ref new String(L".jpg")); //picker.FileTypeFilter().Append(hstring(L".jpg"));
picker->FileTypeFilter->Append(ref new String(L".jpeg"));
picker->FileTypeFilter->Append(ref new String(L".png"));
//Windows::Storage::StorageFile file = picker->PickSingleFileAsync(); //Windows::Storage::StorageFile file = picker->PickSingleFileAsync();
} }
ref class CCApp sealed : IFrameworkView struct CCApp : implements<CCApp, IFrameworkView, IFrameworkViewSource>
{ {
public: public:
virtual void Initialize(CoreApplicationView^ view) // IFrameworkView interface
void Initialize(const CoreApplicationView& view)
{ {
} }
virtual void Load(String^ EntryPoint) void Load(const hstring& entryPoint)
{ {
} }
virtual void Uninitialize() void Uninitialize()
{ {
} }
virtual void Run() void Run()
{ {
CoreWindow^ window = CoreWindow::GetForCurrentThread(); CoreWindow& window = CoreWindow::GetForCurrentThread();
window->Activate(); window.Activate();
CoreDispatcher^ dispatcher = window->Dispatcher; CoreDispatcher& dispatcher = window.Dispatcher();
dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit); dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
} }
virtual void SetWindow(CoreWindow^ win) void SetWindow(const CoreWindow& win)
{ {
} }
// IFrameworkViewSource interface
IFrameworkView CreateView()
{
return *this;
}
}; };
ref class CCAppSource sealed : IFrameworkViewSource int __stdcall wWinMain(void*, void*, wchar_t** argv, int argc)
{ {
public: auto app = CCApp();
virtual IFrameworkView^ CreateView() CoreApplication::Run(app);
{
return ref new CCApp();
}
};
[MTAThread]
int main(Array<String^>^ args)
{
//init_apartment();
auto source = ref new CCAppSource();
CoreApplication::Run(source);
} }