Direct2D printing from Windows Store apps (DirectX and C++)
[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]
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
You might want to add Direct2D print functionality to your Windows Store app using DirectX. Here we'll show you how.
Learn here how to format content for Direct2D printing in your Windows Store app using DirectX.
Here's how to get and set Direct2D print settings in your Windows Store apps using C++ and DirectX.
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
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.