MSDN Community

Your gateway to Microsoft Developer Network

Windows Runtime (WinRT) API Reference

Welcome to the Windows Runtime (WinRT) API reference. WinRT is a modern, object-oriented API set that enables developers to build rich, integrated applications for Windows. It provides a consistent way to access system capabilities and hardware features across various programming languages and development models.

Overview

The Windows Runtime provides a set of APIs that are accessible from native code (C++), managed code (.NET), JavaScript, and other languages. It is built on a component-object model that allows for language projection, enabling interoperability between different languages.

Key Concepts:
  • Components: Reusable units of code that expose WinRT interfaces.
  • Interfaces: Contracts that define the methods and properties available from a component.
  • Classes: Implementations of WinRT interfaces, often representing specific functionalities.
  • Runtime Class: The fundamental building block of WinRT, defining a type.
  • Projection: The mechanism that translates WinRT types into language-specific constructs.

Core APIs

These APIs form the foundation of the Windows Runtime, providing access to fundamental system services and data types.

Example API: Windows.Foundation.Point

Represents a point in two-dimensional space.

Properties:

  • X (Double): The x-coordinate of the point.
  • Y (Double): The y-coordinate of the point.

Methods:

  • Translate(Windows.Foundation.Point point, Windows.Foundation.Point translatePoint): Translates a point by the offset of another point.
See More Core APIs...

UI & Graphics

Access APIs related to user interface elements, layout, rendering, and graphics.

Example API: Windows.UI.Xaml.Controls.Button

Represents a clickable button control.

Properties:

  • Content (Object): Gets or sets the content of the button.
  • IsEnabled (Boolean): Gets or sets a value that indicates whether the button is enabled.
See More UI APIs...

Connectivity

Interact with network services, sockets, and other communication protocols.

Example API: Windows.Networking.Sockets.StreamSocket

Represents a TCP stream socket for sending and receiving data.

Methods:

  • ConnectAsync(Windows.Networking.HostName remoteHostName, String remoteServiceName): Connects the socket to a remote host.
  • DisconnectAsync(Windows.Networking.Sockets.SocketErrorStatus reserved): Disconnects the socket.
See More Connectivity APIs...

Storage

Manage files, folders, and local storage for your applications.

Example API: Windows.Storage.StorageFile

Represents a file in the file system.

Properties:

  • Name (String): Gets the name of the file.
  • FileType (String): Gets the file extension.

Methods:

  • OpenAsync(Windows.Storage.FileAccessMode accessMode): Opens the file for reading or writing.
  • DeleteAsync(): Deletes the file.
See More Storage APIs...

Devices

Access and control various hardware devices connected to the system.

Example API: Windows.Devices.Geolocation.Geolocator

Represents a device that provides location and position information.

Properties:

  • MovementThreshold (UInt32): Gets or sets the distance in meters that must change before a new position is reported.

Methods:

  • GetGeopositionAsync(): Asynchronously retrieves the current location.
See More Device APIs...

Notifications

Implement toast notifications and live tiles to inform users.

Example API: Windows.UI.Notifications.ToastNotificationManager

Manages the display of toast notifications.

Methods:

  • CreateToastNotifier(): Creates a toast notifier for the application.
  • GetTemplateContent(ToastTemplateType type): Gets the XML content for a specified toast template.
See More Notification APIs...

Media

Work with audio, video, and camera functionalities.

Example API: Windows.Media.Capture.MediaCapture

Captures media from a media capture device.

Methods:

  • InitializeAsync(MediaCaptureInitializationSettings settings): Initializes the media capture object.
  • StartRecordToStorageFileAsync(MediaEncodingProfile profile, IRandomAccessStream stream): Starts recording media to a file.
See More Media APIs...

Code Example: Using WinRT in C++

Here's a simple C++ example demonstrating how to use the Windows.Storage.StorageFolder API to get the current user's documents folder.


#include <winrt/Windows.Storage.h>
#include <iostream>

int main() {
    // Enable WinRT
    winrt::init_apartment();

    try {
        // Get the Documents library
        Windows::Storage::StorageFolder documentsFolder = Windows::Storage::KnownFolders::DocumentsLibrary();

        // Print the folder name
        std::wcout << L"Accessing folder: " << documentsFolder.Name().c_str() << std::endl;

        // Further operations like listing files or creating new ones can be done here.

    } catch (const winrt::hresult_error& e) {
        std::wcerr << L"WinRT Error: " << winrt::to_hstring(e.message()).c_str() << std::endl;
        return 1;
    }

    // Disable WinRT
    winrt::uninit_apartment();
    return 0;
}
            

Further Resources