日期:2014-05-18 浏览次数:21409 次
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); }
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; } }