protected virtual void OnSelectedFolderChanged(
     SelectedFolderChangedEventArgs args)
 {
     if (SelectedFolderChanged != null)
     {
         SelectedFolderChanged(this, args);
     }
 }
Example #2
0
        // ------------------------------------------------------------------
        #endregion

        #region Private methods.
        // ------------------------------------------------------------------

        private int extendedFolderBrowserDialogBrowseCallbackProc(
            IntPtr hwnd,
            int msg,
            IntPtr lParam,
            IntPtr lpData)
        {
            switch (msg)
            {
            case Win32.BFFM_INITIALIZED:
                if (_selectedPath.Length != 0)
                {
                    Win32.SendMessage(
                        new HandleRef(null, hwnd),
                        Win32.BFFM_SETSELECTION,
                        1,
                        _selectedPath);

                    //centerToScreen(hwnd);

                    _nativeWindow = new MyNativeWindow(this);
                    _nativeWindow.AssignHandle(hwnd);
                }
                break;

            case Win32.BFFM_SELCHANGED:
            {
                //centerToScreen(hwnd);

                var ptr1 = lParam;
                if (ptr1 != IntPtr.Zero)
                {
                    // --

                    if (_selectedPath.Length != 0)
                    {
                        // Work-around bug_ in Windows 7 that the selected item is not visible.
                        // http://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7
                        // http://stackoverflow.com/questions/7014190/why-is-enumchildwindows-skipping-children
                        // http://www.ureader.com/msg/14842617.aspx
                        // http://stackoverflow.com/questions/3660556/how-to-select-an-item-in-a-treeview-using-win32-api

                        var childWindows = GetChildWindows(hwnd);

                        if (childWindows.Count > 0)
                        {
                            var hWndTree = childWindows[0];

                            var treeItem =
                                Win32.SendMessage(
                                    new HandleRef(null, hWndTree),
                                    Win32.TVM_GETNEXTITEM,
                                    Win32.TVGN_CARET,
                                    0);

                            Win32.SendMessage(
                                new HandleRef(null, hWndTree),
                                Win32.TVM_ENSUREVISIBLE,
                                0,
                                treeItem);
                        }
                    }

                    // --

                    var ptr2       = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize);
                    var flag1      = Win32.Shell32.SHGetPathFromIDList(ptr1, ptr2);
                    var folderPath = Marshal.PtrToStringAuto(ptr2);
                    Marshal.FreeHGlobal(ptr2);

                    var enable = flag1;
                    if (flag1)
                    {
                        var args =
                            new SelectedFolderChangedEventArgs(
                                ptr1,
                                folderPath);

                        OnSelectedFolderChanged(args);

                        enable = args.EnableOK;
                    }

                    Win32.SendMessage(
                        new HandleRef(null, hwnd),
                        Win32.BFFM_ENABLEOK,
                        0,
                        enable ? 1 : 0);
                }
                break;
            }
            }
            return(0);
        }
Example #3
0
 protected virtual void OnSelectedFolderChanged(
     SelectedFolderChangedEventArgs args)
 {
     SelectedFolderChanged?.Invoke(this, args);
 }