【问题标题】:Windows Application not showing in taskbar on vistaWindows 应用程序未显示在 vista 的任务栏中
【发布时间】:2011-01-22 21:49:42
【问题描述】:
我们有一个在 windows XP 和 windows vista 上运行良好的 C# 应用程序,但不显示任务栏(仅在 Vista 中)。在 windows vista 中,应用程序在底部工具栏中没有图标,即如果我打开应用程序然后我转到另一个应用程序,我可以返回应用程序的唯一方法是通过 alt+tab,我无法单击图标在底部。
该应用程序的其他功能在 XP 和 Vista 中的工作方式相同。请告知如何在 Vista 上恢复此功能?
问候,
【问题讨论】:
标签:
c#
visual-studio
windows-vista
windows-xp
【解决方案1】:
Windows 使用扩展样式位来决定一个窗口是否应该有一个任务栏图标,这些样式在 C# 中不能直接访问,但是当您的窗体是一个普通的应用程序窗体时应该正确设置这些样式。
控制它的标志是在顶级表单窗口的扩展样式中设置的WS_EX_APPWINDOW。来自CreateWindowEx 文档
WS_EX_APPWINDOW 当窗口可见时,将顶层窗口强制放到任务栏上。
您可以使用 Spy++ 查看是否为您的窗口设置了该标志。我确定设置它的唯一方法是使用互操作。
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
const int GWL_EXSTYLE = -20;
const int WS_EX_APPWINDOW = 0x00040000;
int ExStyle = GetWindowLong(form.Handle, GWL_EXSTYLE);
SetWindowLong(form.Handle, GWL_EXSTYLE, new IntPtr(ExStyle | WS_EX_APPWINDOW));
【解决方案2】:
我们通过将表单属性 showintaskbar 属性设置为 true 来修复它。
奇怪的是所有 Windows 操作系统的应用程序运行方式都不相同!