jna getDesktop BringWindowToTop

发布于 2024-12-08 16:55:15 字数 241 浏览 0 评论 0原文

我在激活桌面窗口时遇到问题。

我采取了以下方法

1:GetDesktopWindow来检索桌面的句柄(这有效) 我尝试过以下方法将桌面窗口置于顶部,但它们不起作用。

   SetForegroundWindow 
   SwitchToThisWindow
   ShowWindow
   BringWindowToTop

我做错了什么吗?或者用jna无法显示桌面?

I'm having problems activating desktop window.

I have taken the following approach

1: GetDesktopWindow to retrieve the handle of desktop (This works)
I have tried the following methods to bring desktop window to top, but they did not work.

   SetForegroundWindow 
   SwitchToThisWindow
   ShowWindow
   BringWindowToTop

Is there something i'm doing wrong? Or is not possible to show desktop with jna?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2024-12-15 16:55:15

一种方法是获取任务栏的句柄并向其发送一条消息以隐藏所有窗口,也许像这样的方法在 Windows 7 上对我有用:

import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.win32.W32APIOptions;

public class ToggleDesktop3 {
   public interface User32 extends W32APIOptions {
      public static final String SHELL_TRAY_WND = "Shell_TrayWnd";
      public static final int WM_COMMAND = 0x111;
      public static final int MIN_ALL = 0x1a3;
      public static final int MIN_ALL_UNDO = 0x1a0;

      User32 instance = (User32) Native.loadLibrary("user32", User32.class,
            DEFAULT_OPTIONS);

      HWND FindWindow(String winClass, String title);

      long SendMessageA(HWND hWnd, int msg, int num1, int num2);
   }

   public static void main(String[] args) {
      // get the taskbar's window handle
      HWND shellTrayHwnd = User32.instance.FindWindow(User32.SHELL_TRAY_WND,
            null);

      // use it to minimize all windows
      User32.instance.SendMessageA(shellTrayHwnd, User32.WM_COMMAND,
            User32.MIN_ALL, 0);

      // sleep for 3 seconds
      try {
         Thread.sleep(3000);
      } catch (InterruptedException e) {
      }

      // then restore previously minimized windows
      User32.instance.SendMessageA(shellTrayHwnd, User32.WM_COMMAND,
            User32.MIN_ALL_UNDO, 0);
   }
}

看起来还有另一种方法可以通过 Shell32 库调用(涉及 ToggleDesktop function -- 对于 C# 版本,请查看此 SO 链接),但我还没有让它发挥作用。

One way is to do get the taskbar's handle and send it a message to hide all windows, perhaps something like this which has worked for me on Windows 7:

import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.win32.W32APIOptions;

public class ToggleDesktop3 {
   public interface User32 extends W32APIOptions {
      public static final String SHELL_TRAY_WND = "Shell_TrayWnd";
      public static final int WM_COMMAND = 0x111;
      public static final int MIN_ALL = 0x1a3;
      public static final int MIN_ALL_UNDO = 0x1a0;

      User32 instance = (User32) Native.loadLibrary("user32", User32.class,
            DEFAULT_OPTIONS);

      HWND FindWindow(String winClass, String title);

      long SendMessageA(HWND hWnd, int msg, int num1, int num2);
   }

   public static void main(String[] args) {
      // get the taskbar's window handle
      HWND shellTrayHwnd = User32.instance.FindWindow(User32.SHELL_TRAY_WND,
            null);

      // use it to minimize all windows
      User32.instance.SendMessageA(shellTrayHwnd, User32.WM_COMMAND,
            User32.MIN_ALL, 0);

      // sleep for 3 seconds
      try {
         Thread.sleep(3000);
      } catch (InterruptedException e) {
      }

      // then restore previously minimized windows
      User32.instance.SendMessageA(shellTrayHwnd, User32.WM_COMMAND,
            User32.MIN_ALL_UNDO, 0);
   }
}

There looks to be another way to do this via Shell32 library calls (something involving the ToggleDesktop function -- for a C# version, check out this SO link), but I've not gotten it to work yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文