很早之前我就想使用Java做个动态可交互的WIN10壁纸,但是在网上查询大部分都是使用C++,Python制作的,我花了将近一天的时间研究。发现还是可以的,无论是C++还是Python实际都是调用user32.dll,Java通过JNA也可以调用该DLL
JNA依赖
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.8.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.8.0</version>
</dependency>
关键代码
WinDef.HWND hide=null;
new Thread(TestFrame::new).start();
User32 user32 = User32.INSTANCE;
WinDef.HWND windowHandle = user32.FindWindow("Progman", null);
user32.SendMessageTimeout(windowHandle, 0x052c, null, null, SMTO_NORMAL,
0x3e8, null);
user32.EnumWindows((hWnd, data) -> {
WinDef.HWND defview = user32.FindWindowEx(hWnd, null, "SHELLDLL_DefView", null);
if (defview != null) {
hide = user32.FindWindowEx(null, hWnd, "WorkerW", null);
}
return true;
}, null);
user32.ShowWindow(hide, SW_HIDE);
WinDef.HWND hwnd = user32.FindWindow(null, "BG_FRAME");
user32.SetParent(hwnd,windowHandle);
全部相关代码下载:http://49.234.47.204:2222/s/6383x8iS9nFx9gp
效果
主要查考文章
https://zhuanlan.zhihu.com/p/37877070
|