Tôi đã viết một ứng dụng nhỏ vô hiệu hóa thanh tiêu đề và biểu tượng thanh tác vụ của tất cả các cửa sổ của HĐH Windows trong C#. Đây là mã:Làm thế nào tôi có thể loại bỏ các thanh tiêu đề và thanh tác vụ của các chương trình Java trên Windows 7?
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;
}
}
}
Mã này có vẻ hoạt động tốt với các ứng dụng cửa sổ gốc. Vấn đề duy nhất của tôi bây giờ là Java rõ ràng sử dụng một thể hiện khác của biểu tượng ứng dụng của nó để hiển thị trong thanh tác vụ. Có nghĩa là ứng dụng nhỏ của tôi loại bỏ biểu tượng trong thanh tiêu đề của các chương trình Java, nhưng không phải là một trong thanh tác vụ (Netbeans là một ví dụ tốt).
Cách giải quyết vấn đề đó? Có thể truyền thông điệp tới các chương trình đó thông qua JVM, tương tự như mẹo tôi đã sử dụng với API cửa sổ, để gọi JFrame.setIconImage()
khi chạy các ứng dụng Java hay gì đó dọc theo các dòng đó không?
EDIT: Tôi không bị ràng buộc chỉ C#, tôi rất sẵn sàng viết một cái gì đó giống như một ứng dụng "trợ giúp" trong java mà tôi sẽ thực hiện trong ứng dụng chính của tôi, nếu cần thiết.
Tôi tò mò ... tại sao bạn muốn loại bỏ các biểu tượng cung cấp cách dễ dàng phân biệt các ứng dụng – Gus
Bạn đã thử cách này chưa? http://stackoverflow.com/questions/50398/calling-c-sharp-code-from-java – Diego
@Diego Điều đó sẽ giúp ích như thế nào? – hvd