Direct2D printing from Windows Store apps (DirectX and C++)

Applies to Windows only

These topics show you how to use Direct2D printing to print content from a Windows Store app using DirectX with C++. They assume that you already know how to write code in C++, so they focus on the techniques that are specific to printing from Windows Store apps using DirectX.

In this section

TopicDescription

Quickstart: Add printing to your app

You might want to add Direct2D print functionality to your Windows Store app using DirectX. Here we'll show you how.

How to format content for Direct2D printing

Learn here how to format content for Direct2D printing in your Windows Store app using DirectX.

How to retrieve and change Direct2D print settings

Here's how to get and set Direct2D print settings in your Windows Store apps using C++ and DirectX.

 

Overview

Starting in Windows 8, you can add Direct2D printing to your Windows Store app using DirectX to print content in much the same way you draw to a screen. You can reuse most of your knowledge and code from your Direct2D display code for printing.

A Windows Store app must do the following before it can print using DirectX and C++:

  • Use a multithreaded Direct2D factory to handle multiple threads.
  • Register for the Print contract.
  • Provide formatted content for print preview.
  • Provide formatted content to print.

Use a multithreaded Direct2D factory to handle multiple threads

In Windows Store apps, printing is always invoked in a separate thread. In fact, apps use separate threads to display, preview, and print the same content. Handling Direct2D resources in more than one thread requires that your app use the multithreaded Direct2D factory to avoid resource competition and guarantee resource synchronization. For more info about the Direct2D factory, see Multithreaded Direct2D apps.

Register for the Print contract

To use Windows printing, your app must register for the Print contract. This involves getting a PrintManager object and associating it to the PrintTaskRequested event.

After registering for the Print contract, your app can use the default print UI that Windows provides, or it can customize the UI by adding or removing printing options.

Provide formatted content for print preview

Windows printing provides a preview feature to all apps that have registered for the Print contract. Use the print preview functions of Windows printing instead of showing print preview content in your Windows Store app itself. For more info about Windows printing, see Printing (Windows Store apps using C#/VB/C++ and XAML).

Provide formatted content to print

After your app has registered for the Print contract, Windows fires printing events that correspond to various aspects of the printing process. Your app must format and return the content required by each event. It can render content for printing by using the same APIs it uses to render content for display.

Direct2D printing workflow

The workflow for Direct2D printing begins when the user selects the Devices charm and then chooses a printer. Windows then displays a print dialog for Windows Store apps, letting the user change print settings. The app then generates preview images and the print dialog displays the preview images to the user. The user can choose to close the print dialog to end the workflow, or click the Print button to tell the app to print. This diagram shows the Direct2D printing workflow.

Direct2D printing workflow

Related topics

Printing and command lists
ID2D1PrintControl interface
Quickstart: Add Direct2D printing to your app
How to format content for Direct2D printing
How to retrieve and change Direct2D print settings
Improving the performance of Direct2D apps

 

 

Show:
© 2014 Microsoft. All rights reserved.