我在激活桌面窗口时遇到问题.
我采取了以下方法
1:GetDesktopWindow检索桌面的句柄(这个工作)我已经尝试了以下方法将桌面窗口置于顶部,但它们不起作用.
SetForegroundWindow
SwitchToThisWindow
ShowWindow
BringWindowToTop
Run Code Online (Sandbox Code Playgroud)
有什么我做错了吗?或者不可能用jna显示桌面?
一种方法是获取任务栏的句柄并向其发送一条消息以隐藏所有窗口,也许这样的东西在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);
}
}
Run Code Online (Sandbox Code Playgroud)
看起来有另一种方法可以通过Shell32库调用来执行此操作(涉及ToggleDesktop函数 - 对于C#版本,请查看此SO链接),但我还没有让它工作.