私はWindows OSのすべてのウィンドウのタイトルバーとタスクバーのアイコンをC#で無効にする小さなアプリケーションを作成しました。コードは次のとおりです。Windows 7でJavaプログラムのタイトルバーとタスクバーアイコンを削除するにはどうすればよいですか?
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;
}
}
}
このコードは、ネイティブウィンドウアプリケーションで正常に動作するようです。私の唯一の問題は、Javaが明らかにアプリケーションアイコンの別のインスタンスを使用してタスクバーに表示されることです。私の小さなアプリケーションがJavaプログラムのタイトルバーのアイコンを削除するが、タスクバーのアイコンは削除されないことを意味する(Netbeansは良い例である)。
この問題を解決するにはどうすればよいですか? JVMを介してメッセージを渡すことは可能でしょうか?ウィンドウAPIで使用したトリックと同様に、実行中のJavaアプリケーションやその行にあるJFrame.setIconImage()
を呼び出しますか?
編集:私はちょうどのC#にバインドされていないです、私は私が私のメインアプリで実行しますJavaで「ヘルパー」アプリのようなものを書くのはとても喜んで、それが必要でなければなりません。
私は好奇心が強い...あなたが視覚的にあなたがこれを試してみました – Gus
アプリケーションを区別する簡単な方法を提供し、アイコンを取り除きたいなぜ? http://stackoverflow.com/questions/50398/calling-c-sharp-code-from-java – Diego
@Diegoどうすれば助けになるのでしょうか?タスクバーに表示され、アイコンを変更したくない – hvd