Esempio n. 1
0
        // This is a major hack to get the .NET's OFD to show with Thumbnail view by default!
        // Luckily for us this is a covert hack, and not one where we're working around a bug
        // in the framework or OS.
        // This hack works by retrieving a private property of the OFD class after it has shown
        // the dialog box.
        // Based off code found here: http://vbnet.mvps.org/index.html?code/hooks/fileopensavedlghooklvview.htm
        private static void EnableThumbnailView(FileDialog ofd)
        {
            // HACK: Must verify this still works with each new revision of .NET
            try
            {
                Type      ofdType = typeof(FileDialog);
                FieldInfo fi      = ofdType.GetField("dialogHWnd", BindingFlags.Instance | BindingFlags.NonPublic);

                if (fi != null)
                {
                    object dialogHWndObject = fi.GetValue(ofd);
                    IntPtr dialogHWnd       = (IntPtr)dialogHWndObject;
                    IntPtr hwndLV           = SafeNativeMethods.FindWindowExW(dialogHWnd, IntPtr.Zero, "SHELLDLL_DefView", null);

                    if (hwndLV != IntPtr.Zero)
                    {
                        SafeNativeMethods.SendMessageW(hwndLV, NativeConstants.WM_COMMAND, new IntPtr(NativeConstants.SHVIEW_THUMBNAIL), IntPtr.Zero);
                    }
                }
            }

            catch (Exception)
            {
                // Ignore.
            }
        }
Esempio n. 2
0
        public static void EnableShield(Button button, bool enableShield)
        {
            IntPtr hWnd = button.Handle;

            SafeNativeMethods.SendMessageW(
                hWnd,
                NativeConstants.BCM_SETSHIELD,
                IntPtr.Zero,
                enableShield ? new IntPtr(1) : IntPtr.Zero);

            GC.KeepAlive(button);
        }
Esempio n. 3
0
        public static void ShowComboBox(ComboBox comboBox, bool show)
        {
            IntPtr hWnd = comboBox.Handle;

            SafeNativeMethods.SendMessageW(
                hWnd,
                NativeConstants.CB_SHOWDROPDOWN,
                show ? new IntPtr(1) : IntPtr.Zero,
                IntPtr.Zero);

            GC.KeepAlive(comboBox);
        }
        public void SendInstanceMessage(string text, int timeoutSeconds)
        {
            IntPtr   ourHwnd     = IntPtr.Zero;
            DateTime now         = DateTime.Now;
            DateTime timeoutTime = DateTime.Now + new TimeSpan(0, 0, 0, timeoutSeconds);

            while (ourHwnd == IntPtr.Zero && now < timeoutTime)
            {
                ourHwnd = ReadHandleFromFromMappedFile();
                now     = DateTime.Now;

                if (ourHwnd == IntPtr.Zero)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }

            if (ourHwnd != IntPtr.Zero)
            {
                NativeStructs.COPYDATASTRUCT copyDataStruct = new NativeStructs.COPYDATASTRUCT();
                IntPtr szText = IntPtr.Zero;

                try
                {
                    unsafe
                    {
                        szText = Marshal.StringToCoTaskMemUni(text);
                        copyDataStruct.dwData = UIntPtr.Zero;
                        copyDataStruct.lpData = szText;
                        copyDataStruct.cbData = (uint)(2 * (1 + text.Length));
                        IntPtr lParam = new IntPtr((void *)&copyDataStruct);

                        SafeNativeMethods.SendMessageW(ourHwnd, NativeConstants.WM_COPYDATA, this.hWnd, lParam);
                    }
                }

                finally
                {
                    if (szText != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(szText);
                        szText = IntPtr.Zero;
                    }
                }
            }
        }
Esempio n. 5
0
        public static void EnableShield(Button button, bool enableShield)
        {
            if (!warn_enable_shield_shown)
            {
                Console.WriteLine("EnableShieldButton not implemented");
                warn_enable_shield_shown = true;
                return;
            }

#if false
            IntPtr hWnd = button.Handle;

            SafeNativeMethods.SendMessageW(
                hWnd,
                NativeConstants.BCM_SETSHIELD,
                IntPtr.Zero,
                enableShield ? new IntPtr(1) : IntPtr.Zero);

            GC.KeepAlive(button);
#endif
        }
Esempio n. 6
0
        /// <summary>
        /// Manages some special handling of window messages.
        /// </summary>
        /// <param name="m"></param>
        /// <returns>true if the message was handled, false if the caller should handle the message.</returns>
        public bool HandleParentWndProc(ref Message m)
        {
            bool returnVal = true;

            switch (m.Msg)
            {
            case NativeConstants.WM_NCPAINT:
                goto default;

            case NativeConstants.WM_NCACTIVATE:
                if (this.forceActiveTitleBar && m.WParam == IntPtr.Zero)
                {
                    if (ignoreNcActivate > 0)
                    {
                        --ignoreNcActivate;
                        goto default;
                    }
                    else if (Form.ActiveForm != this.host ||      // Gets rid of: if you have the form active, then click on the desktop --> desktop refreshes
                             !this.host.Visible)                  // Gets rid of: desktop refresh on exit
                    {
                        goto default;
                    }
                    else
                    {
                        // Only 'lock' for the topmost form in the application. Otherwise you get the whole system
                        // refreshing (i.e. the dreaded "repaint the whole desktop 5 times" glitch) when you do things
                        // like minimize the window
                        // And only lock if we aren't minimized. Otherwise the desktop refreshes.
                        bool locked = false;
                        if (this.host.Owner == null &&
                            this.host.WindowState != FormWindowState.Minimized)
                        {
                            //UI.SetControlRedraw(this.host, false);
                            locked = true;
                        }

                        this.realParentWndProc(ref m);

                        SafeNativeMethods.SendMessageW(this.host.Handle, NativeConstants.WM_NCACTIVATE,
                                                       new IntPtr(1), IntPtr.Zero);

                        if (locked)
                        {
                            //UI.SetControlRedraw(this.host, true);
                            //this.host.Invalidate(true);
                        }

                        break;
                    }
                }
                else
                {
                    goto default;
                }

            case NativeConstants.WM_ACTIVATE:
                goto default;

            case NativeConstants.WM_ACTIVATEAPP:
                this.realParentWndProc(ref m);

                // Check if the app is being deactivated
                if (this.forceActiveTitleBar && m.WParam == IntPtr.Zero)
                {
                    // If so, put our titlebar in the inactive state
                    SafeNativeMethods.PostMessageW(this.host.Handle, NativeConstants.WM_NCACTIVATE,
                                                   IntPtr.Zero, IntPtr.Zero);

                    ++ignoreNcActivate;
                }

                if (m.WParam == new IntPtr(1))
                {
                    foreach (Form childForm in this.host.OwnedForms)
                    {
                        FormEx childFormEx = FindFormEx(childForm);

                        if (childFormEx != null)
                        {
                            if (childFormEx.ForceActiveTitleBar && childForm.IsHandleCreated)
                            {
                                SafeNativeMethods.PostMessageW(childForm.Handle, NativeConstants.WM_NCACTIVATE,
                                                               new IntPtr(1), IntPtr.Zero);
                            }
                        }
                    }

                    FormEx ownerEx = FindFormEx(this.host.Owner);
                    if (ownerEx != null)
                    {
                        if (ownerEx.ForceActiveTitleBar && this.host.Owner.IsHandleCreated)
                        {
                            SafeNativeMethods.PostMessageW(this.host.Owner.Handle, NativeConstants.WM_NCACTIVATE,
                                                           new IntPtr(1), IntPtr.Zero);
                        }
                    }
                }

                break;

            default:
                returnVal = false;
                break;
            }

            GC.KeepAlive(this.host);
            return(returnVal);
        }
Esempio n. 7
0
 /// <summary>
 /// Sets the control's redraw state.
 /// </summary>
 /// <param name="control">The control whose state should be modified.</param>
 /// <param name="enabled">The new state for redrawing ability.</param>
 /// <remarks>
 /// Note to implementors: This method is used by SuspendControlPainting() and ResumeControlPainting().
 /// This may be implemented as a no-op.
 /// </remarks>
 private static void SetControlRedrawImpl(Control control, bool enabled)
 {
     SafeNativeMethods.SendMessageW(control.Handle, NativeConstants.WM_SETREDRAW, enabled ? new IntPtr(1) : IntPtr.Zero, IntPtr.Zero);
     GC.KeepAlive(control);
 }