Skip to content

Various fixes for C++ project and item templates #3745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<LanguageTag>csharp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">BlankWindow.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"
#include "$safeitemname$.xaml.h"
#if __has_include("$safeitemname$.g.cpp")
Expand All @@ -15,11 +12,6 @@ using namespace Microsoft::UI::Xaml;

namespace winrt::$rootnamespace$::implementation
{
$safeitemname$::$safeitemname$()
{
InitializeComponent();
}

int32_t $safeitemname$::MyProperty()
{
throw hresult_not_implemented();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "$safeitemname$.g.h"
Expand All @@ -9,12 +6,16 @@ namespace winrt::$rootnamespace$::implementation
{
struct $safeitemname$ : $safeitemname$T<$safeitemname$>
{
$safeitemname$();
$safeitemname$()
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
}

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

namespace $rootnamespace$
{
[default_interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<LanguageTag>cpp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">BlankWindow.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>csharp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">BlankPage.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>csharp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">ResourceDictionary.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>csharp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem ItemType="PRIResource">Resources.resw</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>csharp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.cs">CustomControl.cs</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>csharp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">UserControl.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"
#include "$safeitemname$.xaml.h"
#if __has_include("$safeitemname$.g.cpp")
Expand All @@ -15,11 +12,6 @@ using namespace Microsoft::UI::Xaml;

namespace winrt::$rootnamespace$::implementation
{
$safeitemname$::$safeitemname$()
{
InitializeComponent();
}

int32_t $safeitemname$::MyProperty()
{
throw hresult_not_implemented();
Expand Down
11 changes: 6 additions & 5 deletions dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "$safeitemname$.g.h"
Expand All @@ -9,12 +6,16 @@ namespace winrt::$rootnamespace$::implementation
{
struct $safeitemname$ : $safeitemname$T<$safeitemname$>
{
$safeitemname$();
$safeitemname$()
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
}

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

namespace $rootnamespace$
{
[default_interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>cpp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">BlankPage.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>cpp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" TargetFileName="$fileinputname$.xaml">ResourceDictionary.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>cpp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem ItemType="PRIResource">Resources.resw</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"
#include "$safeitemname$.h"
#if __has_include("$safeitemname$.g.cpp")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "winrt/Microsoft.UI.Xaml.h"
#include "winrt/Microsoft.UI.Xaml.Markup.h"
#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h"
#include "$safeitemname$.g.h"

namespace winrt::$rootnamespace$::implementation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

namespace $rootnamespace$
{
[default_interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>cpp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.cpp" ReplaceParameters="true">TemplatedControl.cpp</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"
#include "$safeitemname$.xaml.h"
#if __has_include("$safeitemname$.g.cpp")
Expand All @@ -15,11 +12,6 @@ using namespace Microsoft::UI::Xaml;

namespace winrt::$rootnamespace$::implementation
{
$safeitemname$::$safeitemname$()
{
InitializeComponent();
}

int32_t $safeitemname$::MyProperty()
{
throw hresult_not_implemented();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "winrt/Microsoft.UI.Xaml.h"
#include "winrt/Microsoft.UI.Xaml.Markup.h"
#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h"
#include "$safeitemname$.g.h"

namespace winrt::$rootnamespace$::implementation
{
struct $safeitemname$ : $safeitemname$T<$safeitemname$>
{
$safeitemname$();
$safeitemname$()
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
}

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

namespace $rootnamespace$
{
[default_interface]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TargetPlatformName>Windows</TargetPlatformName>
<LanguageTag>cpp</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>uwp</ProjectTypeTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<ProjectTypeTag>WinUI</ProjectTypeTag>
</TemplateData>
<TemplateContent>
<ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">UserControl.xaml</ProjectItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#include "pch.h"

#include "App.xaml.h"
#include "MainWindow.xaml.h"

using namespace winrt;
using namespace Windows::Foundation;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Controls;
using namespace Microsoft::UI::Xaml::Navigation;
using namespace $safeprojectname$;
using namespace $safeprojectname$::implementation;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
namespace winrt::$safeprojectname$::implementation
{
InitializeComponent();
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
{
if (IsDebuggerPresent())
UnhandledException([](IInspectable const&, UnhandledExceptionEventArgs const& e)
{
auto errorMessage = e.Message();
__debugbreak();
}
});
if (IsDebuggerPresent())
{
auto errorMessage = e.Message();
__debugbreak();
}
});
#endif
}
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched(LaunchActivatedEventArgs const&)
{
window = make<MainWindow>();
window.Activate();
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched([[maybe_unused]] LaunchActivatedEventArgs const& e)
{
m_window = make<MainWindow>();
m_window.Activate();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "App.xaml.g.h"
Expand All @@ -14,6 +11,6 @@ namespace winrt::$safeprojectname$::implementation
void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

private:
winrt::Microsoft::UI::Xaml::Window window{ nullptr };
winrt::Microsoft::UI::Xaml::Window m_window{ nullptr };
};
}

This file was deleted.

Loading