本文整理汇总了Java中com.sun.jna.platform.win32.User32类的典型用法代码示例。如果您正苦于以下问题:Java User32类的具体用法?Java User32怎么用?Java User32使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
User32类属于com.sun.jna.platform.win32包,在下文中一共展示了User32类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
@Override
public void init() {
super.init();
WindowManager.createWindow(handle, window, true);
long hwndGLFW = glfwGetWin32Window(window.getID());
HWND hwnd = new HWND(Pointer.createConstant(hwndGLFW));
WindowProc proc = new WindowProc() {
@Override
public long invoke(long hw, int uMsg, long wParam, long lParam) {
if (hw == hwndGLFW)
switch (uMsg) {
case WM_WINDOWPOSCHANGING:
WINDOWPOS pos = new WINDOWPOS(new Pointer(lParam));
pos.flags |= SWP_NOZORDER | SWP_NOACTIVATE;
pos.write();
break;
}
return org.lwjgl.system.windows.User32.DefWindowProc(hw, uMsg, wParam, lParam);
}
};
User32.INSTANCE.SetWindowLongPtr(hwnd, GWL_WNDPROC, Pointer.createConstant(proc.address()));
User32Ext.INSTANCE.SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
User32Ext.INSTANCE.SetWindowLongPtr(hwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
User32.INSTANCE.SetWindowPos(hwnd, new HWND(Pointer.createConstant(HWND_BOTTOM)), 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
wallpaper = window.getResourceLoader().loadNVGTexture(getCurrentDesktopWallpaper(), true);
TaskManager.addTask(() -> window.setVisible(true));
}
示例2: getAppUserModelId
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
public static String getAppUserModelId(HWND hwnd) {
IntByReference processID = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(hwnd, processID);
HANDLE hProcess = Kernel32.INSTANCE.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, processID.getValue());
UINTByReference length = new UINTByReference();
Kernel32Ext.INSTANCE.GetApplicationUserModelId(hProcess, length, null);
char[] modelID = new char[length.getValue().intValue()];
Kernel32Ext.INSTANCE.GetApplicationUserModelId(hProcess, length, modelID);
return new String(Native.toString(modelID));
}
示例3: createHotKeys
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
private void createHotKeys() {
Thread keys = new Thread(() -> {
keysThreadID = Kernel32.INSTANCE.GetCurrentThreadId();
User32.INSTANCE.RegisterHotKey(new HWND(Pointer.NULL), 1, MOD_WIN | MOD_NOREPEAT, VK_E);
MSG msg = new MSG();
while (User32.INSTANCE.GetMessage(msg, new HWND(Pointer.NULL), 0, 0) != 0 && running) {
if (msg.message == WM_HOTKEY) {
try {
switch (msg.wParam.intValue()) {
case 1:
new ProcessBuilder("explorer.exe", ",").start();
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
User32.INSTANCE.UnregisterHotKey(Pointer.NULL, 1);
});
keys.start();
}
示例4: dispose
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
@Override
public void dispose() {
super.dispose();
window.dispose(AppUI.getMainWindow());
if (ENABLED_NOTIFICATIONS)
TrayHook.INSTANCE.UnregisterSystemTrayHook();
User32Ext.INSTANCE.SystemParametersInfo(SPI.SPI_SETWORKAREA, 0, old.getPointer(), 0);
User32Ext.INSTANCE.DeregisterShellHookWindow(local);
if (noExplorer) {
backgroundWindow.getWindow().closeDisplay();
User32.INSTANCE.PostThreadMessage(keysThreadID, WM_QUIT, new WPARAM(), new LPARAM());
User32Ext.INSTANCE.SystemParametersInfo(SPI.SPI_SETMINIMIZEDMETRICS, oldMM.size(), oldMM.getPointer(), 0);
} else {
if (taskbar != null)
User32.INSTANCE.ShowWindow(taskbar, SW_SHOW);
}
}
示例5: quit
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
/**
* Quits the process.
*
* @param titlePattern a pattern matching the title of the window of the process to quit
*/
public void quit(final Pattern titlePattern) {
if (user32 == null) {
user32 = User32.INSTANCE;
}
final WinDef.HWND handle = Utils.findWindow(null, titlePattern);
if (handle != null) {
Utils.quitProcess(handle);
}
}
示例6: testStartProcess_Starts_Notepad
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
@Test
public void testStartProcess_Starts_Notepad() {
try {
Utils.startProcess("notepad.exe");
this.andRest();
WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null, getLocal("notepad.title"));
assertTrue("startProcess - no process", hwnd != null);
} catch (IOException io) {
assertTrue("startProcess: " + io.getMessage(), false);
}
assertTrue("startProcess", true);
}
示例7: testQuitProcess_Quits_Notepad
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
@Test
public void testQuitProcess_Quits_Notepad() {
try {
Utils.startProcess("notepad.exe");
WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null, getLocal("notepad.title"));
if (hwnd != null) {
Utils.quitProcess(hwnd);
}
} catch (IOException io) {
assertTrue("quitProcess: " + io.getMessage(), false);
}
assertTrue("quitProcess", true);
}
示例8: testCloseWindow_Closes_Notepad
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
@Test
public void testCloseWindow_Closes_Notepad() {
try {
Utils.startProcess("notepad.exe");
WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null, getLocal("notepad.title"));
if (hwnd != null) {
Utils.closeWindow(hwnd);
}
} catch (IOException io) {
assertTrue("quitProcess: " + io.getMessage(), false);
}
assertTrue("quitProcess", true);
}
示例9: gameToFront
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
private void gameToFront() {
User32.INSTANCE.EnumWindows((hWnd, arg1) -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(hWnd, className, 512);
String wText = Native.toString(className);
if (wText.isEmpty()) {
return true;
}
if (wText.equals("POEWindowClass")) {
User32.INSTANCE.SetForegroundWindow(hWnd);
return false;
}
return true;
}, null);
}
示例10: createWindowsProcess
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
private HWND createWindowsProcess() {
WString windowClass = new WString(APPNAME);
HMODULE hInst = libK.GetModuleHandle("");
WNDCLASSEX wndclass = new WNDCLASSEX();
wndclass.hInstance = hInst;
wndclass.lpfnWndProc = SSHAgent.this;
wndclass.lpszClassName = windowClass;
// register window class
libU.RegisterClassEx(wndclass);
getLastError();
// create new window
HWND winprocess = libU
.CreateWindowEx(
User32.WS_OVERLAPPED,
windowClass,
APPNAME,
0, 0, 0, 0, 0,
null, // WM_DEVICECHANGE contradicts parent=WinUser.HWND_MESSAGE
null, hInst, null);
mutex = libK.CreateMutex(null, false, MUTEX_NAME);
return winprocess;
}
示例11: getNativeWindowHandles
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
/**
* Gets the native window handles.
*
* @return the native window handles
*/
private void getNativeWindowHandles()
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
HWND fgWindow = User32.INSTANCE.GetForegroundWindow();
int titleLength = User32.INSTANCE.GetWindowTextLength(fgWindow) + 1;
char[] title = new char[titleLength];
User32.INSTANCE.GetWindowText(fgWindow, title, titleLength);
int awtCanvasHandle = (int) Pointer.nativeValue(fgWindow.getPointer());
setApplicationHandle(awtCanvasHandle);
}
});
}
示例12: capture
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
public BufferedImage capture(final HWND hWnd) {
final HDC hdcWindow = User32.INSTANCE.GetDC(hWnd);
final HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow);
final RECT bounds = new RECT();
User32Extra.INSTANCE.GetClientRect(hWnd, bounds);
final int width = bounds.right - bounds.left;
final int height = bounds.bottom - bounds.top;
if (width * height <= 0) { return null; }
final HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height);
final HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap);
GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY);
GDI32.INSTANCE.SelectObject(hdcMemDC, hOld);
GDI32.INSTANCE.DeleteDC(hdcMemDC);
final BITMAPINFO bmi = new BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
final Memory buffer = new Memory(width * height * 4);
GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, buffer.getIntArray(0, width * height), 0, width);
GDI32.INSTANCE.DeleteObject(hBitmap);
User32.INSTANCE.ReleaseDC(hWnd, hdcWindow);
return image;
}
示例13: createHotKeysHook
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
public void createHotKeysHook() {
registerAllHotKeys();
//User32Ex.instance.MsgWaitForMultipleObjects(0, Pointer.NULL, true, INFINITE, QS_HOTKEY);
//System.out.println("starting message loop");
MSG msg = new MSG();
try {
while (!quit) {
User32.INSTANCE.PeekMessage(msg, null, 0, 0, 1);
if (msg.message == User32.WM_HOTKEY){ // && msg.wParam.intValue() == 1
//System.out.println("Hot key pressed " + msg.wParam);
TargetKeyPress target = findTargetKeyPressById(msg.wParam.intValue());
if (target != null)
events.keyPressed(target);
msg = new MSG(); //must clear msg so it doesn't repeat
}
Thread.sleep(10);
}
} catch (Exception e) {
e.printStackTrace();
}
unregisterAllHotKeys();
//System.out.println("message loop stopped");
}
示例14: registerAllHotKeys
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
private void registerAllHotKeys() // must register hot keys in the same thread that is watching for hotkey messages
{
//System.out.println("registering hotkeys");
for (TargetKeyPress tkp : KeyboardHook.targetList) {
//BOOL WINAPI RegisterHotKey(HWND hWnd, int id, UINT fsModifiers, UINT vk);
int modifiers = User32.MOD_NOREPEAT;
if (tkp.withShift)
modifiers = modifiers | User32.MOD_SHIFT;
if (tkp.withCtrl)
modifiers = modifiers | User32.MOD_CONTROL;
if (tkp.withAlt)
modifiers = modifiers | User32.MOD_ALT;
//System.out.println("RegisterHotKey " + tkp.idNumber + "," + modifiers + ", " + tkp.targetKeyCode);
if (!User32.INSTANCE.RegisterHotKey(new WinDef.HWND(Pointer.NULL), tkp.idNumber, modifiers, tkp.targetKeyCode))
{
System.out.println("Couldn't register hotkey " + tkp.targetKeyCode);
}
}
}
示例15: getHandle
import com.sun.jna.platform.win32.User32; //导入依赖的package包/类
@Test
public void getHandle() {
Assert.assertNull(Win.getHandle(NOTEPAD_TITLE));
Assert.assertNull(Win.getHandle((HWND) null));
// run notepad
int pid = runNotepad();
HWND hWnd = Win.getHandle_(NOTEPAD_TITLE);
Assert.assertNotNull(hWnd);
assertEquals(
AutoItX.hwndToHandle(User32.INSTANCE.GetForegroundWindow()),
Win.getHandle(NOTEPAD_TITLE));
assertEquals(
AutoItX.hwndToHandle(User32.INSTANCE.GetForegroundWindow()),
Win.getHandle(hWnd));
// close notepad
closeNotepad(pid);
Assert.assertNull(Win.getHandle(NOTEPAD_TITLE));
Assert.assertNull(Win.getHandle(hWnd));
}