日期:2014-05-18  浏览次数:21409 次

C#服务程序FolderBrowserDialog看不见目录树
我写的C#服务程序里用到了FolderBrowserDialog,但是看不见目录树
服务代码如下:
C# code

        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。
            mainThread = new Thread(new ThreadStart(FormShow));
            mainThread.Start();
        }

void      FormShow()
        {
            GetDesktopWindow();
            IntPtr hwinstaSave = GetProcessWindowStation();
            IntPtr dwThreadId = GetCurrentThreadId();
            IntPtr hdeskSave = GetThreadDesktop(dwThreadId);
            IntPtr hwinstaUser = OpenWindowStation("WinSta0", false, 33554432);
            if (hwinstaUser == IntPtr.Zero)
            {
                RpcRevertToSelf();
                return;
            }
            SetProcessWindowStation(hwinstaUser);
            IntPtr hdeskUser = OpenDesktop("Default", 0, false, 33554432);
            RpcRevertToSelf();
            if (hdeskUser == IntPtr.Zero)
            {
                SetProcessWindowStation(hwinstaSave);
                CloseWindowStation(hwinstaUser);
                return;
            }
            SetThreadDesktop(hdeskUser);
            IntPtr dwGuiThreadId = dwThreadId;
            fm = new FormMain();
            Application.Run(fm);
            dwGuiThreadId = IntPtr.Zero;
            SetThreadDesktop(hdeskSave);
            SetProcessWindowStation(hwinstaSave);
            CloseDesktop(hdeskUser);
            CloseWindowStation(hwinstaUser);
        }


打开FolderBrowserDialog的代码如下:
C# code

private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fb = new FolderBrowserDialog();
            fb.ShowNewFolderButton = true;
            fb.RootFolder = Environment.SpecialFolder.Desktop;
            if(fb.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = fb.SelectedPath;
            }
        }



之前看到过提同样问题的帖子了,但是没可用方法。

------解决方案--------------------
看不动