Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions NanaZip.Modern/NanaZip.Modern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "SponsorPage.h"
#include "AboutPage.h"
#include "InformationPage.h"
#include "SharePage.h"

#include <CommCtrl.h>
#pragma comment(lib, "comctl32.lib")
Expand Down Expand Up @@ -283,3 +284,31 @@ EXTERN_C INT WINAPI K7ModernShowInformationDialog(

return Result;
}

EXTERN_C INT WINAPI K7ModernShowShareDialog(
_In_opt_ HWND ParentWindowHandle,
_In_ std::vector<std::wstring> const& SharingFilePaths)
{
HWND WindowHandle =
winrt::check_pointer(::K7ModernCreateXamlDialog(ParentWindowHandle));

using Interface =
winrt::NanaZip::Modern::SharePage;
using Implementation =
winrt::NanaZip::Modern::implementation::SharePage;

Interface Window = winrt::make<Implementation>(
WindowHandle,
SharingFilePaths);

winrt::check_hresult(::MileXamlSetTransparentBackgroundAttribute(true));

int Result = ::K7ModernShowXamlDialog(
WindowHandle,
500,
375,
winrt::detach_abi(Window),
ParentWindowHandle);

return Result;
}
3 changes: 2 additions & 1 deletion NanaZip.Modern/NanaZip.Modern.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ EXPORTS
K7ModernShowSponsorDialog
K7ModernShowAboutDialog
K7ModernCreateMainWindowToolBarPage
K7ModernShowInformationDialog
K7ModernShowInformationDialog
K7ModernShowShareDialog
4 changes: 4 additions & 0 deletions NanaZip.Modern/NanaZip.Modern.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ EXTERN_C INT WINAPI K7ModernShowInformationDialog(
_In_opt_ LPCWSTR Title,
_In_opt_ LPCWSTR Text);

EXTERN_C INT WINAPI K7ModernShowShareDialog(
_In_opt_ HWND ParentWindowHandle,
_In_ std::vector<std::wstring> const& SharingFilePaths);

#endif // !NANAZIP_MODERN_EXPERIENCE
39 changes: 35 additions & 4 deletions NanaZip.Modern/NanaZip.Modern.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<Page Include="ProgressPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="SharePage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="SponsorPage.xaml">
<SubType>Designer</SubType>
</Page>
Expand Down Expand Up @@ -99,6 +102,10 @@
<DependentUpon>ProgressPage.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="SharePage.idl">
<DependentUpon>SharePage.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="SponsorPage.idl">
<DependentUpon>SponsorPage.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -129,7 +136,9 @@
<DependentUpon>InformationPage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="NanaZip.Modern.h" />
<ClInclude Include="NanaZip.Modern.h">
<DependentUpon>NanaZip.Modern.def</DependentUpon>
</ClInclude>
<ClInclude Include="pch.h" />
<ClInclude Include="App.h">
<DependentUpon>App.xaml</DependentUpon>
Expand All @@ -138,6 +147,13 @@
<DependentUpon>ProgressPage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="ShareExchange.h">
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="SharePage.h">
<DependentUpon>SharePage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="SponsorPage.h">
<DependentUpon>SponsorPage.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -167,15 +183,27 @@
<DependentUpon>InformationPage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="pch.cpp" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="pch.cpp">
<DependentUpon>pch.h</DependentUpon>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp">
<DependentUpon>NanaZip.Modern.def</DependentUpon>
</ClCompile>
<ClCompile Include="App.cpp">
<DependentUpon>App.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="ProgressPage.cpp">
<DependentUpon>ProgressPage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="ShareExchange.cpp">
<DependentUpon>ShareExchange.h</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="SharePage.cpp">
<DependentUpon>SharePage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="SponsorPage.cpp">
<DependentUpon>SponsorPage.xaml</DependentUpon>
<SubType>Code</SubType>
Expand All @@ -191,7 +219,9 @@
<ClCompile Include="AddressBar.cpp">
<DependentUpon>AddressBar.idl</DependentUpon>
</ClCompile>
<ClCompile Include="NanaZip.Modern.cpp" />
<ClCompile Include="NanaZip.Modern.cpp">
<DependentUpon>NanaZip.Modern.def</DependentUpon>
</ClCompile>
<ClCompile Include="StatusBar.cpp">
<DependentUpon>StatusBar.idl</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -247,6 +277,7 @@
<PRIResource Include="Strings\en\MainWindowToolBarPage.resw" />
<PRIResource Include="Strings\en\ProgressPage.resw" />
<PRIResource Include="Strings\en\SponsorPage.resw" />
<PRIResource Include="Strings\en\SharePage.resjson" />
<PRIResource Include="Strings\eo\InformationPage.resw" />
<PRIResource Include="Strings\eo\ProgressPage.resw" />
<PRIResource Include="Strings\es\InformationPage.resw" />
Expand Down
6 changes: 6 additions & 0 deletions NanaZip.Modern/NanaZip.Modern.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="AddressBar.cpp" />
<ClCompile Include="StatusBar.cpp" />
<ClCompile Include="ShareExchange.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="NanaZip.Modern.h" />
<ClInclude Include="AddressBar.h" />
<ClInclude Include="StatusBar.h" />
<ClInclude Include="ControlMacros.h" />
<ClInclude Include="ShareExchange.h" />
</ItemGroup>
<ItemGroup>
<None Include="Mile.Xaml.Unstaged.targets" />
Expand All @@ -33,6 +35,7 @@
<Page Include="StatusBarTemplate.xaml" />
<Page Include="InformationPage.xaml" />
<Page Include="ProgressPage.xaml" />
<Page Include="SharePage.xaml" />
</ItemGroup>
<ItemGroup>
<Filter Include="Strings">
Expand Down Expand Up @@ -799,6 +802,9 @@
<PRIResource Include="Strings\zh-Hans\ProgressPage.resw">
<Filter>Strings\zh-Hans</Filter>
</PRIResource>
<PRIResource Include="Strings\en\SharePage.resjson">
<Filter>Strings\en</Filter>
</PRIResource>
</ItemGroup>
<ItemGroup>
<Midl Include="AddressBar.idl" />
Expand Down
103 changes: 103 additions & 0 deletions NanaZip.Modern/ShareExchange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "ShareExchange.h"

#include <ShObjIdl_core.h>
#include <winrt/base.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
#include <winrt/Windows.Storage.h>

namespace winrt
{
using Windows::ApplicationModel::DataTransfer::DataTransferManager;
using Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs;
using Windows::ApplicationModel::DataTransfer::DataPackageOperation;
using Windows::Storage::IStorageItem;
using Windows::Storage::StorageFile;
}

K7ShareExchangeInterop::K7ShareExchangeInterop(
_In_ std::vector<std::wstring> const& SharingPaths) :
m_StdPaths(SharingPaths)
{
}

void K7ShareExchangeInterop::SharingByWindowsMessaging(
_In_opt_ HWND const& ParentWindowHandle)
{
if (this->m_MapiFiles.empty())
{
this->m_MapiFiles.reserve(m_StdPaths.size());
for (auto& Path : m_StdPaths)
{
MapiFileDescW Cache{};
Cache.nPosition = static_cast<ULONG>(-1);
Cache.lpszPathName = Path.data();
//Cache.lpszFileName =
this->m_MapiFiles.emplace_back(Cache);
}
}

static decltype(::MAPISendMailW)* volatile pMAPISendMailW{
reinterpret_cast<decltype(::MAPISendMailW)*>(
winrt::check_pointer(::GetProcAddress(
winrt::check_pointer(::LoadLibraryExW(
L"mapi32.dll",
nullptr,
LOAD_LIBRARY_SEARCH_SYSTEM32)),
"MAPISendMailW"))) };

MapiMessageW Message{};
Message.nFileCount = static_cast<ULONG>(this->m_MapiFiles.size());
Message.lpFiles = this->m_MapiFiles.data();

::EnableWindow(ParentWindowHandle, false);
pMAPISendMailW(
reinterpret_cast<LHANDLE>(nullptr),
reinterpret_cast<ULONG_PTR>(ParentWindowHandle),
&Message,
MAPI_DIALOG & MAPI_LOGON_UI & MAPI_FORCE_UNICODE,
0);
::EnableWindow(ParentWindowHandle, true);
}

void K7ShareExchangeInterop::SharingByDataTransferManager(
_In_ HWND const& ParentWindowHandle)
{
winrt::DataTransferManager Manager{ nullptr };
winrt::com_ptr<IDataTransferManagerInterop> Interop{
winrt::get_activation_factory
<winrt::DataTransferManager, IDataTransferManagerInterop>() };
winrt::check_hresult(Interop->GetForWindow(
ParentWindowHandle,
winrt::guid_of<winrt::DataTransferManager>(),
winrt::put_abi(Manager)));

if (Manager.IsSupported())
{
if (!this->m_WinRtFiles)
{
this->m_WinRtFiles =
winrt::single_threaded_vector
<winrt::Windows::Storage::IStorageItem>();
for (auto const& Path : this->m_StdPaths)
{
this->m_WinRtFiles.Append(
winrt::StorageFile::GetFileFromPathAsync(Path).get());
}
}

Manager.DataRequested(
[this](winrt::DataTransferManager const&,
winrt::DataRequestedEventArgs const& Args)
{
Args.Request().Data().Properties().Title(L"NanaZip");
Args.Request().Data().SetStorageItems(this->m_WinRtFiles);
Args.Request().Data().RequestedOperation(
winrt::DataPackageOperation::None);
});
winrt::check_hresult(Interop->ShowShareUIForWindow(
ParentWindowHandle));
}
}

33 changes: 33 additions & 0 deletions NanaZip.Modern/ShareExchange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <string>
#include <vector>

#include <Windows.h>
#include <MAPI.h>

#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Storage.h>

namespace winrt
{
using Windows::Foundation::Collections::IVector;
using Windows::Storage::IStorageItem;
}

class K7ShareExchangeInterop
{
private:
std::vector<std::wstring> m_StdPaths;
std::vector<MapiFileDescW> m_MapiFiles;
winrt::IVector<winrt::IStorageItem> m_WinRtFiles{ nullptr };

public:
K7ShareExchangeInterop(_In_ std::vector<std::wstring> const& SharingPaths);

void SharingByWindowsMessaging(
_In_opt_ HWND const& ParentWindowHandle);

void SharingByDataTransferManager(
_In_ HWND const& ParentWindowHandle);
};
45 changes: 45 additions & 0 deletions NanaZip.Modern/SharePage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "pch.h"
#include "SharePage.h"
#if __has_include("SharePage.g.cpp")
#include "SharePage.g.cpp"
#endif

using namespace winrt;
using namespace Windows::UI::Xaml;

namespace winrt::NanaZip::Modern::implementation
{
SharePage::SharePage(
_In_ HWND WindowHandle,
_In_ std::vector<std::wstring> const& SharingFilePaths) :
m_WindowHandle(WindowHandle),
m_SharingInterop(SharingFilePaths){ }

void SharePage::InitializeComponent()
{
SharePageT::InitializeComponent();

this->ShareButton().Click([this](
winrt::IInspectable const&,
winrt::RoutedEventArgs const&)
{
this->m_SharingInterop.SharingByDataTransferManager(
this->m_WindowHandle);
});

this->EmailButton().Click([this](
winrt::IInspectable const&,
winrt::RoutedEventArgs const&)
{
this->m_SharingInterop.SharingByWindowsMessaging(
this->m_WindowHandle);
});

this->CancelButton().Click([this](
winrt::IInspectable const&,
winrt::RoutedEventArgs const&)
{
::check_bool(::DestroyWindow(this->m_WindowHandle));
});
}
}
Loading
Loading