Skip to content

Commit 4ea4342

Browse files
author
Committer
committed
ShareTarget & SharePage
1 parent d57971b commit 4ea4342

File tree

13 files changed

+547
-89
lines changed

13 files changed

+547
-89
lines changed

NanaZip.Modern/NanaZip.Modern.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "SponsorPage.h"
1919
#include "AboutPage.h"
2020
#include "InformationPage.h"
21+
#include "SharePage.h"
2122

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

284285
return Result;
285286
}
287+
288+
EXTERN_C INT WINAPI K7ModernShowShareDialog(
289+
_In_opt_ HWND ParentWindowHandle,
290+
_In_ std::vector<std::wstring> const& SharingFilePaths)
291+
{
292+
HWND WindowHandle =
293+
winrt::check_pointer(::K7ModernCreateXamlDialog(ParentWindowHandle));
294+
295+
using Interface =
296+
winrt::NanaZip::Modern::SharePage;
297+
using Implementation =
298+
winrt::NanaZip::Modern::implementation::SharePage;
299+
300+
Interface Window = winrt::make<Implementation>(
301+
WindowHandle,
302+
SharingFilePaths);
303+
304+
winrt::check_hresult(::MileXamlSetTransparentBackgroundAttribute(true));
305+
306+
int Result = ::K7ModernShowXamlDialog(
307+
WindowHandle,
308+
500,
309+
375,
310+
winrt::detach_abi(Window),
311+
ParentWindowHandle);
312+
313+
return Result;
314+
}

NanaZip.Modern/NanaZip.Modern.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ EXPORTS
55
K7ModernShowSponsorDialog
66
K7ModernShowAboutDialog
77
K7ModernCreateMainWindowToolBarPage
8-
K7ModernShowInformationDialog
8+
K7ModernShowInformationDialog
9+
K7ModernShowShareDialog

NanaZip.Modern/NanaZip.Modern.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ EXTERN_C INT WINAPI K7ModernShowInformationDialog(
2929
_In_opt_ LPCWSTR Title,
3030
_In_opt_ LPCWSTR Text);
3131

32+
EXTERN_C INT WINAPI K7ModernShowShareDialog(
33+
_In_opt_ HWND ParentWindowHandle,
34+
_In_ std::vector<std::wstring> const& SharingFilePaths);
35+
3236
#endif // !NANAZIP_MODERN_EXPERIENCE

NanaZip.Modern/NanaZip.Modern.vcxproj

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<Page Include="ProgressPage.xaml">
7171
<SubType>Designer</SubType>
7272
</Page>
73+
<Page Include="SharePage.xaml">
74+
<SubType>Designer</SubType>
75+
</Page>
7376
<Page Include="SponsorPage.xaml">
7477
<SubType>Designer</SubType>
7578
</Page>
@@ -99,6 +102,10 @@
99102
<DependentUpon>ProgressPage.xaml</DependentUpon>
100103
<SubType>Code</SubType>
101104
</Midl>
105+
<Midl Include="SharePage.idl">
106+
<DependentUpon>SharePage.xaml</DependentUpon>
107+
<SubType>Code</SubType>
108+
</Midl>
102109
<Midl Include="SponsorPage.idl">
103110
<DependentUpon>SponsorPage.xaml</DependentUpon>
104111
<SubType>Code</SubType>
@@ -129,7 +136,9 @@
129136
<DependentUpon>InformationPage.xaml</DependentUpon>
130137
<SubType>Code</SubType>
131138
</ClInclude>
132-
<ClInclude Include="NanaZip.Modern.h" />
139+
<ClInclude Include="NanaZip.Modern.h">
140+
<DependentUpon>NanaZip.Modern.def</DependentUpon>
141+
</ClInclude>
133142
<ClInclude Include="pch.h" />
134143
<ClInclude Include="App.h">
135144
<DependentUpon>App.xaml</DependentUpon>
@@ -138,6 +147,13 @@
138147
<DependentUpon>ProgressPage.xaml</DependentUpon>
139148
<SubType>Code</SubType>
140149
</ClInclude>
150+
<ClInclude Include="ShareExchange.h">
151+
<SubType>Code</SubType>
152+
</ClInclude>
153+
<ClInclude Include="SharePage.h">
154+
<DependentUpon>SharePage.xaml</DependentUpon>
155+
<SubType>Code</SubType>
156+
</ClInclude>
141157
<ClInclude Include="SponsorPage.h">
142158
<DependentUpon>SponsorPage.xaml</DependentUpon>
143159
<SubType>Code</SubType>
@@ -167,15 +183,27 @@
167183
<DependentUpon>InformationPage.xaml</DependentUpon>
168184
<SubType>Code</SubType>
169185
</ClCompile>
170-
<ClCompile Include="pch.cpp" />
171-
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
186+
<ClCompile Include="pch.cpp">
187+
<DependentUpon>pch.h</DependentUpon>
188+
</ClCompile>
189+
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp">
190+
<DependentUpon>NanaZip.Modern.def</DependentUpon>
191+
</ClCompile>
172192
<ClCompile Include="App.cpp">
173193
<DependentUpon>App.xaml</DependentUpon>
174194
</ClCompile>
175195
<ClCompile Include="ProgressPage.cpp">
176196
<DependentUpon>ProgressPage.xaml</DependentUpon>
177197
<SubType>Code</SubType>
178198
</ClCompile>
199+
<ClCompile Include="ShareExchange.cpp">
200+
<DependentUpon>ShareExchange.h</DependentUpon>
201+
<SubType>Code</SubType>
202+
</ClCompile>
203+
<ClCompile Include="SharePage.cpp">
204+
<DependentUpon>SharePage.xaml</DependentUpon>
205+
<SubType>Code</SubType>
206+
</ClCompile>
179207
<ClCompile Include="SponsorPage.cpp">
180208
<DependentUpon>SponsorPage.xaml</DependentUpon>
181209
<SubType>Code</SubType>
@@ -191,7 +219,9 @@
191219
<ClCompile Include="AddressBar.cpp">
192220
<DependentUpon>AddressBar.idl</DependentUpon>
193221
</ClCompile>
194-
<ClCompile Include="NanaZip.Modern.cpp" />
222+
<ClCompile Include="NanaZip.Modern.cpp">
223+
<DependentUpon>NanaZip.Modern.def</DependentUpon>
224+
</ClCompile>
195225
<ClCompile Include="StatusBar.cpp">
196226
<DependentUpon>StatusBar.idl</DependentUpon>
197227
<SubType>Code</SubType>
@@ -247,6 +277,7 @@
247277
<PRIResource Include="Strings\en\MainWindowToolBarPage.resw" />
248278
<PRIResource Include="Strings\en\ProgressPage.resw" />
249279
<PRIResource Include="Strings\en\SponsorPage.resw" />
280+
<PRIResource Include="Strings\en\SharePage.resjson" />
250281
<PRIResource Include="Strings\eo\InformationPage.resw" />
251282
<PRIResource Include="Strings\eo\ProgressPage.resw" />
252283
<PRIResource Include="Strings\es\InformationPage.resw" />

NanaZip.Modern/NanaZip.Modern.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
1313
<ClCompile Include="AddressBar.cpp" />
1414
<ClCompile Include="StatusBar.cpp" />
15+
<ClCompile Include="ShareExchange.cpp" />
1516
</ItemGroup>
1617
<ItemGroup>
1718
<ClInclude Include="pch.h" />
1819
<ClInclude Include="NanaZip.Modern.h" />
1920
<ClInclude Include="AddressBar.h" />
2021
<ClInclude Include="StatusBar.h" />
2122
<ClInclude Include="ControlMacros.h" />
23+
<ClInclude Include="ShareExchange.h" />
2224
</ItemGroup>
2325
<ItemGroup>
2426
<None Include="Mile.Xaml.Unstaged.targets" />
@@ -33,6 +35,7 @@
3335
<Page Include="StatusBarTemplate.xaml" />
3436
<Page Include="InformationPage.xaml" />
3537
<Page Include="ProgressPage.xaml" />
38+
<Page Include="SharePage.xaml" />
3639
</ItemGroup>
3740
<ItemGroup>
3841
<Filter Include="Strings">
@@ -799,6 +802,9 @@
799802
<PRIResource Include="Strings\zh-Hans\ProgressPage.resw">
800803
<Filter>Strings\zh-Hans</Filter>
801804
</PRIResource>
805+
<PRIResource Include="Strings\en\SharePage.resjson">
806+
<Filter>Strings\en</Filter>
807+
</PRIResource>
802808
</ItemGroup>
803809
<ItemGroup>
804810
<Midl Include="AddressBar.idl" />

NanaZip.Modern/ShareExchange.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "ShareExchange.h"
2+
3+
#include <ShObjIdl_core.h>
4+
#include <winrt/base.h>
5+
#include <winrt/Windows.Foundation.h>
6+
#include <winrt/Windows.Foundation.Collections.h>
7+
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
8+
#include <winrt/Windows.Storage.h>
9+
10+
namespace winrt
11+
{
12+
using Windows::ApplicationModel::DataTransfer::DataTransferManager;
13+
using Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs;
14+
using Windows::ApplicationModel::DataTransfer::DataPackageOperation;
15+
using Windows::Storage::IStorageItem;
16+
using Windows::Storage::StorageFile;
17+
}
18+
19+
K7ShareExchangeInterop::K7ShareExchangeInterop(
20+
_In_ std::vector<std::wstring> const& SharingPaths) :
21+
m_StdPaths(SharingPaths)
22+
{
23+
}
24+
25+
void K7ShareExchangeInterop::SharingByWindowsMessaging(
26+
_In_opt_ HWND const& ParentWindowHandle)
27+
{
28+
if (this->m_MapiFiles.empty())
29+
{
30+
this->m_MapiFiles.reserve(m_StdPaths.size());
31+
for (auto& Path : m_StdPaths)
32+
{
33+
MapiFileDescW Cache{};
34+
Cache.nPosition = static_cast<ULONG>(-1);
35+
Cache.lpszPathName = Path.data();
36+
//Cache.lpszFileName =
37+
this->m_MapiFiles.emplace_back(Cache);
38+
}
39+
}
40+
41+
static decltype(::MAPISendMailW)* volatile pMAPISendMailW{
42+
reinterpret_cast<decltype(::MAPISendMailW)*>(
43+
winrt::check_pointer(::GetProcAddress(
44+
winrt::check_pointer(::LoadLibraryExW(
45+
L"mapi32.dll",
46+
nullptr,
47+
LOAD_LIBRARY_SEARCH_SYSTEM32)),
48+
"MAPISendMailW"))) };
49+
50+
MapiMessageW Message{};
51+
Message.nFileCount = static_cast<ULONG>(this->m_MapiFiles.size());
52+
Message.lpFiles = this->m_MapiFiles.data();
53+
54+
::EnableWindow(ParentWindowHandle, false);
55+
pMAPISendMailW(
56+
reinterpret_cast<LHANDLE>(nullptr),
57+
reinterpret_cast<ULONG_PTR>(ParentWindowHandle),
58+
&Message,
59+
MAPI_DIALOG & MAPI_LOGON_UI & MAPI_FORCE_UNICODE,
60+
0);
61+
::EnableWindow(ParentWindowHandle, true);
62+
}
63+
64+
void K7ShareExchangeInterop::SharingByDataTransferManager(
65+
_In_ HWND const& ParentWindowHandle)
66+
{
67+
winrt::DataTransferManager Manager{ nullptr };
68+
winrt::com_ptr<IDataTransferManagerInterop> Interop{
69+
winrt::get_activation_factory
70+
<winrt::DataTransferManager, IDataTransferManagerInterop>() };
71+
winrt::check_hresult(Interop->GetForWindow(
72+
ParentWindowHandle,
73+
winrt::guid_of<winrt::DataTransferManager>(),
74+
winrt::put_abi(Manager)));
75+
76+
if (Manager.IsSupported())
77+
{
78+
if (!this->m_WinRtFiles)
79+
{
80+
this->m_WinRtFiles =
81+
winrt::single_threaded_vector
82+
<winrt::Windows::Storage::IStorageItem>();
83+
for (auto const& Path : this->m_StdPaths)
84+
{
85+
this->m_WinRtFiles.Append(
86+
winrt::StorageFile::GetFileFromPathAsync(Path).get());
87+
}
88+
}
89+
90+
Manager.DataRequested(
91+
[this](winrt::DataTransferManager const&,
92+
winrt::DataRequestedEventArgs const& Args)
93+
{
94+
Args.Request().Data().Properties().Title(L"NanaZip");
95+
Args.Request().Data().SetStorageItems(this->m_WinRtFiles);
96+
Args.Request().Data().RequestedOperation(
97+
winrt::DataPackageOperation::None);
98+
});
99+
winrt::check_hresult(Interop->ShowShareUIForWindow(
100+
ParentWindowHandle));
101+
}
102+
}
103+

NanaZip.Modern/ShareExchange.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
6+
#include <Windows.h>
7+
#include <MAPI.h>
8+
9+
#include <winrt/Windows.Foundation.Collections.h>
10+
#include <winrt/Windows.Storage.h>
11+
12+
namespace winrt
13+
{
14+
using Windows::Foundation::Collections::IVector;
15+
using Windows::Storage::IStorageItem;
16+
}
17+
18+
class K7ShareExchangeInterop
19+
{
20+
private:
21+
std::vector<std::wstring> m_StdPaths;
22+
std::vector<MapiFileDescW> m_MapiFiles;
23+
winrt::IVector<winrt::IStorageItem> m_WinRtFiles{ nullptr };
24+
25+
public:
26+
K7ShareExchangeInterop(_In_ std::vector<std::wstring> const& SharingPaths);
27+
28+
void SharingByWindowsMessaging(
29+
_In_opt_ HWND const& ParentWindowHandle);
30+
31+
void SharingByDataTransferManager(
32+
_In_ HWND const& ParentWindowHandle);
33+
};

NanaZip.Modern/SharePage.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "pch.h"
2+
#include "SharePage.h"
3+
#if __has_include("SharePage.g.cpp")
4+
#include "SharePage.g.cpp"
5+
#endif
6+
7+
using namespace winrt;
8+
using namespace Windows::UI::Xaml;
9+
10+
namespace winrt::NanaZip::Modern::implementation
11+
{
12+
SharePage::SharePage(
13+
_In_ HWND WindowHandle,
14+
_In_ std::vector<std::wstring> const& SharingFilePaths) :
15+
m_WindowHandle(WindowHandle),
16+
m_SharingInterop(SharingFilePaths){ }
17+
18+
void SharePage::InitializeComponent()
19+
{
20+
SharePageT::InitializeComponent();
21+
22+
this->ShareButton().Click([this](
23+
winrt::IInspectable const&,
24+
winrt::RoutedEventArgs const&)
25+
{
26+
this->m_SharingInterop.SharingByDataTransferManager(
27+
this->m_WindowHandle);
28+
});
29+
30+
this->EmailButton().Click([this](
31+
winrt::IInspectable const&,
32+
winrt::RoutedEventArgs const&)
33+
{
34+
this->m_SharingInterop.SharingByWindowsMessaging(
35+
this->m_WindowHandle);
36+
});
37+
38+
this->CancelButton().Click([this](
39+
winrt::IInspectable const&,
40+
winrt::RoutedEventArgs const&)
41+
{
42+
::check_bool(::DestroyWindow(this->m_WindowHandle));
43+
});
44+
}
45+
}

0 commit comments

Comments
 (0)