teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/21 10:11

投稿

TN8001
TN8001

スコア10111

answer CHANGED
@@ -1,24 +1,29 @@
1
- UWPで作るのでしたら、こちらが参考になるでしょう。
2
- [Lock screen personalization sample - Code Samples | Microsoft Docs](https://docs.microsoft.com/en-us/samples/microsoft/windows-universal-samples/personalization/)
3
-
4
- それ以外で作る場合は、NuGetで`Microsoft.Windows.SDK.Contracts`を入れれば簡単に使えます。
5
- ```C#
6
- // 要NuGet Microsoft.Windows.SDK.Contracts
7
-
8
- using System;
9
- using System.Threading.Tasks;
10
- using Windows.Storage;
11
- using Windows.System.UserProfile;
12
-
13
- namespace Questions254323
14
- {
15
- class Program
16
- {
17
- static async Task Main()
18
- {
19
- var file = await StorageFile.GetFileFromPathAsync(@"C:\Windows\Web\Screen\img101.png");
20
- await LockScreen.SetImageFileAsync(file);
21
- }
22
- }
23
- }
24
- ```
1
+ UWPで作るのでしたら、こちらが参考になるでしょう。
2
+ [Lock screen personalization sample - Code Samples | Microsoft Docs](https://docs.microsoft.com/en-us/samples/microsoft/windows-universal-samples/personalization/)
3
+
4
+ それ以外で作る場合は、NuGetで`Microsoft.Windows.SDK.Contracts`を入れれば簡単に使えます。
5
+
6
+ .NET 6 以降ではさらに簡単になっています(TFMを変えるだけ)
7
+ [デスクトップ アプリで Windows ランタイム API を呼び出す - Windows apps | Microsoft Learn](https://learn.microsoft.com/ja-jp/windows/apps/desktop/modernize/desktop-to-uwp-enhance)
8
+
9
+ ```cs
10
+ using System;
11
+ using System.Threading.Tasks;
12
+ using Windows.Storage;
13
+ using Windows.System.UserProfile;
14
+
15
+ namespace Questions254323
16
+ {
17
+ class Program
18
+ {
19
+ static async Task Main()
20
+ {
21
+ var file = await StorageFile.GetFileFromPathAsync(@"C:\Windows\Web\Screen\img101.png");
22
+ await LockScreen.SetImageFileAsync(file);
23
+ }
24
+ }
25
+ }
26
+ ```
27
+ [StorageFile.GetFileFromPathAsync(String) メソッド (Windows.Storage) - Windows UWP applications | Microsoft Learn](https://learn.microsoft.com/ja-jp/uwp/api/windows.storage.storagefile.getfilefrompathasync)
28
+
29
+ [LockScreen.SetImageFileAsync(IStorageFile) メソッド (Windows.System.UserProfile) - Windows UWP applications | Microsoft Learn](https://learn.microsoft.com/ja-jp/uwp/api/windows.system.userprofile.lockscreen.setimagefileasync)