本文整理汇总了Java中com.sun.jna.platform.win32.WinUser类的典型用法代码示例。如果您正苦于以下问题:Java WinUser类的具体用法?Java WinUser怎么用?Java WinUser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WinUser类属于com.sun.jna.platform.win32包,在下文中一共展示了WinUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callback
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
@Override
public LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam) {
Logger.getLogger(SSHAgent.class.getName()).log(Level.FINE, "Windows requests operation: {0}", uMsg);
switch (uMsg) {
case MY_WM_COPYDATA: {
return processMessage(hwnd, wParam, lParam);
}
case WinUser.WM_CREATE: {
return new LRESULT(0);
}
case WinUser.WM_DESTROY: {
libU.PostQuitMessage(0);
return new LRESULT(0);
}
default:
return libU.DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
示例2: main
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
public static void main(String[] args) {
final User32 user32 = User32.INSTANCE;
user32.EnumWindows(new WinUser.WNDENUMPROC() {
int count = 0;
@Override
public boolean callback(WinDef.HWND hwnd, Pointer pointer) {
byte[] windowText = new byte[512];
byte[] className = new byte[512];
user32.GetWindowTextA(hwnd, windowText, 512);
user32.GetClassNameA(hwnd, className, 512);
String title = Native.toString(windowText);
String classN = Native.toString(className);
// get rid of this if block if you want all windows regardless of whether
// or not they have text
if (title.isEmpty()) {
return true;
}
System.out.println("Title: " + title + " Class name: " + classN);
return true;
}
},null);
}
示例3: pressKeys
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
public void pressKeys(final List<KeyboardKey> keys) {
if (keys.isEmpty()) {
return;
}
final WinUser.INPUT input = new WinUser.INPUT();
final WinUser.INPUT[] inputs = (WinUser.INPUT[]) input.toArray(keys.size() * 2);
final ListIterator<KeyboardKey> iterator = keys.listIterator();
int index = 0;
while (iterator.hasNext()) {
setKeyDown(inputs[index], iterator.next());
index++;
}
while (iterator.hasPrevious()) {
setKeyUp(inputs[index], iterator.previous());
index++;
}
user32.SendInput(new WinDef.DWORD(inputs.length), inputs, inputs[0].size());
}
示例4: EnumerateWin32ChildWindows
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
public static Map<String, WindowInfo> EnumerateWin32ChildWindows(HWND parentHwnd)
{
final Map<String, WindowInfo> infoList = new LinkedHashMap<String, WindowInfo>();
class ChildWindowCallback implements WinUser.WNDENUMPROC {
@Override
public boolean callback(HWND hWnd, Pointer lParam) {
WindowInfo wi = new WindowInfo(hWnd, true);
infoList.put(wi.hwndStr, wi);
return true;
}
}
Api.User32Ex.instance.EnumChildWindows(parentHwnd, new ChildWindowCallback(), new Pointer(0));
return infoList;
}
示例5: FindMainWindowFromPid
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
public static HWND FindMainWindowFromPid(final long targetProcessId) {
final List<HWND> resultList = new ArrayList<HWND>();
class ParentWindowCallback implements WinUser.WNDENUMPROC {
@Override
public boolean callback(HWND hWnd, Pointer lParam) {
PointerByReference pointer = new PointerByReference();
User32Ex.instance.GetWindowThreadProcessId(hWnd, pointer);
long pid = pointer.getPointer().getInt(0);
if (pid == targetProcessId)
if (resultList.isEmpty())
resultList.add(hWnd);
return true;
}
}
Api.User32Ex.instance.EnumWindows(new ParentWindowCallback(), 0);
if (!resultList.isEmpty())
return resultList.get(0);
return null;
}
示例6: enumerateParentWindowsTest
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
@Test
public void enumerateParentWindowsTest() {
final Map<String, WindowInfo> infoList = new LinkedHashMap<String, WindowInfo>();
class ParentWindowCallback implements WinUser.WNDENUMPROC {
@Override
public boolean callback(HWND hWnd, Pointer lParam) {
output("Getting window info " + Api.GetHandleAsString(hWnd));
//WindowInfo wi = new WindowInfo(hWnd, false);
infoList.put(getWindow32Information(hWnd, false), null);
//Api.User32.instance.EnumChildWindows(hWnd, new ChildWindowCallback(), new Pointer(0));
return true;
}
}
Api.User32Ex.instance.EnumWindows(new ParentWindowCallback(), 0);
output("enumerateParentWindowsTest size: " + infoList.size());
assertTrue(infoList.size() > 0);
}
示例7: main
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
/**
* @param args (ignored)
*/
public static void main(String[] args)
{
System.out.println("Installed Physical Monitors: " + User32.INSTANCE.GetSystemMetrics(WinUser.SM_CMONITORS));
User32.INSTANCE.EnumDisplayMonitors(null, null, new MONITORENUMPROC() {
@Override
public int apply(HMONITOR hMonitor, HDC hdc, RECT rect, LPARAM lparam)
{
enumerate(hMonitor);
return 1;
}
}, new LPARAM(0));
}
示例8: createWindow
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
private static void createWindow(final File f) {
SwingUtilities.invokeLater(() -> {
if (!f.isDirectory()) // if the file was changed or deleted before this could execute, exit
return;
final BDWindow w = new BDWindow(f);
windows.add(w);
w.pack();
w.setVisible(true);
threadPool.execute(() -> {
// sets whether the windows blur the background behind them
Settings.INSTANCE.blurBackground.addListener(enabled -> {
ch.njol.betterdesktop.win32.User32.enableBlur(w, enabled);
});
// disables the windows from being hidden when "peeking" the desktop
Settings.INSTANCE.excludeFromPeek.addListener(enabled -> {
Dwmapi.setExcludedFromPeek(w, enabled);
});
// prevents "show desktop" button from hiding the windows
if (Settings.INSTANCE.showOnDesktop.get()) {
final HWND progman = User32.INSTANCE.FindWindow("Progman", "Program Manager");
User32.INSTANCE.SetWindowLongPtr(new HWND(Native.getComponentPointer(w)), WinUser.GWL_HWNDPARENT, progman.getPointer());
// the following is required so that this setting actually does something - no idea why though
try {
Thread.sleep(100);
} catch (final InterruptedException e1) {}
w.setAlwaysOnTop(true);
w.setAlwaysOnTop(false);
}
});
});
}
示例9: quitProcess
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
/**
* Quits the given process.
*
* @param handle The handle to quit.
*/
public static void quitProcess(final WinDef.HWND handle) {
ensureWinApiInstances();
user32.PostMessage(handle,
WinUser.WM_QUIT,
null,
null);
}
示例10: closeWindow
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
/**
* Closes the given window.
*
* @param handle The handle of the window to close.
*/
public static void closeWindow(final WinDef.HWND handle) {
ensureWinApiInstances();
user32.PostMessage(handle,
WinUser.WM_CLOSE,
null,
null);
}
示例11: setTransparent
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
private void setTransparent(Component w) {
this.componentHwnd = getHWnd(w);
this.settingWl = User32.INSTANCE.GetWindowLong(componentHwnd, WinUser.GWL_EXSTYLE);
int transparentWl = User32.INSTANCE.GetWindowLong(componentHwnd, WinUser.GWL_EXSTYLE) |
WinUser.WS_EX_LAYERED |
WinUser.WS_EX_TRANSPARENT;
User32.INSTANCE.SetWindowLong(componentHwnd, WinUser.GWL_EXSTYLE, transparentWl);
}
示例12: setTransparent
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
private static void setTransparent(Component w) {
WinDef.HWND hwnd = getHWnd(w);
int wl = User32.INSTANCE.GetWindowLong(hwnd, WinUser.GWL_EXSTYLE);
// wl = wl | WinUser.WS_EX_LAYERED | WinUser.WS_EX_TRANSPARENT;
wl = wl | WinUser.WS_EX_LAYERED | WinUser.WS_EX_TRANSPARENT;
User32.INSTANCE.SetWindowLong(hwnd, WinUser.GWL_EXSTYLE, wl);
}
示例13: setMouseHook
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
/**
* Start watching...
*/
public void setMouseHook() {
thrd = new Thread(new Runnable() {
@Override
public void run() {
try {
if (!isHooked) {
hhk = USER32INST.SetWindowsHookEx(14, mouseHook, KERNEL32INST.GetModuleHandle(null), 0);
isHooked = true;
WinUser.MSG msg = new WinUser.MSG();
while ((USER32INST.GetMessage(msg, null, 0, 0)) != 0) {
USER32INST.TranslateMessage(msg);
USER32INST.DispatchMessage(msg);
//System.out.print(isHooked);
if (!isHooked) {
break;
}
}
} else {
}
} catch (Exception e) {
System.err.println(e.getMessage());
System.err.println("Caught exception in MouseHook!");
}
}
}, "Named thread");
threadFinish = false;
thrd.start();
}
示例14: setDisplaySleep
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
public void setDisplaySleep(final boolean sleep) {
user32.DefWindowProc(
getForegroundWindow().get(),
WinUser.WM_SYSCOMMAND,
new WinDef.WPARAM(SC_MONITORPOWER),
new WinDef.LPARAM(sleep ? 2 : -1)
);
}
示例15: run
import com.sun.jna.platform.win32.WinUser; //导入依赖的package包/类
public void run(final String command, final String parameters, final String workingDirectory)
throws SystemException {
final WinDef.INT_PTR result = shell32.ShellExecute(
null,
"open",
Objects.requireNonNull(command),
Objects.requireNonNull(parameters),
workingDirectory,
WinUser.SW_SHOWNORMAL
);
if (result.intValue() <= 32) {
throw new SystemException("Could not run command: " + command + " " + parameters);
}
}