summaryrefslogtreecommitdiff
path: root/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs
diff options
context:
space:
mode:
authorDave Wilson <[email protected]>2015-03-17 19:50:07 -0700
committerDave Wilson <[email protected]>2015-03-17 19:50:07 -0700
commit97cf5197cf5b882b2c689d8dc2b555f2edf8f418 (patch)
tree46f3701832d70b420eb0fc0eb93261f9da45db3f /print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs
parentef1905bf1e8825bb31120dfb27e0daf3154d859a (diff)
Initial publish
Diffstat (limited to 'print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs')
-rw-r--r--print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs146
1 files changed, 146 insertions, 0 deletions
diff --git a/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs b/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs
new file mode 100644
index 00000000..d37585c4
--- /dev/null
+++ b/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/App.xaml.cs
@@ -0,0 +1,146 @@
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved
+//
+//
+// Abstract:
+//
+// This file contains the entry point to the application.
+
+using System;
+using System.Windows;
+using System.Runtime;
+
+using Microsoft.Samples.Printing.PrinterExtension.Types;
+using Microsoft.Samples.Printing.PrinterExtension.Helpers;
+
+using System.Windows.Interop;
+
+namespace Microsoft.Samples.Printing.PrinterExtension
+{
+ /// <summary>
+ /// Interaction logic for App.xaml.
+ /// </summary>
+ public partial class App : Application
+ {
+ /// <summary>
+ /// This is the event handler invoked on various driver events.
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="eventArgs"></param>
+ private static void OnDriverEvent(object sender, PrinterExtensionEventArgs eventArgs)
+ {
+ //
+ // Display the print preferences window.
+ //
+
+ if (eventArgs.ReasonId.Equals(PrinterExtensionReason.PrintPreferences))
+ {
+ PrintPreferenceWindow printPreferenceWindow = new PrintPreferenceWindow();
+ printPreferenceWindow.Initialize(eventArgs);
+
+ //
+ // Set the caller application's window as parent/owner of the newly created printing preferences window.
+ //
+
+ WindowInteropHelper wih = new WindowInteropHelper(printPreferenceWindow);
+ wih.Owner = eventArgs.WindowParent;
+
+ //
+ // Display a modal/non-modal window based on the 'WindowModal' parameter.
+ //
+
+ if (eventArgs.WindowModal)
+ {
+ printPreferenceWindow.ShowDialog();
+ }
+ else
+ {
+ printPreferenceWindow.Show();
+
+ // Flash the window to draw the user's attention. This is required
+ // because the printer extension may be drawn behind the parent window.
+ // The return value of FlashWindow can be safely ignored if there is no need
+ // to know if the window has focus or not.
+ WindowHelper.FlashWindow(wih.Handle);
+ }
+ }
+ else if (eventArgs.ReasonId.Equals(PrinterExtensionReason.DriverEvent))
+ {
+ //
+ // Handle driver events here.
+ //
+ }
+ }
+
+ /// <summary>
+ /// Perform initialization tasks for the printer extension in this event handler.
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void Application_Startup(object sender, StartupEventArgs e)
+ {
+ //
+ // It is recommended that exactly one instance of the PrinterExtensionManager be created per instance of
+ // the printer extension.
+ //
+
+ if (manager != null)
+ {
+ return;
+ }
+ manager = new PrinterExtensionManager();
+
+ //
+ // Enable events to be received on one printer driver id.
+ //
+ // Note: The order of adding the delegate to PrinterExtensionManager.OnDriverEvent
+ // and invoking PrinterExtensionManager::EnableEvents is important.
+ // Adding the delegate should be done first.
+ //
+
+ manager.OnDriverEvent += OnDriverEvent;
+
+ //
+ // It is recommended that an instance of a printer extension invoke PrinterExtensionManager::EnableEvents
+ // for exactly one printer driver id. The printer driver id could come in from a command line argument,
+ // thereby allowing one application binary to dynamically invoke PrinterExtensionManager::EnableEvents against
+ // the appropriate printer driver id.
+ //
+
+ manager.EnableEvents(Guid.Parse(PrinterDriverID));
+ }
+
+ /// <summary>
+ /// Perform uninitialization tasks for the printer extension in this event handler.
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void Application_Exit(object sender, ExitEventArgs e)
+ {
+ manager.OnDriverEvent -= OnDriverEvent;
+ manager.DisableEvents();
+
+ manager = null;
+ }
+
+ /// <summary>
+ /// This is the printer driver id, as defined in the printer driver manifest file.
+ /// Please replace this GUID with the printer driver id from your manifest file.
+ ///
+ /// It is recommended that you invoke PrinterExtensionManager::EnableEvents() on exactly
+ /// one printer driver id. The id could come in from a command line argument, thereby enabling
+ /// one application binary to work with multiple printer driver ids.
+ /// </summary>
+ private const string PrinterDriverID = "{E0691E8D-F7CC-456E-A7B5-D1FC19BA2279}";
+
+ /// <summary>
+ /// Instance of the PrinterExtensionManager. It is recommended that you have only instance
+ /// of the PrinterExtensionManager per application instance.
+ /// </summary>
+ private static PrinterExtensionManager manager = null;
+ }
+}