java 隐藏任务栏,在Java中隐藏Windows任务栏?

I want to hide the Windows taskbar with Java. How can I do this? My compiler is Eclipse with JDK 7. I have tried using setSize() to go to full resolution, but the taskbar goes in front of it.

解决方案

Yes, you can by using JNA, adopted from technet forums some help from a JNA FindWindow question and reading the JNA source code for Win32:

Warning: This isn't the same as auto-hide. To get it back, you'll need to invoke ShowWindow again, but with SW_SHOW.

private static int SW_HIDE = 0;

private static int SW_SHOW = 1;

public static void main(String... args) throws Exception {

WinDef.HWND shellTray = User32.INSTANCE.FindWindow("Shell_TrayWnd", "");

User32.INSTANCE.ShowWindow(shellTray, SW_HIDE);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要获取任务栏打开的程序并将其顶置,可以使用Java的AWT和JNI(Java Native Interface)技术。 下面是一个简单的示例代码,可以实现获取任务栏打开的程序并将其顶置: ```java import java.awt.*; public class SetTopTaskbarWindow { public static void main(String[] args) { String windowTitle = "MyWindow"; // 要顶置的窗口标题 int hwnd = findWindow(windowTitle); // 获取窗口句柄 setWindowTop(hwnd); // 将窗口设置为顶置窗口 } // 查找窗口句柄 private static int findWindow(String windowTitle) { int hwnd = 0; hwnd = User32.INSTANCE.FindWindow(null, windowTitle); return hwnd; } // 将窗口设置为顶置窗口 private static void setWindowTop(int hwnd) { User32.INSTANCE.SetForegroundWindow(hwnd); } // 获取任务栏打开的程序并将其顶置 private static void setTopTaskbarWindow() { User32.INSTANCE.SetForegroundWindow(User32.INSTANCE.FindWindow("Shell_TrayWnd", null)); User32.INSTANCE.SetForegroundWindow(User32.INSTANCE.FindWindowEx(0, 0, "Button", null)); } } // 使用JNI调用Windows API interface User32 extends W32APIOptions { User32 INSTANCE = Native.load("user32", User32.class, DEFAULT_OPTIONS); boolean SetForegroundWindow(int hwnd); int FindWindow(String lpClassName, String lpWindowName); int FindWindowEx(int parent, int child, String className, String windowName); } ``` 需要注意的是,这段代码只能在Windows操作系统上运行,因为它使用了Windows API。如果要在其他操作系统上运行,需要使用相应的API。 `setTopTaskbarWindow()`方法,首先将任务栏(Shell_TrayWnd)窗口设置为顶置窗口,然后将任务栏上的第一个按钮(Button)设置为顶置窗口,这样就可以获取任务栏打开的程序并将其顶置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值