Beispiel #1
0
 internal static extern HRESULT TaskDialog(
     IntPtr hwndParent,
     IntPtr hInstance,
     [MarshalAs(UnmanagedType.LPWStr)] string pszWindowtitle,
     [MarshalAs(UnmanagedType.LPWStr)] string pszMainInstruction,
     [MarshalAs(UnmanagedType.LPWStr)] string pszContent,
     SafeNativeMethods.TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,
     [MarshalAs(UnmanagedType.LPWStr)]string pszIcon,
     [In, Out] ref int pnButton);
Beispiel #2
0
 internal static extern int GetMessage(
     out SafeNativeMethods.MSG lpMsg,
     SafeWindowHandle hWnd,
     uint wMsgFilterMin,
     uint wMsgFilterMax);
Beispiel #3
0
        private void UpdateTextCore(string s, SafeNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            AssertCurrentlyShowing();

            FreeOldString(element);
            SendMessageHelper(
                SafeNativeMethods.TASKDIALOG_MESSAGES.TDM_SET_ELEMENT_TEXT,
                (int)element,
                (long)MakeNewString(s, element));
        }
Beispiel #4
0
 internal static extern int GetClientRect(
     IntPtr hwnd,
     ref SafeNativeMethods.RECT rect);
Beispiel #5
0
 internal static extern int SHGetStockIconInfo(
     StockIconIdentifier identifier,
     StockIconOptions flags,
     ref SafeNativeMethods.StockIconInfo info);
Beispiel #6
0
 internal static extern int DwmEnableBlurBehindWindow(
     IntPtr hwnd,
     ref SafeNativeMethods.DWM_BLURBEHIND bb);
Beispiel #7
0
 internal static extern int DwmQueryThumbnailSourceSize(
     IntPtr hThumbnailId,
     ref SafeNativeMethods.SIZE size);
Beispiel #8
0
 internal static extern int DwmRegisterThumbnail(
     IntPtr hwndDestination,
     IntPtr hwndSource,
     ref SafeNativeMethods.SIZE minimizedSize,
     ref IntPtr hThumbnailId);
        internal static bool IsOptionSet(IFileDialog dialog, SafeNativeMethods.FOS flag)
        {
            SafeNativeMethods.FOS currentFlags = GetCurrentOptionFlags(dialog);

            return (currentFlags & flag) == flag;
        }
Beispiel #10
0
        private static IntPtr AllocateAndMarshalButtons(SafeNativeMethods.TASKDIALOG_BUTTON[] structs)
        {
            IntPtr initialPtr = Marshal.AllocHGlobal(
                Marshal.SizeOf(typeof(SafeNativeMethods.TASKDIALOG_BUTTON)) * structs.Length);

            IntPtr currentPtr = initialPtr;
            foreach (SafeNativeMethods.TASKDIALOG_BUTTON button in structs)
            {
                Marshal.StructureToPtr(button, currentPtr, false);
                currentPtr = (IntPtr)((int)currentPtr + Marshal.SizeOf(button));
            }

            return initialPtr;
        }
Beispiel #11
0
        // Checks to see if the given element already has an 
        // updated string, and if so, 
        // frees it. This is done in preparation for a call to 
        // MakeNewString(), to prevent
        // leaks from multiple updates calls on the same element 
        // within a single native dialog lifetime.

        private void FreeOldString(SafeNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            int elementIndex = (int)element;
            if (updatedStrings[elementIndex] != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(updatedStrings[elementIndex]);
                updatedStrings[elementIndex] = IntPtr.Zero;
            }
        }
Beispiel #12
0
        // Allocates a new string on the unmanaged heap, 
        // and stores the pointer so we can free it later.

        private IntPtr MakeNewString(string s, 
            SafeNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            IntPtr newStringPtr = Marshal.StringToHGlobalUni(s);
            updatedStrings[(int)element] = newStringPtr;
            return newStringPtr;
        }
Beispiel #13
0
 private bool IsOptionSet(SafeNativeMethods.TASKDIALOG_FLAGS flag)
 {
     return ((nativeDialogConfig.dwFlags & flag) == flag);
 }
Beispiel #14
0
        private int SendMessageHelper(SafeNativeMethods.TASKDIALOG_MESSAGES msg, int wParam, long lParam)
        {
            // Be sure to at least assert here - 
            // messages to invalid handles often just disappear silently
            Debug.Assert(hWndDialog != null, 
                "HWND for dialog is null during SendMessage");

            return (int)UnsafeNativeMethods.SendMessage(
                hWndDialog,
                (uint)msg,
                (IntPtr)wParam,
                new IntPtr(lParam));
        }
Beispiel #15
0
 private void UpdateIconCore(TaskDialogStandardIcon icon, SafeNativeMethods.TASKDIALOG_ICON_ELEMENT element)
 {
     AssertCurrentlyShowing();
     SendMessageHelper(
         SafeNativeMethods.TASKDIALOG_MESSAGES.TDM_UPDATE_ICON,
         (int)element,
         (long)icon);
 }
Beispiel #16
0
 public static extern int RegisterClassEx(
     ref SafeNativeMethods.WNDCLASSEX wndcls);
 internal abstract SafeNativeMethods.FOS GetDerivedOptionFlags(SafeNativeMethods.FOS flags);
 public void OnShareViolation(
     IFileDialog pfd, 
     IShellItem psi, 
     out SafeNativeMethods.FDE_SHAREVIOLATION_RESPONSE pResponse)
 {
     // Do nothing: we will ignore share violations, 
     // and don't register
     // for them, so this method should never be called.
     pResponse = SafeNativeMethods.FDE_SHAREVIOLATION_RESPONSE.FDESVR_ACCEPT;
 }
Beispiel #19
0
 internal static extern int DwmUpdateThumbnailProperties(
     IntPtr hThumbnailId,
     ref SafeNativeMethods.DWM_THUMBNAIL_PROPERTIES tp);
 public void OnOverwrite(IFileDialog pfd, IShellItem psi, out SafeNativeMethods.FDE_OVERWRITE_RESPONSE pResponse)
 {
     pResponse = SafeNativeMethods.FDE_OVERWRITE_RESPONSE.FDEOR_ACCEPT;
 }
Beispiel #21
0
 public static extern int DwmSetPresentParameters(
     IntPtr hwnd,
     ref SafeNativeMethods.DWM_PRESENT_PARAMETERS pPresentParams);
        private void ApplyGeneralNativeConfiguration(SafeNativeMethods.TASKDIALOGCONFIG dialogConfig)
        {
            // If an owner wasn't specifically specified, 
            // we'll use the app's main window.
            Window currentOwner = ownerWindow;
            if (currentOwner == null)
                currentOwner = Helpers.GetDefaultOwnerWindow();

            if (currentOwner != null)
                dialogConfig.hwndParent = (new WindowInteropHelper(currentOwner)).Handle;

            // Other miscellaneous sets.
            dialogConfig.MainIcon =
                new SafeNativeMethods.TASKDIALOGCONFIG_ICON_UNION((int)mainIcon);
            dialogConfig.FooterIcon =
                new SafeNativeMethods.TASKDIALOGCONFIG_ICON_UNION((int)footerIcon);
            dialogConfig.dwCommonButtons =
                (SafeNativeMethods.TASKDIALOG_COMMON_BUTTON_FLAGS)standardButtons;
        }
Beispiel #23
0
 internal static extern int DwmExtendFrameIntoClientArea(
     IntPtr hwnd,
     ref SafeNativeMethods.MARGINS m);
 /// <summary>
 /// Sets important text properties.
 /// </summary>
 /// <param name="dialogConfig">An instance of a <see cref="SafeNativeMethods.TASKDIALOGCONFIG"/> object.</param>
 private void ApplyTextConfiguration(SafeNativeMethods.TASKDIALOGCONFIG dialogConfig)
 {
     // note that nulls or empty strings are fine here.
     dialogConfig.pszContent = content;
     dialogConfig.pszWindowTitle = caption;
     dialogConfig.pszMainInstruction = instruction;
     dialogConfig.pszExpandedInformation = expandedText;
     dialogConfig.pszExpandedControlText = expandedControlText;
     dialogConfig.pszCollapsedControlText = collapsedControlText;
     dialogConfig.pszFooter = footerText;
     dialogConfig.pszVerificationText = checkBoxText;
 }
Beispiel #25
0
 internal static extern int DrawCaption(
     // Handle to window.
     IntPtr hwnd,
     // Handle to device context.
     IntPtr hdc,
     // Rectangle to draw in.
     ref SafeNativeMethods.RECT lprc,
     // drawing options.
     int uFlags   
 );
        private void ApplyOptionConfiguration(SafeNativeMethods.TASKDIALOGCONFIG dialogConfig)
        {
            // Handle options - start with no options set.
            SafeNativeMethods.TASKDIALOG_FLAGS options = SafeNativeMethods.TASKDIALOG_FLAGS.NONE;
            if (cancelable)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_ALLOW_DIALOG_CANCELLATION;
            if (checkBoxChecked.HasValue && checkBoxChecked.Value)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_VERIFICATION_FLAG_CHECKED;
            if (hyperlinksEnabled)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_ENABLE_HYPERLINKS;
            if (expanded)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_EXPANDED_BY_DEFAULT;
            if (Tick != null)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_CALLBACK_TIMER;
            if (startupLocation == TaskDialogStartupLocation.CenterOwner)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_POSITION_RELATIVE_TO_WINDOW;

            // Note: no validation required, as we allow this to 
            // be set even if there is no expanded information 
            // text because that could be added later.
            // Default for Win32 API is to expand into (and after) 
            // the content area.
            if (expansionMode == TaskDialogExpandedInformationLocation.ExpandFooter)
                options |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_EXPAND_FOOTER_AREA;

            // Finally, apply options to config.
            dialogConfig.dwFlags = options;
        }
 internal override SafeNativeMethods.FOS GetDerivedOptionFlags(SafeNativeMethods.FOS flags)
 {
     if (overwritePrompt)
         flags |= SafeNativeMethods.FOS.FOS_OVERWRITEPROMPT;
     if (createPrompt)
         flags |= SafeNativeMethods.FOS.FOS_CREATEPROMPT;
     if (!enableMiniMode)
         flags |= SafeNativeMethods.FOS.FOS_DEFAULTNOMINIMODE;
     if (strictExtensions)
         flags |= SafeNativeMethods.FOS.FOS_STRICTFILETYPES;
     return flags;
 }
        internal override SafeNativeMethods.FOS GetDerivedOptionFlags(SafeNativeMethods.FOS flags)
        {
            if (multiselect)
                flags |= SafeNativeMethods.FOS.FOS_ALLOWMULTISELECT;
            if (foldersOnly)
                flags |= SafeNativeMethods.FOS.FOS_PICKFOLDERS;

            return flags;
        }