Có cách nào để đưa con trỏ HWnd đến cửa sổ trên cùng của Visual Studio 2010 từ phần mở rộng VSIX không? (Tôi muốn thay đổi tiêu đề của cửa sổ).HWnd của Visual Studio 2010
Trả lời
Vì có cơ hội tốt mà mở rộng VSIX của bạn sẽ được chạy trong quá trình với Visual Studio, bạn nên cố gắng này:
System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle
(Lưu ý nếu bạn làm điều này quá sớm, bạn sẽ nhận được VS Splash màn hình ...)
Tôi giả sử bạn muốn thực hiện điều này một cách có lập trình trong C#?
Bạn sẽ cần phải xác định P/Invoke bên trong lớp học của bạn:
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
Sau đó, có một số mã trông tương tự như sau:
Process visualStudioProcess = null;
//Process[] allProcesses = Process.GetProcessesByName("VCSExpress"); // Only do this if you know the exact process name
// Grab all of the currently running processes
Process[] allProcesses = Process.GetProcesses();
foreach (Process process in allProcesses)
{
// My process is called "VCSExpress" because I have C# Express, but for as long as I've known, it's been called "devenv". Change this as required
if (process.ProcessName.ToLower() == "vcsexpress" ||
process.ProcessName.ToLower() == "devenv"
/* Other possibilities*/)
{
// We have found the process we were looking for
visualStudioProcess = process;
break;
}
}
// This is done outside of the loop because I'm assuming you may want to do other things with the process
if (visualStudioProcess != null)
{
SetWindowText(visualStudioProcess.MainWindowHandle, "Hello World");
}
Doc trên Process: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
Tài liệu trên P/Gọi: http://msdn.microsoft.com/en-us/library/aa288468%28VS.71%29.aspx
. Thử mã này trên máy cục bộ của tôi, có vẻ như đặt tiêu đề cửa sổ, nhưng Visual Studio ghi đè nó trong nhiều điều kiện: tăng tiêu điểm, vào/rời khỏi chế độ gỡ lỗi ... Điều này có thể rắc rối.
Lưu ý: Bạn có thể TẢI tiêu đề cửa sổ ngay từ đối tượng Quy trình, nhưng bạn không thể đặt nó.
Bạn có thể sử dụng EnvDTE API để có được những hWnd của cửa sổ chính:
var hwndMainWindow = (IntPtr) dte.MainWindow.HWnd;
trong Visual Studio 2010/2012, cửa sổ chính và một phần của điều khiển người dùng được triển khai bằng WPF. Bạn có thể ngay lập tức nhận được cửa sổ WPF của cửa sổ chính và làm việc với nó. Tôi đã viết phương pháp mở rộng sau cho việc này:
public static Window GetWpfMainWindow(this EnvDTE.DTE dte)
{
if (dte == null)
{
throw new ArgumentNullException("dte");
}
var hwndMainWindow = (IntPtr)dte.MainWindow.HWnd;
if (hwndMainWindow == IntPtr.Zero)
{
throw new NullReferenceException("DTE.MainWindow.HWnd is null.");
}
var hwndSource = HwndSource.FromHwnd(hwndMainWindow);
if (hwndSource == null)
{
throw new NullReferenceException("HwndSource for DTE.MainWindow is null.");
}
return (Window) hwndSource.RootVisual;
}
- 1. WebsiteSpark & Visual Studio 2010
- 2. Visual Studio 2010 - RemovePreviousVersions
- 3. UnInstall Visual Studio 2010
- 4. NUnit vs MSTest của Visual Studio 2010?
- 5. Visual Studio 2010 "INS" & "OVR"
- 6. GTK # trong Visual Studio 2010
- 7. /LinkResource trong Visual Studio 2010
- 8. Dự án Visual Studio 2010 cho Visual Studio 2012
- 9. Visual Studio 2010 Snippet Generator
- 10. Ctrl-Backspace Visual Studio 2010
- 11. Java trong Visual Studio 2010?
- 12. Visual Studio 2010 Team Explorer
- 13. ExtJS trong Visual Studio (2010)
- 14. Visual Studio 2010 chủ đề cho Visual Studio 2012?
- 15. Visual Studio 2010 không thể mở một giải pháp 2010 Visual Studio 2012 sửa đổi
- 16. Microsoft Visual Studio 2010 Academic Edition
- 17. Visual Studio 2008/2010 Mã Bookmarks Backup
- 18. Phát triển Sharepoint trong Visual Studio 2010
- 19. System.OutOfMemoryException khi sử dụng Visual Studio 2010
- 20. Visual Studio 2010 Biến màu SQL
- 21. Visual Studio 2010 MEF so với MPF?
- 22. Visual Studio 2010 Publishing Vì vậy, chậm
- 23. Thư mục nguồn trong Visual Studio 2010
- 24. vấn đề với Visual Studio 2010
- 25. Visual studio 2010 intellisense ngừng hoạt động
- 26. định dạng HTML trong Visual Studio 2010
- 27. Visual Studio 2010 phông chữ mờ
- 28. visual studio 2010: biểu đồ phụ thuộc
- 29. Visual Studio 2010: Nhúng Interop loại
- 30. ReportViewer 11 (2012) Visual Studio 2010
Cảm ơn thông tin. Điều này đã dẫn tôi đến một giải pháp đơn giản hơn. Process.GetCurrentProcess() MainWindowHandle –
VS sẽ tiếp tục ghi đè lên tiêu đề. Nó được thảo luận ở đây: http://stackoverflow.com/questions/577188/how-to-change-the-title-bar-text-of-visual-studio –