Skip to content

Commit

Permalink
Windows 11 Version 21H2 - June 2023 Samples Update
Browse files Browse the repository at this point in the history
* BluetoothLE:  Protect against bad device thumbnails #905
* BarcodeScanner: Add software trigger support to scenario 1 #681
* New: NetworkConnectivity
* Archived: BarcodeScanner VB and C++/CX
  • Loading branch information
oldnewthing committed Jun 15, 2023
1 parent ad9a0c4 commit 118d53b
Show file tree
Hide file tree
Showing 67 changed files with 2,404 additions and 20 deletions.
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -509,21 +509,24 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
<tr>
<td><a href="Samples/Json">JSON</a></td>
<td><a href="Samples/MobileBroadband">Mobile broadband</a></td>
<td><a href="Samples/RadioManager">Radios</a></td>
<td><a href="Samples/NetworkConnectivity">Network connectivity</a></td>
</tr>
<tr>
<td><a href="Samples/RadioManager">Radios</a></td>
<td><a href="Samples/SocketActivityStreamSocket">Socket activity trigger stream socket</a></td>
<td><a href="Samples/StreamSocket">StreamSocket</a></td>
<td><a href="Samples/Syndication">Syndication</a></td>
</tr>
<tr>
<td><a href="Samples/Syndication">Syndication</a></td>
<td><a href="Samples/UssdProtcol">USSD protocol</a></td>
<td><a href="Samples/WebSocket">WebSocket</a></td>
<td><a href="Samples/WiFiDirect">Wi-Fi Direct</a></td>
</tr>
<tr>
<td><a href="Samples/WiFiDirect">Wi-Fi Direct</a></td>
<td><a href="Samples/WiFiDirectServices">Wi-Fi Direct services</a></td>
<td><a href="Samples/HotspotAuthentication">Wi-Fi hotspot authentication</a></td>
</tr>
<tr>
<td><a href="Samples/WiFiScan">Wi-Fi scanning</a></td>
</tr>
</table>
Expand Down
4 changes: 1 addition & 3 deletions Samples/BarcodeScanner/README.md
Expand Up @@ -3,8 +3,6 @@ page_type: sample
languages:
- csharp
- cpp
- cppcx
- vb
- cppwinrt
products:
- windows
Expand Down Expand Up @@ -95,7 +93,7 @@ To obtain information about Microsoft Visual Studio and the tools for developing

### Related samples

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

## System requirements

Expand Down
23 changes: 23 additions & 0 deletions Samples/BarcodeScanner/cppwinrt/Scenario1_BasicFunctionality.cpp
Expand Up @@ -66,6 +66,7 @@ namespace winrt::SDKTemplate::implementation
// reset the button state
ScenarioEndScanButton().IsEnabled(false);
ScenarioStartScanButton().IsEnabled(true);
ScenarioSoftwareTriggerPanel().Visibility(Visibility::Collapsed);
}
}

Expand Down Expand Up @@ -102,6 +103,14 @@ namespace winrt::SDKTemplate::implementation

m_rootPage.NotifyUser(L"Ready to scan. Device ID: " + m_scanner.DeviceId(), NotifyType::StatusMessage);
ScenarioEndScanButton().IsEnabled(true);

// If the scanner is a software scanner, show the software trigger buttons.
if (!m_scanner.VideoDeviceId().empty())
{
ScenarioSoftwareTriggerPanel().Visibility(Visibility::Visible);
ScenarioStartTriggerButton().IsEnabled(true);
ScenarioStopTriggerButton().IsEnabled(false);
}
}
else
{
Expand Down Expand Up @@ -149,4 +158,18 @@ namespace winrt::SDKTemplate::implementation
{
ResetTheScenarioState();
}

fire_and_forget Scenario1_BasicFunctionality::ScenarioStartTriggerButton_Click(IInspectable const&, RoutedEventArgs const&)
{
ScenarioStartTriggerButton().IsEnabled(false);
co_await m_claimedScanner.StartSoftwareTriggerAsync();
ScenarioStopTriggerButton().IsEnabled(true);
}

fire_and_forget Scenario1_BasicFunctionality::ScenarioStopTriggerButton_Click(IInspectable const&, RoutedEventArgs const&)
{
ScenarioStopTriggerButton().IsEnabled(false);
co_await m_claimedScanner.StopSoftwareTriggerAsync();
ScenarioStartTriggerButton().IsEnabled(true);
}
}
Expand Up @@ -21,6 +21,8 @@ namespace winrt::SDKTemplate::implementation

fire_and_forget ScenarioStartScanButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void ScenarioEndScanButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
fire_and_forget ScenarioStartTriggerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
fire_and_forget ScenarioStopTriggerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);

void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs const& e);
Expand Down
30 changes: 30 additions & 0 deletions Samples/BarcodeScanner/cs/Scenario1_BasicFunctionality.xaml.cs
Expand Up @@ -95,6 +95,14 @@ private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs

rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
ScenarioEndScanButton.IsEnabled = true;

// If the scanner is a software scanner, show the software trigger buttons.
if (!string.IsNullOrEmpty(scanner.VideoDeviceId))
{
ScenarioSoftwareTriggerPanel.Visibility = Visibility.Visible;
ScenarioStartTriggerButton.IsEnabled = true;
ScenarioStopTriggerButton.IsEnabled = false;
}
}
else
{
Expand Down Expand Up @@ -172,6 +180,7 @@ private void ResetTheScenarioState()
// reset the button state
ScenarioEndScanButton.IsEnabled = false;
ScenarioStartScanButton.IsEnabled = true;
ScenarioSoftwareTriggerPanel.Visibility = Visibility.Collapsed;
}
}

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

/// <summary>
/// Event handler for Start Software Trigger button click.
/// Presses the software trigger button.
/// </summary>
private async void ScenarioStartTriggerButton_Click(object sender, RoutedEventArgs e)
{
ScenarioStartTriggerButton.IsEnabled = false;
await claimedScanner.StartSoftwareTriggerAsync();
ScenarioStopTriggerButton.IsEnabled = true;
}

/// <summary>
/// Event handler for Stop Software Trigger button click.
/// Releases the software trigger button.
/// </summary>
private async void ScenarioStopTriggerButton_Click(object sender, RoutedEventArgs e)
{
ScenarioStopTriggerButton.IsEnabled = false;
await claimedScanner.StopSoftwareTriggerAsync();
ScenarioStartTriggerButton.IsEnabled = true;
}
}
}
15 changes: 8 additions & 7 deletions Samples/BarcodeScanner/shared/Scenario1_BasicFunctionality.xaml
Expand Up @@ -22,6 +22,7 @@
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="RootGrid" Margin="12,20,12,12">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
Expand All @@ -40,7 +41,13 @@
<Button x:Name="ScenarioEndScanButton" Content="End Scanning" Margin="0,0,10,0" Click="ScenarioEndScanButton_Click"/>
</StackPanel>

<Grid Grid.Row="2" Margin="0,0,0,20">
<StackPanel x:Name="ScenarioSoftwareTriggerPanel" Orientation="Horizontal" Margin="5,5,5,20" Visibility="Collapsed" Grid.Row="2">
<Button x:Name="ScenarioStartTriggerButton" Content="Start Software Trigger" Margin="0,0,10,0" Click="ScenarioStartTriggerButton_Click"/>
<Button x:Name="ScenarioStopTriggerButton" Content="Stop Software Trigger" Margin="0,0,10,0" Click="ScenarioStopTriggerButton_Click"/>
</StackPanel>


<Grid Grid.Row="3" Margin="0,0,0,20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="200"/>
Expand All @@ -59,12 +66,6 @@
</Grid>
</StackPanel>
</ScrollViewer>

<!-- Status Block for providing messages to the user. Use the
NotifyUser() method to populate the message -->
<Border x:Name="ErrorBorder" Background="Red" Grid.Row="1"/>
<TextBlock x:Name="StatusBlock" Grid.Row="1" Margin="12, 10, 12, 10" Visibility="Collapsed"/>

</Grid>
</Grid>
</Page>
13 changes: 10 additions & 3 deletions Samples/BluetoothLE/cppwinrt/BluetoothLEDeviceDisplay.cpp
@@ -1,4 +1,4 @@
#include "pch.h"
#include "pch.h"
#include "BluetoothLEDeviceDisplay.h"
#include "BluetoothLEDeviceDisplay.g.cpp"

Expand Down Expand Up @@ -55,9 +55,16 @@ namespace winrt::SDKTemplate::implementation
fire_and_forget BluetoothLEDeviceDisplay::UpdateGlyphBitmapImage()
{
auto lifetime = get_strong();
DeviceThumbnail deviceThumbnail = co_await m_deviceInformation.GetGlyphThumbnailAsync();
BitmapImage glyphBitmapImage;
co_await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
try
{
DeviceThumbnail deviceThumbnail = co_await m_deviceInformation.GetGlyphThumbnailAsync();
co_await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
}
catch (...)
{
// Something went wrong getting or decoding the device glyph.
}
m_glyphBitmapImage = glyphBitmapImage;
OnPropertyChanged(L"GlyphBitmapImage");
}
Expand Down
15 changes: 11 additions & 4 deletions Samples/BluetoothLE/cs/DisplayHelpers.cs
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
Expand Down Expand Up @@ -115,9 +115,16 @@ public void Update(DeviceInformationUpdate deviceInfoUpdate)

private async void UpdateGlyphBitmapImage()
{
DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
var glyphBitmapImage = new BitmapImage();
await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
try
{
DeviceThumbnail deviceThumbnail = await DeviceInformation.GetGlyphThumbnailAsync();
await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
}
catch (Exception)
{
// Something went wrong getting or decoding the device glyph.
}
GlyphBitmapImage = glyphBitmapImage;
OnPropertyChanged("GlyphBitmapImage");
}
Expand Down Expand Up @@ -317,4 +324,4 @@ public static byte[] ReadBufferToBytes(IBuffer buffer)
return data;
}
}
}
}
72 changes: 72 additions & 0 deletions Samples/NetworkConnectivity/README.md
@@ -0,0 +1,72 @@
---
page_type: sample
languages:
- csharp
- cpp
- cppwinrt
products:
- windows
- windows-uwp
urlFragment: NetworkingConnectivity
extendedZipContent:
- path: SharedContent
target: SharedContent
- path: LICENSE
target: LICENSE
description: "Shows how to query network connectivity and respond to network connectivity changes."
---

# NetworkingConnectivity sample

Demonstrates how to use the NetworkInformation and related classes
to determine the network connectivity status,
and shows how to use this information to determine
when to attempt to connect to the Internet.

Apps can use the NetworkInformation and related Windows Runtime classes
to check the network connectivity status before attempting to connect to the Internet.
These class simplify the complex task of determining connectivity for various network configurations.
These checks are not strictly required because higher-level APIs (such as HttpClient)
report insufficient network connectivity through failures/results at the point of connection.

This sample also demonstrates how to register for network connectivity change events.
Apps can subscribe to the events instead of building their
own logic to track network connectivity changes.

> **Note:** This sample is part of a large collection of UWP feature samples.
> You can download this sample as a standalone ZIP file
> [from docs.microsoft.com](https://docs.microsoft.com/samples/microsoft/windows-universal-samples/networkingconnectivity/),
> or you can download the entire collection as a single
> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/main.zip), but be
> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file,
> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center.

### Declaring the internetClient capability

This sample requires that internetClient capability be set in the *Package.appxmanifest* file to allow the app to access the Internet connection at runtime.
The capability can be set in the app manifest using Microsoft Visual Studio.

## System requirements

* Windows 10

## Build the sample

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.
2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**.
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.
4. Press Ctrl+Shift+B or select **Build** \> **Build Solution**.

## Run the sample

The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.

### Deploying the sample

- Select Build > Deploy Solution.

### Debugging and running the sample

- 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.
43 changes: 43 additions & 0 deletions Samples/NetworkConnectivity/cppwinrt/NetworkConnectivity.sln
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkConnectivity", "NetworkConnectivity.vcxproj", "{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.ActiveCfg = Debug|ARM64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.Build.0 = Debug|ARM64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|ARM64.Deploy.0 = Debug|ARM64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.ActiveCfg = Debug|x64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.Build.0 = Debug|x64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x64.Deploy.0 = Debug|x64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.ActiveCfg = Debug|Win32
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.Build.0 = Debug|Win32
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Debug|x86.Deploy.0 = Debug|Win32
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.ActiveCfg = Release|ARM64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.Build.0 = Release|ARM64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|ARM64.Deploy.0 = Release|ARM64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.ActiveCfg = Release|x64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.Build.0 = Release|x64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x64.Deploy.0 = Release|x64
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.ActiveCfg = Release|Win32
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.Build.0 = Release|Win32
{21C18BA0-582C-4264-B0DD-7F2867D8E3D6}.Release|x86.Deploy.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {77D722D2-6DBF-402D-9B3B-6473BA169D27}
EndGlobalSection
EndGlobal

0 comments on commit 118d53b

Please sign in to comment.