mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-07 21:25:41 +00:00
prototype
This commit is contained in:
@@ -8,7 +8,10 @@
|
||||
#include "MyPage.g.cpp"
|
||||
#include "..\..\..\src\cascadia\UnitTests_Control\MockControlSettings.h"
|
||||
#include "..\..\..\src\types\inc\utils.hpp"
|
||||
|
||||
#include <Shlobj.h>
|
||||
#include <Shlobj_core.h>
|
||||
#include <wincodec.h>
|
||||
#include <Windows.Graphics.Imaging.Interop.h>
|
||||
using namespace std::chrono_literals;
|
||||
using namespace winrt::Microsoft::Terminal;
|
||||
|
||||
@@ -19,6 +22,9 @@ namespace winrt
|
||||
using IInspectable = Windows::Foundation::IInspectable;
|
||||
}
|
||||
|
||||
using namespace winrt::Windows::Graphics::Imaging;
|
||||
using namespace winrt::Windows::Storage::Streams;
|
||||
|
||||
namespace winrt::SampleApp::implementation
|
||||
{
|
||||
MyPage::MyPage()
|
||||
@@ -30,10 +36,79 @@ namespace winrt::SampleApp::implementation
|
||||
{
|
||||
}
|
||||
|
||||
winrt::Windows::Graphics::Imaging::SoftwareBitmap MyConvertToSoftwareBitmap(HICON hicon,
|
||||
winrt::Windows::Graphics::Imaging::BitmapPixelFormat pixelFormat,
|
||||
winrt::Windows::Graphics::Imaging::BitmapAlphaMode alphaMode,
|
||||
IWICImagingFactory* imagingFactory)
|
||||
{
|
||||
// Load the icon into an IWICBitmap
|
||||
wil::com_ptr<IWICBitmap> iconBitmap;
|
||||
THROW_IF_FAILED(imagingFactory->CreateBitmapFromHICON(hicon, iconBitmap.put()));
|
||||
|
||||
// Put the IWICBitmap into a SoftwareBitmap. This may fail if WICBitmap's format is not supported by
|
||||
// SoftwareBitmap. CreateBitmapFromHICON always creates RGBA8 so we're ok.
|
||||
auto softwareBitmap = winrt::capture<winrt::Windows::Graphics::Imaging::SoftwareBitmap>(
|
||||
winrt::create_instance<ISoftwareBitmapNativeFactory>(CLSID_SoftwareBitmapNativeFactory),
|
||||
&ISoftwareBitmapNativeFactory::CreateFromWICBitmap,
|
||||
iconBitmap.get(),
|
||||
false);
|
||||
|
||||
// Convert the pixel format and alpha mode if necessary
|
||||
if (softwareBitmap.BitmapPixelFormat() != pixelFormat || softwareBitmap.BitmapAlphaMode() != alphaMode)
|
||||
{
|
||||
softwareBitmap = winrt::Windows::Graphics::Imaging::SoftwareBitmap::Convert(softwareBitmap, pixelFormat, alphaMode);
|
||||
}
|
||||
|
||||
return softwareBitmap;
|
||||
}
|
||||
|
||||
winrt::Windows::Graphics::Imaging::SoftwareBitmap MyGetBitmapFromIconFileAsync(const winrt::hstring& iconPath,
|
||||
int32_t iconIndex,
|
||||
uint32_t iconSize)
|
||||
{
|
||||
wil::unique_hicon hicon;
|
||||
LOG_IF_FAILED(SHDefExtractIcon(iconPath.c_str(), iconIndex, 0, &hicon, nullptr, iconSize));
|
||||
|
||||
if (!hicon)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wil::com_ptr<IWICImagingFactory> wicImagingFactory;
|
||||
THROW_IF_FAILED(CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wicImagingFactory)));
|
||||
|
||||
return MyConvertToSoftwareBitmap(hicon.get(), BitmapPixelFormat::Bgra8, BitmapAlphaMode::Premultiplied, wicImagingFactory.get());
|
||||
}
|
||||
|
||||
winrt::fire_and_forget MyPage::CreateClicked(const IInspectable& sender,
|
||||
const WUX::Input::TappedRoutedEventArgs& eventArgs)
|
||||
{
|
||||
// Try:
|
||||
// * c:\Windows\System32\SHELL32.dll, 210
|
||||
// * c:\Windows\System32\notepad.exe, 0
|
||||
// * C:\Program Files\PowerShell\6-preview\pwsh.exe, 0 (this doesn't exist for me)
|
||||
// * C:\Program Files\PowerShell\7\pwsh.exe, 0
|
||||
auto text{ GuidInput().Text() };
|
||||
auto index{ static_cast<int>(IconIndex().Value()) };
|
||||
|
||||
co_await winrt::resume_background();
|
||||
auto swBitmap{ MyGetBitmapFromIconFileAsync(text, index, 32) };
|
||||
if (swBitmap == nullptr)
|
||||
{
|
||||
co_return;
|
||||
}
|
||||
co_await winrt::resume_foreground(Dispatcher());
|
||||
winrt::Windows::UI::Xaml::Media::Imaging::SoftwareBitmapSource bitmapSource{};
|
||||
co_await bitmapSource.SetBitmapAsync(swBitmap);
|
||||
co_await winrt::resume_foreground(Dispatcher());
|
||||
|
||||
winrt::Microsoft::UI::Xaml::Controls::ImageIconSource imageIconSource{};
|
||||
imageIconSource.ImageSource(bitmapSource);
|
||||
winrt::Microsoft::UI::Xaml::Controls::ImageIcon icon{};
|
||||
icon.Source(bitmapSource);
|
||||
icon.Width(32);
|
||||
icon.Height(32);
|
||||
InProcContent().Children().Append(icon);
|
||||
}
|
||||
|
||||
void MyPage::CloseClicked(const IInspectable& /*sender*/,
|
||||
|
||||
@@ -22,24 +22,12 @@
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox x:Name="GuidInput"
|
||||
Width="400"
|
||||
PlaceholderText="{}{guid here}" />
|
||||
PlaceholderText="path here" />
|
||||
<mux:NumberBox x:Name="IconIndex" />
|
||||
<Button x:Name="CreateOutOfProcControl"
|
||||
Grid.Row="0"
|
||||
Tapped="CreateClicked">
|
||||
Create
|
||||
</Button>
|
||||
<Button x:Name="CloseOutOfProcControl"
|
||||
Grid.Row="0"
|
||||
Margin="4,0,0,0"
|
||||
Tapped="CloseClicked">
|
||||
Close
|
||||
</Button>
|
||||
<Button x:Name="KillOutOfProcControl"
|
||||
Grid.Row="0"
|
||||
Margin="4,0,0,0"
|
||||
Tapped="KillClicked">
|
||||
Kill
|
||||
</Button>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
@@ -53,12 +41,13 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid x:Name="InProcContent"
|
||||
Grid.Column="0"
|
||||
Padding="16"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="#ff0000" />
|
||||
<StackPanel x:Name="InProcContent"
|
||||
Grid.Column="0"
|
||||
Padding="16"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="#ff0000"
|
||||
Orientation="Vertical" />
|
||||
|
||||
<Grid Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
|
||||
@@ -83,6 +83,13 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- ====================== Compiler & Linker Flags ===================== -->
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(OpenConsoleCommonOutDir)\ConTypes.lib;WindowsApp.lib;shell32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<Import Project="$(OpenConsoleDir)packages\Microsoft.UI.Xaml.2.7.1\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('$(OpenConsoleDir)packages\Microsoft.UI.Xaml.2.7.1\build\native\Microsoft.UI.Xaml.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <winrt/Windows.Foundation.Metadata.h>
|
||||
#include <winrt/Windows.Graphics.Display.h>
|
||||
#include <winrt/Windows.Graphics.Imaging.h>
|
||||
// #include <winrt/Windows.Graphics.Imaging.Interop.h>
|
||||
#include <winrt/windows.ui.core.h>
|
||||
#include <winrt/Windows.ui.input.h>
|
||||
#include <winrt/Windows.UI.Text.h>
|
||||
@@ -41,10 +43,12 @@
|
||||
#include <winrt/Windows.UI.Xaml.Data.h>
|
||||
#include <winrt/Windows.ui.xaml.media.h>
|
||||
#include <winrt/Windows.UI.Xaml.Media.Animation.h>
|
||||
#include <winrt/Windows.UI.Xaml.Media.Imaging.h>
|
||||
#include <winrt/Windows.ui.xaml.input.h>
|
||||
#include <winrt/Windows.UI.Xaml.Hosting.h>
|
||||
#include "winrt/Windows.UI.Xaml.Markup.h"
|
||||
#include "winrt/Windows.UI.ViewManagement.h"
|
||||
#include "winrt/Windows.Storage.Streams.h"
|
||||
|
||||
#include <winrt/Microsoft.Toolkit.Win32.UI.XamlHost.h>
|
||||
#include <winrt/Microsoft.UI.Xaml.Controls.h>
|
||||
|
||||
Reference in New Issue
Block a user