jna getDesktop BringWindowToTop [英] jna getDesktop bringWindowToTop

查看:95
本文介绍了jna getDesktop BringWindowToTop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having problems activating desktop window.

我采用了以下方法

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

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

我在做错什么吗?还是无法通过jna显示桌面?

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

推荐答案

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

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);
   }
}

似乎还有另一种方法可以通过Shell32库调用(涉及ToggleDesktop函数的东西-对于C#版本,请查看此

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.

这篇关于jna getDesktop BringWindowToTop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆