Created
October 13, 2014 14:29
-
-
Save bsorrentino/681fb27eea39404e86c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bsc.jna; | |
import com.sun.jna.Library; | |
import com.sun.jna.Native; | |
import com.sun.jna.Pointer; | |
import com.sun.jna.platform.win32.ShellAPI; | |
import com.sun.jna.platform.win32.ShellAPI.APPBARDATA; | |
import com.sun.jna.platform.win32.WinDef.DWORD; | |
import com.sun.jna.platform.win32.WinDef.HWND; | |
import com.sun.jna.platform.win32.WinDef.UINT_PTR; | |
import com.sun.jna.platform.win32.WinUser; | |
import com.sun.jna.win32.StdCallLibrary; | |
import com.sun.jna.win32.W32APIFunctionMapper; | |
import com.sun.jna.win32.W32APITypeMapper; | |
import java.util.HashMap; | |
import java.util.Map; | |
import javax.swing.JFrame; | |
public class JNADock { | |
private HWND hWndGlobal; | |
private final String frameTitle = "Dockable frame"; | |
public interface Shell32 extends StdCallLibrary { | |
final static Map<String, Object> WIN32API_OPTIONS = new HashMap<String, Object>() { | |
private static final long serialVersionUID = 1L; | |
{ | |
put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); | |
put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); | |
} | |
}; | |
public Shell32 INSTANCE = (Shell32) Native.loadLibrary("Shell32", Shell32.class, WIN32API_OPTIONS); | |
UINT_PTR SHAppBarMessage(DWORD dwMessage, APPBARDATA pData); | |
} | |
public interface User32 extends StdCallLibrary { | |
final static Map<String, Object> WIN32API_OPTIONS = new HashMap<String, Object>() { | |
private static final long serialVersionUID = 1L; | |
{ | |
put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); | |
put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); | |
} | |
}; | |
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class, WIN32API_OPTIONS); | |
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg); | |
int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount); | |
HWND FindWindowA(String winClass, String title); | |
} | |
public static void main(String[] args) { | |
JNADock jna = new JNADock(); | |
} | |
public JNADock() { | |
JFrame frame = new JFrame(frameTitle); | |
frame.setSize(600, 100); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setVisible(true); | |
newAppBar(); | |
frame.setLocation(0,0); | |
} | |
private void newAppBar() { | |
final User32 user32 = User32.INSTANCE; | |
final String title = "Calculator"; | |
hWndGlobal = user32.FindWindowA(null, title); | |
appbarNew(); | |
appbarSetPos(); | |
} | |
private void appbarNew() { | |
APPBARDATA data = new APPBARDATA.ByReference(); | |
data.cbSize.setValue(data.size()); | |
int WM_USER = 0x0400; | |
data.hWnd = hWndGlobal; | |
data.uCallbackMessage.setValue(WM_USER + 1); | |
UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_NEW), data); | |
System.out.println("result: " + result); | |
} | |
private void appbarSetPos() { | |
APPBARDATA data = new APPBARDATA.ByReference(); | |
data.cbSize.setValue(data.size()); | |
data.uEdge.setValue(ShellAPI.ABE_TOP); | |
data.rc.top = 0; | |
data.rc.left = 0; | |
data.rc.bottom = 100; | |
data.rc.right = 600; | |
UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_SETPOS), data); | |
System.out.println("result: " + result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment