選擇您的應用程式平台Choose your app platform

當您想要為 Windows 電腦建立新的傳統型應用程式時,首先必須決定要使用哪個應用程式平台。When you want to create a new desktop application for Windows PCs, the first decision you make is which application platform to use. Windows 提供四個主要應用程式平台,各有不同的優勢:Windows provides four main application platforms, each with different strengths:

所有這些應用程式平台都可讓您建立在傳統 Windows 桌面上執行的傳統型應用程式 (例如 Word、Excel 和 Photoshop),並充分利用該環境的特定功能。All of these application platforms let you create desktop apps like Word, Excel, and Photoshop that run in the classic Windows desktop and take full advantage of that environment's specific features. 不過,其中有些平台會共用一些特性,而且更適合特定類型的應用程式:However, some of these platforms share some traits and are better suited for certain types of applications:

  • UWP、WPF 和 Windows FormsUWP, WPF, and Windows Forms. 這些平台提供受管理的執行階段環境 (適用於 UWP 的 Windows 執行階段,以及適用於 Windows Forms 和 WPF 的 .NET),其有許多優點,特別是在開發人員生產力、複雜且可自訂的 UI,以及應用程式安全性等方面。These platforms provide managed runtime environments (the Windows Runtime for UWP, and .NET for Windows Forms and WPF) with many benefits, especially in the areas of developer productivity, sophisticated and customizable UI, and application security. 由於這些架構支援視覺化設計工具和 UI 標記來快速建立 UI,因此特別適用於企業營運應用程式。Because these frameworks support visual designers and UI markup for rapidly creating UI, they are particularly well-suited for line-of-business applications.

  • Win32 APIWin32 API. Win32 API (也稱為 Windows API) 是適用於原生 C/C++ Windows 應用程式的原創平台,而這些應用程式需要直接存取 Windows 和硬體。The Win32 API (also called the Windows API) is the original platform for native C/C++ Windows applications that require direct access to Windows and hardware. 它提供了一流的開發體驗,而不需取決於受管理的執行階段環境 (例如 .NET 和 WinRT)。It provides a first-class development experience without depending on a managed runtime environment like .NET and WinRT. 這讓 Win32 API 成為應用程式的首選平台,因為這些應用程式需要最高階效能及直接存取系統硬體。This makes the Win32 API the platform of choice for applications that need the highest level of performance and direct access to system hardware.

本文會更詳細地說明這些平台,並協助您判斷最適合您應用程式的平台。This article describes these platforms in more detail and helps you determine the best one for your application.

注意

無論您選擇哪一個應用程式平台,都可以使用通用 Windows 平台 (UWP) 的眾多功能,以在 Windows 10 上的應用程式中提供現代化體驗。No matter which app platform you choose, you can use many features of the Universal Windows Platform (UWP) to deliver a modern experience in your app on Windows 10. 例如,即使您的傳統型應用程式是使用 WPF、Windows Forms 或 Win32 API 建置的,您仍然可以使用 UWP 首次引進的眾多功能,例如 MSIX 套件部署和 UWP XAML 控制項。For example, even if your desktop app is built using WPF, Windows Forms, or the Win32 API, you can still use many features first introduced with UWP, such as MSIX package deployment and UWP XAML controls. 如需詳細資訊,請參閱讓您的傳統型應用程式現代化For more information, see Modernize your desktop apps.

UWPUWP

UWP 是適用於 Windows 10 應用程式和遊戲的先進平台。UWP is the leading-edge platform for Windows 10 applications and games. 它是高度可自訂的平臺,其會使用 XAML 標記來分隔 UI (簡報) 與程式碼 (商務邏輯)。It's a highly customizable platform that uses XAML markup to separate UI (presentation) from code (business logic). UWP 適用於需要複雜 UI、樣式自訂和圖形密集案例的傳統型應用程式。UWP is suitable for desktop applications that require a sophisticated UI, styles customization, and graphics-intensive scenarios. UWP 也提供 Fluent Design 系統 的內建支援,以取得預設的 UX 體驗,並可讓您存取 Windows 執行階段 (WinRT) APIUWP also has built-in support for the Fluent Design System for the default UX experience and provides access to the Windows Runtime (WinRT) APIs. 藉由採用 Fluent,UWP 會自動支援一般輸入法,例如筆跡、觸控、遊戲台、鍵盤和滑鼠。By adopting Fluent, UWP automatically supports common input methods such as ink, touch, gamepad, keyboard, and mouse.

您不僅可以使用 UWP 來建立適用於 Windows 電腦的傳統型應用程式,而且 UWP 也是 Xbox、HoloLens 和 Surface Hub 應用程式唯一支援的平台。Not only can you use UWP to create desktop applications for Windows PCs, but UWP is also the only supported platform for Xbox, HoloLens, and Surface Hub applications. UWP 是我們最先進的應用程式平台。UWP is our newest, leading-edge application platform.

如需 UWP 的詳細資訊,請參閱下列文章:For more information about UWP, see the following articles:

WPFWPF

WPF 是針對受管理 Windows 應用程式所建立的平台,可存取 .NET Core 或完整的 .NET Framework,而且也會使用 XAML 標記來區隔 UI 與程式碼。WPF is the established platform for managed Windows applications with access to .NET Core or the full .NET Framework, and it also uses XAML markup to separate UI from code. 此平台是針對需要複雜 UI、樣式自訂和圖形密集案例的傳統型應用程式而設計的。This platform is designed for desktop applications that require a sophisticated UI, styles customization, and graphics-intensive scenarios. WPF 開發技能類似於 UWP 開發技能,因此從 WPF 遷移至 UWP 應用程式比從 Windows Forms 進行遷移更容易。WPF development skills are similar to UWP development skills, so migration from WPF to UWP apps is easier than migration from Windows Forms.

如需 WPF 的詳細資訊,請參閱下列文章:For more information about WPF, see the following articles:

Windows FormsWindows Forms

Windows Forms 是適用於受管理 Windows 應用程式的原創平台,具有輕量型 UI 模型並可存取 .NET Core 或完整的 .NET Framework。Windows Forms is the original platform for managed Windows applications with a lightweight UI model and access to .NET Core or the full .NET Framework. 它擅長於讓開發人員快速開始建立應用程式,甚至適用於初次使用平台的開發人員。It excels at enabling developers to quickly get started building applications, even for developers new to the platform. 這是表單型快速應用程式開發平台,其中包含一組大型內建的視覺效果和非視覺效果拖放控制項集合。This is a forms-based, rapid application development platform with a large built-in collection of visual and non-visual drag-and-drop controls. Windows Forms 不會使用 XAML,因此稍後決定將應用程式延伸至 UWP 時,需要完整重新撰寫您的 UI。Windows Forms does not use XAML, so deciding later to extend your application to UWP entails a complete re-write of your UI.

如需 Windows Forms 的詳細資訊,請參閱下列文章:For more information about Windows Forms, see the following articles:

Win32Win32

搭配使用 Win32 API 與 C++ 可讓您實現最高階效能和效率,方法為嚴加控制目標平台與可能位於受管理執行階段環境 (例如 WinRT 和 .NET) 的未受管理程式碼。Using the Win32 API with C++ makes it possible to achieve the highest levels of performance and efficiency by taking more control of the target platform with unmanaged code than is possible on a managed runtime environment like WinRT and .NET. 不過,對於應用程式執行進行這種層級的控制,需要更加小心謹慎以免出錯,導致開發生產力雖然提高,但執行階段效能卻降低。However, exercising such a level of control over your application's execution requires greater care and attention to get right, and trades development productivity for runtime performance.

以下是 Win32 API 和 C++提供的幾個重點,可讓您建置高效能的應用程式。Here are a few highlights of what the Win32 API and C++ offers to enable you to build high-performance applications.

  • 硬體層級的最佳化,包括嚴格控制資源配置、物件存留期、資料配置、對齊、位元組封裝等。Hardware-level optimizations, including tight control over resource allocation, object lifetimes, data layout, alignment, byte packing, and more.
  • 透過內建函式存取效能導向的指令集 (例如 SSE 和 AVX)。Access to performance-oriented instruction sets like SSE and AVX through intrinsic functions.
  • 使用範本進行有效率的型別安全泛型程式設計。Efficient, type-safe generic programming by using templates.
  • 有效率且安全的容器和演算法。Efficient and safe containers and algorithms.
  • DirectX,特別是 Direct3D 和 DirectCompute (請注意,UWP 也提供 DirectX interop)。DirectX, in particular Direct3D and DirectCompute (note that UWP also offers DirectX interop).

如需詳細資訊,請參閱下列文章:For more information, see the following articles:

平台比較:UWP、WPF 和 Windows FormsPlatform comparison: UWP, WPF, and Windows Forms

下表詳細比較 Windows Forms、WPF 和 UWP 的各種特性。The following table compares various characteristics of Windows Forms, WPF, and UWP in detail.

功能或案例Feature or scenario UWPUWP WPFWPF Windows FormsWindows Forms
支援版本Supported versions Windows 10Windows 10 Windows 7 和更新版本Windows 7 and later Windows 7 和更新版本Windows 7 and later
語言Languages C#、C++/WinRT、C++/CX、VB、JavaScriptC#, C++/WinRT, C++/CX, VB, JavaScript C#、C++/CLI (Managed Extensions for C++)、F#VBC#, C++/CLI (Managed Extensions for C++), F#, VB C#、C++/CLI (Managed Extensions for C++)、F#VBC#, C++/CLI (Managed Extensions for C++), F#, VB
UI 執行階段UI runtime 原生 (C++/WinRT 和 C++/CX) 和受管理 (.NET Native)Native (C++/WinRT and C++/CX) and managed (.NET Native) 受管理 (.NET Framework 和 .NET Core 3)Managed (.NET Framework and .NET Core 3) 受管理 (.NET Framework 和 .NET Core 3)Managed (.NET Framework and .NET Core 3)
開放原始碼Open source 是 (僅限 Windows UI 程式庫)Yes (Windows UI Library only) 是 (僅限 .NET Core)Yes (.NET Core only) 是 (僅限 .NET Core)Yes (.NET Core only)
支援 XAMLSupports XAML Yes Yes No
優勢Strengths
  • 適用於 UI 的 XAML 標記XAML markup for UI
  • 豐富且可自訂的 UXRich and customizable UX
  • 您現有的程式碼基底相容於 .NET StandardYour existing code bases are .NET Standard compliant
  • 高 DPI 支援High DPI support
  • 支援跨 Windows 裝置的多種輸入類型 (包括觸控、手寫筆、遊戲台、滑鼠和鍵盤)Support for multiple input types across Windows devices (including touch, pen, gamepad, mouse, and keyboard)
  • 支援 Xbox、HoloLens、IoT 或 Surface HubSupport for Xbox, HoloLens, IoT or Surface Hub
  • 選擇性密集 (精簡) UIOptional dense (compact) UI
  • 支援原生 C++Support for native C++
  • 最佳化的電池使用時間Optimized battery life
  • 新式協助工具支援 (例如螢幕助讀程式)Modern accessibility support (such as screen readers)
  • Rich Text 格式資料功能 (例如內建的拼字檢查)Rich text data capabilities (such as built-in spell check)
  • 筆跡支援Inking support
  • 透過應用程式容器保護執行安全 (例如,未受信任的內容會沙箱化)Secure execution via application containers (for example, untrusted content is sandboxed)
  • 適用於 UI 的 XAML 標記XAML markup for UI
  • 豐富且可自訂的 UXRich and customizable UX
  • 來自 Microsoft 和合作夥伴的大型控制項集合Large collection of controls from Microsoft and partners
  • 密集 UIDense UI
  • 支援 Windows 7Support for Windows 7
  • 支援平台進行輸入驗證Platform support for input validation
  • 快速應用程式開發Rapid application development
  • 用於建置 UI 的 WYSIWYG 編輯器WYSIWYG editor for building UI
  • 來自 Microsoft 和合作夥伴的大型控制項集合Large collection of controls from Microsoft and partners
  • 密集 UIDense UI
  • 支援 Windows 7Support for Windows 7
  • 鍵盤和滑鼠輸入Keyboard and mouse input
有限支援的案例Scenarios that have limited support
  • 多重視窗支援1Multiple window support1
  • 支援平台進行輸入驗證1Platform support for input validation1
  • 不支援 Windows 7Windows 7 is not supported
  • 某些 UWP API 需要特定的 Windows 10 最低版本Some UWP APIs require specific minimum versions of Windows 10
  • 完整平台支援和命令介面整合 (例如,UWP 目前不支援系統匣整合或完整存取所有裝置)Full platform support and shell integration (for example, UWP currently doesn't support System Tray integration or full access to all devices)
  • 直接存取磁碟上的所有檔案Direct access to all files on disk
  • ADO.NETADO.NET
  • 使用非 .NET Standard 或非 Windows 應用程式認證套件相容 API 的現有程式碼基底類別程式庫Existing code-base class libraries that use non-.NET Standard or non-Windows App Certification Kit compliant APIs
  • 區域網路回送支援 (亦即,如果您的應用程式需要與 localhost 通訊,而不在目標裝置上建立回送豁免)Local network loopback support (that is, if your app needs to communicate with localhost without creating a loopback exemption on the target device)
  • 密集檔案 I/OIntensive file I/O
  • 高 DPI 支援2High DPI support2
  • 觸控輸入2Touch input2
  • 高 DPI 支援2High DPI support2
  • 觸控輸入2Touch input2
  • 可自訂的 UICustomizable UI
  • 豐富的圖形和使用者體驗 (例如觸控和動畫)Rich graphics and user experiences (such as touch and animations)
  • 豐富的視圖和資料模型抽象Rich abstraction of views and data models

1 我們已公開宣佈的功能,可在未來的 Windows 10 版本中解決此案例。1 We have publicly announced features that will address this scenario in a future release of Windows 10.

2 雖然平台缺少此案例的第一級 API 支援,但開發人員可以透過因應措施來支援此案例。2 Although the platform lacks first-class API support for this scenario, developers can support this scenario with workarounds.

其他應用程式平台Other app platforms

漸進式 Web 應用程式 (PWA)Progressive Web Apps (PWAs)

PWA 可讓開發人員封裝他們的網站程式碼,以便能夠在 Windows 10 電腦上安裝並且像應用程式一般執行。PWAs let developers package their website code so it can be installed and run like an application on Windows 10 PCs. 如需詳細資訊,請參閱漸進式 Web 應用程式For more information, see Progressive Web Apps.

XamarinXamarin

使用 Xamarin 可建置跨平台應用程式,不只適用於 Windows 10,也可以在 iOS 和 Android 上執行。Use Xamarin to build cross-platform applications for Windows 10 that can also run on iOS and Android. 如需詳細資訊,請參閱 XamarinFor more information, see Xamarin.