我写了一个小应用程序,禁用C#中 Windows OS 的所有窗口的 Headers 栏和任务栏图标 . 这是代码:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace IconKiller
{
class Program
{
/// Import the needed Windows-API functions:
// ... for enumerating all running desktop windows
[DllImport("user32.dll")]
static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDesktopWindowsDelegate lpfn, IntPtr lParam);
private delegate bool EnumDesktopWindowsDelegate(IntPtr hWnd, int lParam);
// ... for loading an icon
[DllImport("user32.dll")]
static extern IntPtr LoadImage(IntPtr hInst, string lpsz, uint uType, int cxDesired, int cyDesired, uint fuLoad);
// ... for sending messages to other windows
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
/// Setup global variables
// Pointer to empty icon used to replace all other application icons
static IntPtr m_pIcon = IntPtr.Zero;
// Windows API standard values
const int IMAGE_ICON = 1;
const int LR_LOADFROMFILE = 0x10;
const int WM_SETICON = 0x80;
const int ICON_SMALL = 0;
static void Main(string[] args)
{
// Load the empty icon
string strIconFilePath = @"blank.ico";
m_pIcon = LoadImage(IntPtr.Zero, strIconFilePath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
// Setup the break condition for the loop
int counter = 0;
int max = 10 * 60 * 60;
// Loop to catch new opened windows
while (counter < max)
{
// enumerate all desktop windows
EnumDesktopWindows(IntPtr.Zero, new EnumDesktopWindowsDelegate(EnumDesktopWindowsCallback), IntPtr.Zero);
counter++;
System.Threading.Thread.Sleep(100);
}
// ... then restart application
Application.Restart();
}
private static bool EnumDesktopWindowsCallback(IntPtr hWnd, int lParam)
{
// Replace window icon
SendMessage(hWnd, WM_SETICON, ICON_SMALL, m_pIcon);
return true;
}
}
}
此代码似乎适用于本机Windows应用程序 . 我唯一的问题是Java显然使用其应用程序图标的不同实例来显示在任务栏中 . 这意味着我的小应用程序删除了Java程序 Headers 栏中的图标,但没有删除任务栏中的图标(Netbeans就是一个很好的例子) .
如何解决这个问题?是否可以通过JVM将消息传递给那些程序,类似于我在windows API中使用的技巧,在运行Java应用程序或类似的东西上调用 JFrame.setIconImage()
?
编辑:我不仅仅是C#,我非常愿意在java中编写类似“帮助”的应用程序,如果有必要,我会在主应用程序中执行 .
3 回答
这是你在找什么?:
您可以使用Windows API Code Pack覆盖任务栏图标 . Here are some examples .
问题是使用EnumDesktopWindows而不是EnumWindows . 以下代码在我的电脑上正常工作: