PrintDlgEx() 개인적인 메소드

private PrintDlgEx ( IntPtr pdex ) : Int32
pdex IntPtr
리턴 Int32
예제 #1
0
        internal uint ShowDialog()
        {
            uint   result = 0U;
            IntPtr intPtr = IntPtr.Zero;

            if (Application.Current != null && Application.Current.MainWindow != null)
            {
                WindowInteropHelper windowInteropHelper = new WindowInteropHelper(Application.Current.MainWindow);
                intPtr = windowInteropHelper.CriticalHandle;
            }
            try
            {
                if (this._printQueue == null || this._printTicket == null)
                {
                    this.ProbeForPrintingSupport();
                }
                using (Win32PrintDialog.PrintDlgExMarshaler printDlgExMarshaler = new Win32PrintDialog.PrintDlgExMarshaler(intPtr, this))
                {
                    printDlgExMarshaler.SyncToStruct();
                    if (UnsafeNativeMethods.PrintDlgEx(printDlgExMarshaler.UnmanagedPrintDlgEx) == 0)
                    {
                        result = printDlgExMarshaler.SyncFromStruct();
                    }
                }
            }
            catch (Exception ex)
            {
                if (!string.Equals(ex.GetType().FullName, "System.Printing.PrintingNotSupportedException", StringComparison.Ordinal))
                {
                    throw;
                }
                string            text              = SR.Get("PrintDialogInstallPrintSupportMessageBox");
                string            text2             = SR.Get("PrintDialogInstallPrintSupportCaption");
                MessageBoxOptions messageBoxOptions = (text2 != null && text2.Length > 0 && text2[0] == '‏') ? MessageBoxOptions.RtlReading : MessageBoxOptions.None;
                int type = (int)((MessageBoxOptions)64 | messageBoxOptions);
                if (intPtr == IntPtr.Zero)
                {
                    intPtr = UnsafeNativeMethods.GetActiveWindow();
                }
                if (UnsafeNativeMethods.MessageBox(new HandleRef(null, intPtr), text, text2, type) != 0)
                {
                    result = 0U;
                }
            }
            return(result);
        }
        ShowDialog()
        {
            UInt32 result = NativeMethods.PD_RESULT_CANCEL;

            //
            // Get the process main window handle
            //
            IntPtr owner = IntPtr.Zero;

            if ((System.Windows.Application.Current != null) &&
                (System.Windows.Application.Current.MainWindow != null))
            {
                System.Windows.Interop.WindowInteropHelper helper =
                    new System.Windows.Interop.WindowInteropHelper(System.Windows.Application.Current.MainWindow);
                owner = helper.CriticalHandle;
            }

            try
            {
                if (this._printQueue == null || this._printTicket == null)
                {
                    // Normally printDlgEx.SyncToStruct() probes the printer if both the print queue and print
                    // ticket are not null.
                    // If either is null we probe the printer ourselves
                    // If we dont end users will get notified that printing is disabled *after*
                    // the print dialog has been displayed.

                    ProbeForPrintingSupport();
                }

                //
                // Create a PrintDlgEx instance to invoke the Win32 Print Dialog
                //
                using (PrintDlgExMarshaler printDlgEx = new PrintDlgExMarshaler(owner, this))
                {
                    printDlgEx.SyncToStruct();

                    //
                    // Display the Win32 print dialog
                    //
                    Int32 hr = UnsafeNativeMethods.PrintDlgEx(printDlgEx.UnmanagedPrintDlgEx);
                    if (hr == MS.Win32.NativeMethods.S_OK)
                    {
                        result = printDlgEx.SyncFromStruct();
                    }
                }
            }
            //
            // NOTE:
            // This code was previously catch(PrintingNotSupportedException), but that created a circular dependency
            // between ReachFramework.dll and PresentationFramework.dll. Instead, we now catch Exception, check its full type name
            // and rethrow if it doesn't match. Not perfect, but better than having a circular dependency.
            //
            catch (Exception e)
            {
                if (String.Equals(e.GetType().FullName, "System.Printing.PrintingNotSupportedException", StringComparison.Ordinal))
                {
                    string message = System.Windows.SR.Get(System.Windows.SRID.PrintDialogInstallPrintSupportMessageBox);
                    string caption = System.Windows.SR.Get(System.Windows.SRID.PrintDialogInstallPrintSupportCaption);

                    bool isRtlCaption = caption != null && caption.Length > 0 && caption[0] == RightToLeftMark;
                    System.Windows.MessageBoxOptions mbOptions = isRtlCaption ? System.Windows.MessageBoxOptions.RtlReading : System.Windows.MessageBoxOptions.None;

                    int type =
                        (int)System.Windows.MessageBoxButton.OK
                        | (int)System.Windows.MessageBoxImage.Information
                        | (int)mbOptions;

                    if (owner == IntPtr.Zero)
                    {
                        owner = MS.Win32.UnsafeNativeMethods.GetActiveWindow();
                    }

                    if (0 != MS.Win32.UnsafeNativeMethods.MessageBox(new HandleRef(null, owner), message, caption, type))
                    {
                        result = NativeMethods.PD_RESULT_CANCEL;
                    }
                }
                else
                {
                    // Not a PrintingNotSupportedException, rethrow
                    throw;
                }
            }

            return(result);
        }