我一直在努力从我的应用程序的任务栏中隐藏另一个应用程序。
我一直在使用SetWindowLong函数来设置/删除扩展样式。WS_EX_APPWINDOW
我已经尝试单独设置和删除属性以及获取 current WindowLong
,并将其删除/添加到该属性,如下所示:
SetWindowLong(pMainWindow, GWL_EXSTYLE, GetWindowLong(pMainWindow) & WS_EX_APPWINDOW);
并尝试像这样删除它:
SetWindowLong(pMainWindow, GWL_EXSTYLE, GetWindowLong(pMainWindow) & ~WS_EX_APPWINDOW);
还尝试了这两种方法,但没有先让窗口变长。这是我的整个代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
[DllImport("User32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_HIDE = 0x00;
private const int SW_SHOW = 0x05;
private const int WS_EX_APPWINDOW = 0x40000;
private const int GWL_EXSTYLE = -0x14;
private void HideWindowFromTaskbar(IntPtr pMainWindow)
{
SetWindowLong(pMainWindow, GWL_EXSTYLE, ~WS_EX_APPWINDOW);
ShowWindow(pMainWindow, SW_HIDE);
ShowWindow(pMainWindow, SW_SHOW);
}
private void ButtonHide_Click(object sender, RoutedEventArgs e)
{
HideWindowFromTaskbar(Process.GetProcessesByName("notepad")[0].MainWindowHandle);
}
}
我注意到 Spy++ 在查看属性时发生了变化。我有一堆不同的结果,比如WS_EX_APPWINDOW
被添加,但也随机有其他属性消失等。
在查看消息时,我还看到它确实收到了类似STYLE_CHANGED
.