Skip to content

Commit 118d53b

Browse files
committed
Windows 11 Version 21H2 - June 2023 Samples Update
* BluetoothLE: Protect against bad device thumbnails #905 * BarcodeScanner: Add software trigger support to scenario 1 #681 * New: NetworkConnectivity * Archived: BarcodeScanner VB and C++/CX
1 parent ad9a0c4 commit 118d53b

File tree

67 files changed

+2404
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2404
-20
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,21 +509,24 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
509509
<tr>
510510
<td><a href="Samples/Json">JSON</a></td>
511511
<td><a href="Samples/MobileBroadband">Mobile broadband</a></td>
512-
<td><a href="Samples/RadioManager">Radios</a></td>
512+
<td><a href="Samples/NetworkConnectivity">Network connectivity</a></td>
513513
</tr>
514514
<tr>
515+
<td><a href="Samples/RadioManager">Radios</a></td>
515516
<td><a href="Samples/SocketActivityStreamSocket">Socket activity trigger stream socket</a></td>
516517
<td><a href="Samples/StreamSocket">StreamSocket</a></td>
517-
<td><a href="Samples/Syndication">Syndication</a></td>
518518
</tr>
519519
<tr>
520+
<td><a href="Samples/Syndication">Syndication</a></td>
520521
<td><a href="Samples/UssdProtcol">USSD protocol</a></td>
521522
<td><a href="Samples/WebSocket">WebSocket</a></td>
522-
<td><a href="Samples/WiFiDirect">Wi-Fi Direct</a></td>
523523
</tr>
524524
<tr>
525+
<td><a href="Samples/WiFiDirect">Wi-Fi Direct</a></td>
525526
<td><a href="Samples/WiFiDirectServices">Wi-Fi Direct services</a></td>
526527
<td><a href="Samples/HotspotAuthentication">Wi-Fi hotspot authentication</a></td>
528+
</tr>
529+
<tr>
527530
<td><a href="Samples/WiFiScan">Wi-Fi scanning</a></td>
528531
</tr>
529532
</table>

Samples/BarcodeScanner/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ page_type: sample
33
languages:
44
- csharp
55
- cpp
6-
- cppcx
7-
- vb
86
- cppwinrt
97
products:
108
- windows
@@ -95,7 +93,7 @@ To obtain information about Microsoft Visual Studio and the tools for developing
9593

9694
### Related samples
9795

98-
* [BarcodeScanner sample](/archived/BarcodeScanner/) for JavaScript (archived)
96+
* [BarcodeScanner sample](/archived/BarcodeScanner/) for JavaScript, Visual Basic, and C++/CX (archived)
9997

10098
## System requirements
10199

Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace winrt::SDKTemplate::implementation
6666
// reset the button state
6767
ScenarioEndScanButton().IsEnabled(false);
6868
ScenarioStartScanButton().IsEnabled(true);
69+
ScenarioSoftwareTriggerPanel().Visibility(Visibility::Collapsed);
6970
}
7071
}
7172

@@ -102,6 +103,14 @@ namespace winrt::SDKTemplate::implementation
102103

103104
m_rootPage.NotifyUser(L"Ready to scan. Device ID: " + m_scanner.DeviceId(), NotifyType::StatusMessage);
104105
ScenarioEndScanButton().IsEnabled(true);
106+
107+
// If the scanner is a software scanner, show the software trigger buttons.
108+
if (!m_scanner.VideoDeviceId().empty())
109+
{
110+
ScenarioSoftwareTriggerPanel().Visibility(Visibility::Visible);
111+
ScenarioStartTriggerButton().IsEnabled(true);
112+
ScenarioStopTriggerButton().IsEnabled(false);
113+
}
105114
}
106115
else
107116
{
@@ -149,4 +158,18 @@ namespace winrt::SDKTemplate::implementation
149158
{
150159
ResetTheScenarioState();
151160
}
161+
162+
fire_and_forget Scenario1_BasicFunctionality::ScenarioStartTriggerButton_Click(IInspectable const&, RoutedEventArgs const&)
163+
{
164+
ScenarioStartTriggerButton().IsEnabled(false);
165+
co_await m_claimedScanner.StartSoftwareTriggerAsync();
166+
ScenarioStopTriggerButton().IsEnabled(true);
167+
}
168+
169+
fire_and_forget Scenario1_BasicFunctionality::ScenarioStopTriggerButton_Click(IInspectable const&, RoutedEventArgs const&)
170+
{
171+
ScenarioStopTriggerButton().IsEnabled(false);
172+
co_await m_claimedScanner.StopSoftwareTriggerAsync();
173+
ScenarioStartTriggerButton().IsEnabled(true);
174+
}
152175
}

Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace winrt::SDKTemplate::implementation
2121

2222
fire_and_forget ScenarioStartScanButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
2323
void ScenarioEndScanButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
24+
fire_and_forget ScenarioStartTriggerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
25+
fire_and_forget ScenarioStopTriggerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
2426

2527
void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
2628
void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);

Samples/BarcodeScanner/cs/Scenario1_BasicFunctionality.xaml.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs
9595

9696
rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
9797
ScenarioEndScanButton.IsEnabled = true;
98+
99+
// If the scanner is a software scanner, show the software trigger buttons.
100+
if (!string.IsNullOrEmpty(scanner.VideoDeviceId))
101+
{
102+
ScenarioSoftwareTriggerPanel.Visibility = Visibility.Visible;
103+
ScenarioStartTriggerButton.IsEnabled = true;
104+
ScenarioStopTriggerButton.IsEnabled = false;
105+
}
98106
}
99107
else
100108
{
@@ -172,6 +180,7 @@ private void ResetTheScenarioState()
172180
// reset the button state
173181
ScenarioEndScanButton.IsEnabled = false;
174182
ScenarioStartScanButton.IsEnabled = true;
183+
ScenarioSoftwareTriggerPanel.Visibility = Visibility.Collapsed;
175184
}
176185
}
177186

@@ -187,5 +196,26 @@ private void ScenarioEndScanButton_Click(object sender, RoutedEventArgs e)
187196
this.ResetTheScenarioState();
188197
}
189198

199+
/// <summary>
200+
/// Event handler for Start Software Trigger button click.
201+
/// Presses the software trigger button.
202+
/// </summary>
203+
private async void ScenarioStartTriggerButton_Click(object sender, RoutedEventArgs e)
204+
{
205+
ScenarioStartTriggerButton.IsEnabled = false;
206+
await claimedScanner.StartSoftwareTriggerAsync();
207+
ScenarioStopTriggerButton.IsEnabled = true;
208+
}
209+
210+
/// <summary>
211+
/// Event handler for Stop Software Trigger button click.
212+
/// Releases the software trigger button.
213+
/// </summary>
214+
private async void ScenarioStopTriggerButton_Click(object sender, RoutedEventArgs e)
215+
{
216+
ScenarioStopTriggerButton.IsEnabled = false;
217+
await claimedScanner.StopSoftwareTriggerAsync();
218+
ScenarioStartTriggerButton.IsEnabled = true;
219+
}
190220
}
191221
}

Samples/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
2323
<Grid x:Name="RootGrid" Margin="12,20,12,12">
2424
<Grid.RowDefinitions>
25+
<RowDefinition Height="*"/>
2526
<RowDefinition Height="*"/>
2627
<RowDefinition Height="Auto"/>
2728
</Grid.RowDefinitions>
@@ -40,7 +41,13 @@
4041
<Button x:Name="ScenarioEndScanButton" Content="End Scanning" Margin="0,0,10,0" Click="ScenarioEndScanButton_Click"/>
4142
</StackPanel>
4243

43-
<Grid Grid.Row="2" Margin="0,0,0,20">
44+
<StackPanel x:Name="ScenarioSoftwareTriggerPanel" Orientation="Horizontal" Margin="5,5,5,20" Visibility="Collapsed" Grid.Row="2">
45+
<Button x:Name="ScenarioStartTriggerButton" Content="Start Software Trigger" Margin="0,0,10,0" Click="ScenarioStartTriggerButton_Click"/>
46+
<Button x:Name="ScenarioStopTriggerButton" Content="Stop Software Trigger" Margin="0,0,10,0" Click="ScenarioStopTriggerButton_Click"/>
47+
</StackPanel>
48+
49+
50+
<Grid Grid.Row="3" Margin="0,0,0,20">
4451
<Grid.ColumnDefinitions>
4552
<ColumnDefinition Width="Auto"/>
4653
<ColumnDefinition Width="200"/>
@@ -59,12 +66,6 @@
5966
</Grid>
6067
</StackPanel>
6168
</ScrollViewer>
62-
63-
<!-- Status Block for providing messages to the user. Use the
64-
NotifyUser() method to populate the message -->
65-
<Border x:Name="ErrorBorder" Background="Red" Grid.Row="1"/>
66-
<TextBlock x:Name="StatusBlock" Grid.Row="1" Margin="12, 10, 12, 10" Visibility="Collapsed"/>
67-
6869
</Grid>
6970
</Grid>
7071
</Page>

Samples/BluetoothLE/cppwinrt/BluetoothLEDeviceDisplay.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "pch.h"
1+
#include "pch.h"
22
#include "BluetoothLEDeviceDisplay.h"
33
#include "BluetoothLEDeviceDisplay.g.cpp"
44

@@ -55,9 +55,16 @@ namespace winrt::SDKTemplate::implementation
5555
fire_and_forget BluetoothLEDeviceDisplay::UpdateGlyphBitmapImage()
5656
{
5757
auto lifetime = get_strong();
58-
DeviceThumbnail deviceThumbnail = co_await m_deviceInformation.GetGlyphThumbnailAsync();
5958
BitmapImage glyphBitmapImage;
60-
co_await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
59+
try
60+
{
61+
DeviceThumbnail deviceThumbnail = co_await m_deviceInformation.GetGlyphThumbnailAsync();
62+
co_await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
63+
}
64+
catch (...)
65+
{
66+
// Something went wrong getting or decoding the device glyph.
67+
}
6168
m_glyphBitmapImage = glyphBitmapImage;
6269
OnPropertyChanged(L"GlyphBitmapImage");
6370
}

Samples/BluetoothLE/cs/DisplayHelpers.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using Windows.Devices.Bluetooth.GenericAttributeProfile;
@@ -115,9 +115,16 @@ public void Update(DeviceInformationUpdate deviceInfoUpdate)
115115

116116
private async void UpdateGlyphBitmapImage()
117117
{
118-
DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
119118
var glyphBitmapImage = new BitmapImage();
120-
await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
119+
try
120+
{
121+
DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
122+
await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
123+
}
124+
catch (Exception)
125+
{
126+
// Something went wrong getting or decoding the device glyph.
127+
}
121128
GlyphBitmapImage = glyphBitmapImage;
122129
OnPropertyChanged("GlyphBitmapImage");
123130
}
@@ -317,4 +324,4 @@ public static byte[] ReadBufferToBytes(IBuffer buffer)
317324
return data;
318325
}
319326
}
320-
}
327+
}

Samples/NetworkConnectivity/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- csharp
5+
- cpp
6+
- cppwinrt
7+
products:
8+
- windows
9+
- windows-uwp
10+
urlFragment: NetworkingConnectivity
11+
extendedZipContent:
12+
- path: SharedContent
13+
target: SharedContent
14+
- path: LICENSE
15+
target: LICENSE
16+
description: "Shows how to query network connectivity and respond to network connectivity changes."
17+
---
18+
19+
# NetworkingConnectivity sample
20+
21+
Demonstrates how to use the NetworkInformation and related classes
22+
to determine the network connectivity status,
23+
and shows how to use this information to determine
24+
when to attempt to connect to the Internet.
25+
26+
Apps can use the NetworkInformation and related Windows Runtime classes
27+
to check the network connectivity status before attempting to connect to the Internet.
28+
These class simplify the complex task of determining connectivity for various network configurations.
29+
These checks are not strictly required because higher-level APIs (such as HttpClient)
30+
report insufficient network connectivity through failures/results at the point of connection.
31+
32+
This sample also demonstrates how to register for network connectivity change events.
33+
Apps can subscribe to the events instead of building their
34+
own logic to track network connectivity changes.
35+
36+
> **Note:** This sample is part of a large collection of UWP feature samples.
37+
> You can download this sample as a standalone ZIP file
38+
> [from docs.microsoft.com](https://docs.microsoft.com/samples/microsoft/windows-universal-samples/networkingconnectivity/),
39+
> or you can download the entire collection as a single
40+
> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/main.zip), but be
41+
> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file,
42+
> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
43+
> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center.
44+
45+
46+
### Declaring the internetClient capability
47+
48+
This sample requires that internetClient capability be set in the *Package.appxmanifest* file to allow the app to access the Internet connection at runtime.
49+
The capability can be set in the app manifest using Microsoft Visual Studio.
50+
51+
## System requirements
52+
53+
* Windows 10
54+
55+
## Build the sample
56+
57+
1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
58+
2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**.
59+
3. Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio Solution (.sln) file.
60+
4. Press Ctrl+Shift+B or select **Build** \> **Build Solution**.
61+
62+
## Run the sample
63+
64+
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
65+
66+
### Deploying the sample
67+
68+
- Select Build > Deploy Solution.
69+
70+
### Debugging and running the sample
71+
72+
- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or select Debug > Start Without Debugging.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33516.290
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkConnectivity", "NetworkConnectivity.vcxproj", "{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|ARM64 = Debug|ARM64
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|ARM64 = Release|ARM64
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.ActiveCfg = Debug|ARM64
19+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.Build.0 = Debug|ARM64
20+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.Deploy.0 = Debug|ARM64
21+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.ActiveCfg = Debug|x64
22+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.Build.0 = Debug|x64
23+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.Deploy.0 = Debug|x64
24+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.ActiveCfg = Debug|Win32
25+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.Build.0 = Debug|Win32
26+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.Deploy.0 = Debug|Win32
27+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.ActiveCfg = Release|ARM64
28+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.Build.0 = Release|ARM64
29+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.Deploy.0 = Release|ARM64
30+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.ActiveCfg = Release|x64
31+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.Build.0 = Release|x64
32+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.Deploy.0 = Release|x64
33+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.ActiveCfg = Release|Win32
34+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.Build.0 = Release|Win32
35+
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.Deploy.0 = Release|Win32
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {77D722D2-6DBF-402D-9B3B-6473BA169D27}
42+
EndGlobalSection
43+
EndGlobal

0 commit comments

Comments
 (0)