예제 #1
0
        public CommonFileDialogResult ShowDialog()
        {
            CommonFileDialogResult result;

            try
            {
                // Fetch derived native dialog (i.e. Save or Open)
                InitializeNativeFileDialog();
                nativeDialog = GetNativeFileDialog();

                // Process custom controls, and validate overall state
                ProcessControls();
                ValidateCurrentDialogState();

                // Apply outer properties to native dialog instance
                ApplyNativeSettings(nativeDialog);
                InitializeEventSink(nativeDialog);

                // Show dialog
                showState = NativeDialogShowState.Showing;
                int hresult = nativeDialog.Show(GetHandleFromWindow(parentWindow));
                showState = NativeDialogShowState.Closed;

                // Create return information
                if (ErrorHelper.Matches(hresult, Win32ErrorCode.ERROR_CANCELLED))
                {
                    canceled = true;
                    fileNames.Clear();
                }
                else
                {
                    canceled = false;

                    // Populate filenames - though only if user didn't cancel
                    PopulateWithFileNames(fileNames);
                }
                result = new CommonFileDialogResult(canceled.Value);
            }
            finally
            {
                CleanUpNativeFileDialog();
            }
            return result;
        }
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        /// <returns>A <see cref="Microsoft.SDK.Samples.VistaBridge.Library.CommonFileDialogResult"/> object.</returns>
        public CommonFileDialogResult ShowDialog()
        {
            CommonFileDialogResult result;

            try
            {
                // Fetch derived native dialog (i.e. Save or Open).
                InitializeNativeFileDialog();
                nativeDialog = GetNativeFileDialog();

                // Apply outer properties to native dialog instance.
                ApplyNativeSettings(nativeDialog);
                InitializeEventSink(nativeDialog);

                // Clear user data if Reset has been called 
                // since the last show.
                if (resetSelections)
                {
                    resetSelections = false;
                }

                // Show dialog.
                showState = NativeDialogShowState.Showing;
                int hresult = nativeDialog.Show(
                    CommonFileDialog.GetHandleFromWindow(parentWindow));
                showState = NativeDialogShowState.Closed;

                // Create return information.
                if (ErrorHelper.Matches(hresult, 
                    Win32ErrorCode.ERROR_CANCELLED))
                {
                    canceled = true;
                    fileNames.Clear();
                }
                else
                {
                    canceled = false;

                    // Populate filenames if user didn't cancel.
                    PopulateWithFileNames(fileNames);
                }
                result = new CommonFileDialogResult(canceled.Value);
            }
            finally
            {
                CleanUpNativeFileDialog();
            }
            return result;
        }