From 855845761cdffdcb748d33fce5e93d2f454e176e Mon Sep 17 00:00:00 2001 From: Lyor Goldstein Date: Wed, 19 Aug 2015 15:45:53 +0300 Subject: [PATCH] Added GetRawInputDeviceList definition and utility to User32 interface --- CHANGES.md | 1 + .../com/sun/jna/platform/win32/User32.java | 24 + .../sun/jna/platform/win32/User32Util.java | 29 + .../src/com/sun/jna/platform/win32/WinNT.java | 5 + .../com/sun/jna/platform/win32/WinUser.java | 883 ++++++++++-------- .../jna/platform/win32/User32UtilTest.java | 19 +- 6 files changed, 546 insertions(+), 415 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 48d2928f1d..9dcb9d8432 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -51,6 +51,7 @@ Features * [#481] (https://github.com/twall/jna/pull/481): Added volume management functions to 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein). * [#483] (https://github.com/twall/jna/pull/483): Found and fixed duplicate method definitions for the same API in 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein). * [#485] (https://github.com/twall/jna/pull/485): Implemented Comparable interface for many of the base types in 'com.sun.jna.platform.win32.WinDef' - [@lgoldstein](https://github.com/lgoldstein). +* [#488] (https://github.com/twall/jna/pull/488): Added GetRawInputDeviceList definition and utility to 'com.sun.jna.platform.win32' User32 and User32Util - [@lgoldstein](https://github.com/lgoldstein). Bug Fixes --------- diff --git a/contrib/platform/src/com/sun/jna/platform/win32/User32.java b/contrib/platform/src/com/sun/jna/platform/win32/User32.java index 5614cbe507..27f2605d7b 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/User32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/User32.java @@ -1983,4 +1983,28 @@ long SendMessageTimeout(HWND hWnd, int msg, long wParam, long lParam, * error information, call {@link Kernel32#GetLastError()}. */ long GetClassLongPtr(HWND hWnd, int nIndex); + + /** + * @param pRawInputDeviceList + * An array of {@link RAWINPUTDEVICELIST} structures for the devices + * attached to the system. If (@code null}, the number of devices is + * returned in puiNumDevices + * @param puiNumDevices + * If pRawInputDeviceList is {@code null}, the function populates + * this variable with the number of devices attached to the system; + * otherwise, this variable specifies the number of {@link RAWINPUTDEVICELIST} + * structures that can be contained in the buffer to which pRawInputDeviceList + * points. If this value is less than the number of devices attached to + * the system, the function returns the actual number of devices in this + * variable and fails with ERROR_INSUFFICIENT_BUFFER. + * @param cbSize + * The size of a {@link RAWINPUTDEVICELIST} structure, in bytes. + * @return If the function is successful, the return value is the number of devices + * stored in the buffer pointed to by pRawInputDeviceList. On + * any other error, the function returns -1 and {@code GetLastError} + * returns the error indication. + * @see RAWINPUTDEVICELIST#sizeof() + * @see GetRawInputDeviceList + */ + int GetRawInputDeviceList(RAWINPUTDEVICELIST[] pRawInputDeviceList, IntByReference puiNumDevices, int cbSize); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java index e9dd30f882..69b5223d64 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java @@ -9,11 +9,16 @@ */ package com.sun.jna.platform.win32; +import java.util.Arrays; +import java.util.List; + import com.sun.jna.WString; import com.sun.jna.platform.win32.WinDef.HINSTANCE; import com.sun.jna.platform.win32.WinDef.HMENU; import com.sun.jna.platform.win32.WinDef.HWND; import com.sun.jna.platform.win32.WinDef.LPVOID; +import com.sun.jna.platform.win32.WinUser.RAWINPUTDEVICELIST; +import com.sun.jna.ptr.IntByReference; /** @@ -48,4 +53,28 @@ public static final void destroyWindow(final HWND hWnd) { if (!User32.INSTANCE.DestroyWindow(hWnd)) throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } + + public static final List GetRawInputDeviceList() { + IntByReference puiNumDevices = new IntByReference(0); + RAWINPUTDEVICELIST placeholder = new RAWINPUTDEVICELIST(); + int cbSize = placeholder.sizeof(); + // first call is with NULL so we query the expected number of devices + int returnValue = User32.INSTANCE.GetRawInputDeviceList(null, puiNumDevices, cbSize); + if (returnValue != 0) { + throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); + } + + int deviceCount = puiNumDevices.getValue(); + RAWINPUTDEVICELIST[] records = (RAWINPUTDEVICELIST[]) placeholder.toArray(deviceCount); + returnValue = User32.INSTANCE.GetRawInputDeviceList(records, puiNumDevices, cbSize); + if (returnValue == (-1)) { + throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); + } + + if (returnValue != records.length) { + throw new IllegalStateException("Mismatched allocated (" + records.length + ") vs. received devices count (" + returnValue + ")"); + } + + return Arrays.asList(records); + } } \ No newline at end of file diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java index d096f08a07..6cd0cae90d 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java @@ -1240,6 +1240,11 @@ public void setPointer(Pointer p) { super.setPointer(p); } + + @Override + public String toString() { + return String.valueOf(getPointer()); + } } /** diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java b/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java index 7f89c3976b..83c1675f29 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java @@ -1,10 +1,10 @@ /* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU @@ -26,7 +26,7 @@ /** * Ported from WinUser.h Microsoft Windows SDK 6.0A. - * + * * @author dblock[at]dblock.org * @author Andreas "PAX" Lück, onkelpax-git[at]yahoo.de */ @@ -44,7 +44,7 @@ public HDEVNOTIFY(Pointer p) { super(p); } } - + int FLASHW_STOP = 0; int FLASHW_CAPTION = 1; int FLASHW_TRAY = 2; @@ -82,6 +82,7 @@ public class GUITHREADINFO extends Structure { public HWND hwndCaret; public RECT rcCaret; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "flags", "hwndActive", "hwndFocus", "hwndCapture", "hwndMenuOwner", @@ -101,6 +102,7 @@ public class WINDOWINFO extends Structure { public short atomWindowType; public short wCreatorVersion; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "rcWindow", "rcClient", "dwStyle", "dwExStyle", "dwWindowStatus", @@ -108,72 +110,73 @@ protected List getFieldOrder() { "wCreatorVersion" }); } } - + /** - * Contains information about the placement of a window on the screen. + * Contains information about the placement of a window on the screen. */ public class WINDOWPLACEMENT extends Structure { - /** - * The coordinates of the minimized window may be specified. - */ - public static final int WPF_SETMINPOSITION = 0x1; - - /**The restored window will be maximized, regardless of whether it was maximized before it - * was minimized. This setting is only valid the next time the window is restored. It does not - * change the default restoration behavior. - * - * This flag is only valid when the SW_SHOWMINIMIZED value is specified for the showCmd member. - */ - public static final int WPF_RESTORETOMAXIMIZED = 0x2; - - /** - * If the calling thread and the thread that owns the window are attached to different input - * queues, the system posts the request to the thread that owns the window. This prevents - * the calling thread from blocking its execution while other threads process the request. - */ - public static final int WPF_ASYNCWINDOWPLACEMENT = 0x4; - - - - /** - * The length of the structure, in bytes. - */ - public int length = size(); - /** - * The flags that control the position of the minimized window and the method by which the - * window is restored. This member can be one or more of WPF_SETMINPOSITION, - * WPF_RESTORETOMAXIMIZED, or WPF_ASYNCWINDOWPLACEMENT. - */ - public int flags; - /** - * The current show state of the window. This member can be one of SW_HIDE, SW_MAXIMIZE, - * SW_MINIMIZE, SW_RESTORE, SW_SHOW, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE, - * SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL. - * - * Note that here SW_MAXIMIZE and SW_SHOWMAXIMIZED are the same value. - */ - public int showCmd; - /** - * Virtual position of the window's upper-left corner when minimized. Usually largely negative. - * May be in workspace coordinates. - */ - public POINT ptMinPosition; - /** - * Coordinates of the window's upper-right corner when maximized. Usually small and negative. - * May be in workspace coordinates. - */ - public POINT ptMaxPosition; - /** - * The window's coordinates when the window is in the restored position. May be in workspace - * coordinates. - */ - public RECT rcNormalPosition; - - protected List getFieldOrder() { - return Arrays.asList(new String[]{"length","flags","showCmd","ptMinPosition","ptMaxPosition", - "rcNormalPosition"}); - } - } + /** + * The coordinates of the minimized window may be specified. + */ + public static final int WPF_SETMINPOSITION = 0x1; + + /**The restored window will be maximized, regardless of whether it was maximized before it + * was minimized. This setting is only valid the next time the window is restored. It does not + * change the default restoration behavior. + * + * This flag is only valid when the SW_SHOWMINIMIZED value is specified for the showCmd member. + */ + public static final int WPF_RESTORETOMAXIMIZED = 0x2; + + /** + * If the calling thread and the thread that owns the window are attached to different input + * queues, the system posts the request to the thread that owns the window. This prevents + * the calling thread from blocking its execution while other threads process the request. + */ + public static final int WPF_ASYNCWINDOWPLACEMENT = 0x4; + + + + /** + * The length of the structure, in bytes. + */ + public int length = size(); + /** + * The flags that control the position of the minimized window and the method by which the + * window is restored. This member can be one or more of WPF_SETMINPOSITION, + * WPF_RESTORETOMAXIMIZED, or WPF_ASYNCWINDOWPLACEMENT. + */ + public int flags; + /** + * The current show state of the window. This member can be one of SW_HIDE, SW_MAXIMIZE, + * SW_MINIMIZE, SW_RESTORE, SW_SHOW, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_SHOWMINNOACTIVE, + * SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL. + * + * Note that here SW_MAXIMIZE and SW_SHOWMAXIMIZED are the same value. + */ + public int showCmd; + /** + * Virtual position of the window's upper-left corner when minimized. Usually largely negative. + * May be in workspace coordinates. + */ + public POINT ptMinPosition; + /** + * Coordinates of the window's upper-right corner when maximized. Usually small and negative. + * May be in workspace coordinates. + */ + public POINT ptMaxPosition; + /** + * The window's coordinates when the window is in the restored position. May be in workspace + * coordinates. + */ + public RECT rcNormalPosition; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"length","flags","showCmd","ptMinPosition","ptMaxPosition", + "rcNormalPosition"}); + } + } /* Get/SetWindowLong properties */ int GWL_EXSTYLE = -20; @@ -183,30 +186,30 @@ protected List getFieldOrder() { int GWL_ID = -12; int GWL_USERDATA = -21; int GWL_HWNDPARENT = -8; - + int DWL_DLGPROC = Pointer.SIZE; int DWL_MSGRESULT = 0; int DWL_USER = 2*Pointer.SIZE; /* Window Styles */ - + /** The window has a thin-line border. */ - int WS_BORDER = 0x800000; - + int WS_BORDER = 0x800000; + /** The window has a title bar (includes the WS_BORDER style). */ - int WS_CAPTION = 0xc00000; - + int WS_CAPTION = 0xc00000; + /** The window is a child window. A window with this style cannot have a * menu bar. This style cannot be used with the WS_POPUP style. */ - int WS_CHILD = 0x40000000; - + int WS_CHILD = 0x40000000; + /** Same as the WS_CHILD style. */ - int WS_CHILDWINDOW = 0x40000000; - + int WS_CHILDWINDOW = 0x40000000; + /** Excludes the area occupied by child windows when drawing occurs within * the parent window. This style is used when creating the parent window. */ int WS_CLIPCHILDREN = 0x2000000; - + /** Clips child windows relative to each other; that is, when a particular * child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips * all other overlapping child windows out of the region of the child window @@ -214,16 +217,16 @@ protected List getFieldOrder() { * overlap, it is possible, when drawing within the client area of a child * window, to draw within the client area of a neighboring child window. */ int WS_CLIPSIBLINGS = 0x4000000; - + /** The window is initially disabled. A disabled window cannot receive input * from the user. To change this after a window has been created, use the * EnableWindow function. */ - int WS_DISABLED = 0x8000000; - + int WS_DISABLED = 0x8000000; + /** The window has a border of a style typically used with dialog boxes. A * window with this style cannot have a title bar. */ - int WS_DLGFRAME = 0x400000; - + int WS_DLGFRAME = 0x400000; + /** The window is the first control of a group of controls. The group * consists of this first control and all controls defined after it, up to * the next control with the WS_GROUP style. The first control in each group @@ -235,78 +238,78 @@ protected List getFieldOrder() { * change this style after a window has been created, use the SetWindowLong * function. */ - int WS_GROUP = 0x20000; - + int WS_GROUP = 0x20000; + /** The window has a horizontal scroll bar. */ - int WS_HSCROLL = 0x100000; - + int WS_HSCROLL = 0x100000; + /** The window is initially minimized. Same as the WS_MINIMIZE style. */ - int WS_ICONIC = 0x20000000; - + int WS_ICONIC = 0x20000000; + /** The window is initially maximized. */ - int WS_MAXIMIZE = 0x1000000; - + int WS_MAXIMIZE = 0x1000000; + /** The window has a maximize button. Cannot be combined with the * WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified. */ - int WS_MAXIMIZEBOX = 0x10000; - + int WS_MAXIMIZEBOX = 0x10000; + /** The window is initially minimized. Same as the WS_ICONIC style. */ - int WS_MINIMIZE = 0x20000000; - + int WS_MINIMIZE = 0x20000000; + /** The window has a minimize button. Cannot be combined with the * WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified. */ - int WS_MINIMIZEBOX = 0x20000; - + int WS_MINIMIZEBOX = 0x20000; + /** The window style overlapped. The window is an overlapped window. An * overlapped window has a title bar and a border. Same as the WS_TILED style. */ int WS_OVERLAPPED = 0x00000000; - + /** The windows is a pop-up window. This style cannot be used with the WS_CHILD style. */ - int WS_POPUP = 0x80000000; - + int WS_POPUP = 0x80000000; + /** The window has a window menu on its title bar. The WS_CAPTION style must also be specified. */ - int WS_SYSMENU = 0x80000; - + int WS_SYSMENU = 0x80000; + /** The window has a sizing border. Same as the WS_SIZEBOX style. */ - int WS_THICKFRAME = 0x40000; - + int WS_THICKFRAME = 0x40000; + /** The window is a pop-up window. The WS_CAPTION and WS_POPUPWINDOW styles * must be combined to make the window menu visible. */ - int WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU); - + int WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU); + /** The window is an overlapped window. Same as the WS_TILEDWINDOW style. */ - int WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | - WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); - + int WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | + WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); + /** The window has a sizing border. Same as the WS_THICKFRAME style. */ - int WS_SIZEBOX = 0x40000; - + int WS_SIZEBOX = 0x40000; + /** The window is a control that can receive the keyboard focus when the * user presses the TAB key. Pressing the TAB key changes the keyboard focus * to the next control with the WS_TABSTOP style. - * + * * You can turn this style on and off to change dialog box navigation. * To change this style after a window has been created, use the SetWindowLong * function. For user-created windows and modeless dialogs to work with tab * stops, alter the message loop to call the IsDialogMessage function. */ - int WS_TABSTOP = 0x10000; - + int WS_TABSTOP = 0x10000; + /** The window is an overlapped window. An overlapped window has a * title bar and a border. Same as the WS_OVERLAPPED style. */ - int WS_TILED = 0; - + int WS_TILED = 0; + /** The window is an overlapped window. Same as the WS_OVERLAPPEDWINDOW style. */ - int WS_TILEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | - WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); - + int WS_TILEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | + WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); + /** The window is initially visible. This style can be turned on and off * by using the ShowWindow or SetWindowPos function. */ - int WS_VISIBLE = 0x10000000; - + int WS_VISIBLE = 0x10000000; + /** The window has a vertical scroll bar. */ - int WS_VSCROLL = 0x200000; - + int WS_VSCROLL = 0x200000; + /* Extended Window Styles */ int WS_EX_COMPOSITED = 0x20000000; int WS_EX_LAYERED = 0x80000; @@ -315,7 +318,7 @@ protected List getFieldOrder() { /* Layered Window Attributes flags */ int LWA_COLORKEY = 1; int LWA_ALPHA = 2; - + /* Update Layered Window flags */ int ULW_COLORKEY = 1; int ULW_ALPHA = 2; @@ -329,6 +332,7 @@ public class MSG extends Structure { public int time; public POINT pt; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "hWnd", "message", "wParam", "lParam", "time", "pt" }); @@ -342,6 +346,7 @@ public class FLASHWINFO extends Structure { public int uCount; public int dwTimeout; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "hWnd", "dwFlags", "uCount", "dwTimeout" }); @@ -369,6 +374,7 @@ public SIZE(int w, int h) { this.cy = h; } + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "cx", "cy" }); } @@ -385,6 +391,7 @@ public class BLENDFUNCTION extends Structure { public byte SourceConstantAlpha; public byte AlphaFormat; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "BlendOp", "BlendFlags", "SourceConstantAlpha", "AlphaFormat" }); @@ -490,30 +497,30 @@ public interface HOOKPROC extends StdCallCallback { } int WM_DESTROY = 0x0002; public static final int WM_DEVICECHANGE = 0x0219; - - /** - * Sent to a window to retrieve a handle to the large or small icon - * associated with a window. The system displays the large icon in the - * ALT+TAB dialog, and the small icon in the window caption. - */ - int WM_GETICON = 0x007F; - - /** - * Retrieve the large icon for the window. - */ - int ICON_BIG = 1; - - /** - * Retrieve the small icon for the window. - */ - int ICON_SMALL = 0; - - /** - * Retrieves the small icon provided by the application. If the application - * does not provide one, the system uses the system-generated icon for that - * window. - */ - int ICON_SMALL2 = 2; + + /** + * Sent to a window to retrieve a handle to the large or small icon + * associated with a window. The system displays the large icon in the + * ALT+TAB dialog, and the small icon in the window caption. + */ + int WM_GETICON = 0x007F; + + /** + * Retrieve the large icon for the window. + */ + int ICON_BIG = 1; + + /** + * Retrieve the small icon for the window. + */ + int ICON_SMALL = 0; + + /** + * Retrieves the small icon provided by the application. If the application + * does not provide one, the system uses the system-generated icon for that + * window. + */ + int ICON_SMALL2 = 2; public class KBDLLHOOKSTRUCT extends Structure { public int vkCode; @@ -522,6 +529,7 @@ public class KBDLLHOOKSTRUCT extends Structure { public int time; public ULONG_PTR dwExtraInfo; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "vkCode", "scanCode", "flags", "time", "dwExtraInfo" }); @@ -660,7 +668,7 @@ protected List getFieldOrder() { /** * The retrieved handle identifies the window of the same type that is * highest in the Z order. - * + * * If the specified window is a topmost window, the handle identifies a * topmost window. If the specified window is a top-level window, the handle * identifies a top-level window. If the specified window is a child window, @@ -671,7 +679,7 @@ protected List getFieldOrder() { /** * The retrieved handle identifies the window of the same type that is * lowest in the Z order. - * + * * If the specified window is a topmost window, the handle identifies a * topmost window. If the specified window is a top-level window, the handle * identifies a top-level window. If the specified window is a child window, @@ -682,7 +690,7 @@ protected List getFieldOrder() { /** * The retrieved handle identifies the window below the specified window in * the Z order. - * + * * If the specified window is a topmost window, the handle identifies a * topmost window. If the specified window is a top-level window, the handle * identifies a top-level window. If the specified window is a child window, @@ -693,7 +701,7 @@ protected List getFieldOrder() { /** * The retrieved handle identifies the window above the specified window in * the Z order. - * + * * If the specified window is a topmost window, the handle identifies a * topmost window. If the specified window is a top-level window, the handle * identifies a top-level window. If the specified window is a child window, @@ -766,6 +774,7 @@ public HARDWAREINPUT(Pointer memory) { public WinDef.WORD wParamL; public WinDef.WORD wParamH; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "uMsg", "wParamL", "wParamH" }); } @@ -802,6 +811,7 @@ public INPUT(Pointer memory) { public WinDef.DWORD type; public INPUT_UNION input = new INPUT_UNION(); + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "type", "input" }); } @@ -900,6 +910,7 @@ public KEYBDINPUT(Pointer memory) { */ public BaseTSD.ULONG_PTR dwExtraInfo; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "wVk", "wScan", "dwFlags", "time", "dwExtraInfo" }); @@ -936,6 +947,7 @@ public MOUSEINPUT(Pointer memory) { public WinDef.DWORD time; public BaseTSD.ULONG_PTR dwExtraInfo; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "dx", "dy", "mouseData", "dwFlags", "time", "dwExtraInfo" }); @@ -951,15 +963,16 @@ public static class LASTINPUTINFO extends Structure { // Tick count of when the last input event was received. public int dwTime; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "dwTime" }); } } - + /** * Contains window class information. It is used with the RegisterClassEx * and GetClassInfoEx functions. - * + * * The WNDCLASSEX structure is similar to the WNDCLASS structure. There are * two differences. WNDCLASSEX includes the cbSize member, which specifies * the size of the structure, and the hIconSm member, which contains a @@ -982,7 +995,7 @@ public WNDCLASSEX() { /** * Instantiates a new wndclassex. - * + * * @param memory * the memory */ @@ -1027,6 +1040,7 @@ public WNDCLASSEX(Pointer memory) { /** The h icon sm. */ public HICON hIconSm; + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "style", "lpfnWndProc", "cbClsExtra", "cbWndExtra", "hInstance", @@ -1038,7 +1052,7 @@ protected List getFieldOrder() { /** * An application-defined function that processes messages sent to a window. * The WNDPROC type defines a pointer to this callback function. - * + * * WindowProc is a placeholder for the application-defined function name. */ public interface WindowProc extends Callback { @@ -1046,37 +1060,37 @@ public interface WindowProc extends Callback { /** * @param hwnd * [in] Type: HWND - * + * * A handle to the window. - * + * * @param uMsg * [in] Type: UINT - * + * * The message. - * + * * For lists of the system-provided messages, see * System-Defined Messages. - * + * * @param wParam * [in] Type: WPARAM - * + * * Additional message information. The contents of this * parameter depend on the value of the uMsg parameter. - * + * * @param lParam * [in] Type: LPARAM - * + * * Additional message information. The contents of this * parameter depend on the value of the uMsg parameter. - * + * * @return the lresult */ LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam); - } + } - /** - * Each physical display is represented by a monitor handle of type HMONITOR. A valid HMONITOR - * is guaranteed to be non-NULL. A physical display has the same HMONITOR as long as it is part + /** + * Each physical display is represented by a monitor handle of type HMONITOR. A valid HMONITOR + * is guaranteed to be non-NULL. A physical display has the same HMONITOR as long as it is part * of the desktop. */ public class HMONITOR extends HANDLE { @@ -1084,7 +1098,7 @@ public class HMONITOR extends HANDLE { /** * Instantiates a new HMONITOR. */ - public HMONITOR() + public HMONITOR() { } @@ -1092,7 +1106,7 @@ public HMONITOR() * Instantiates a new HMONITOR. * @param p the pointer */ - public HMONITOR(Pointer p) + public HMONITOR(Pointer p) { super(p); } @@ -1126,9 +1140,9 @@ public HMONITOR(Pointer p) /** * The MONITORINFO structure contains information about a display monitor.
- * The {@link User32#GetMonitorInfo} function stores + * The {@link User32#GetMonitorInfo} function stores * information into a MONITORINFO structure

- * The MONITORINFO structure is a subset of the MONITORINFOEX structure. + * The MONITORINFO structure is a subset of the MONITORINFOEX structure. */ public class MONITORINFO extends Structure { @@ -1138,18 +1152,18 @@ public class MONITORINFO extends Structure public int cbSize = size(); /** - * Specifies the display monitor rectangle, expressed in virtual-screen coordinates. - * Note that if the monitor is not the primary display monitor, some of the + * Specifies the display monitor rectangle, expressed in virtual-screen coordinates. + * Note that if the monitor is not the primary display monitor, some of the * rectangle's coordinates may be negative values. */ public RECT rcMonitor; /** - * Specifies the work area rectangle of the display monitor that can be used by - * applications, expressed in virtual-screen coordinates. Windows uses this rectangle - * to maximize an application on the monitor. The rest of the area in rcMonitor - * contains system windows such as the task bar and side bars. Note that if the - * monitor is not the primary display monitor, some of the rectangle's coordinates + * Specifies the work area rectangle of the display monitor that can be used by + * applications, expressed in virtual-screen coordinates. Windows uses this rectangle + * to maximize an application on the monitor. The rest of the area in rcMonitor + * contains system windows such as the task bar and side bars. Note that if the + * monitor is not the primary display monitor, some of the rectangle's coordinates * may be negative values. */ public RECT rcWork; @@ -1169,10 +1183,10 @@ protected List getFieldOrder() /** * The MONITORINFOEX structure contains information about a display monitor.
- * The {@link User32#GetMonitorInfo} function stores + * The {@link User32#GetMonitorInfo} function stores * information into a MONITORINFOEX structure

- * The MONITORINFOEX structure is a superset of the MONITORINFO structure. - * The MONITORINFOEX structure adds a string member to contain a name for the display monitor. + * The MONITORINFOEX structure is a superset of the MONITORINFO structure. + * The MONITORINFOEX structure adds a string member to contain a name for the display monitor. */ public class MONITORINFOEX extends Structure { @@ -1182,18 +1196,18 @@ public class MONITORINFOEX extends Structure public int cbSize; /** - * Specifies the display monitor rectangle, expressed in virtual-screen coordinates. - * Note that if the monitor is not the primary display monitor, some of the + * Specifies the display monitor rectangle, expressed in virtual-screen coordinates. + * Note that if the monitor is not the primary display monitor, some of the * rectangle's coordinates may be negative values. */ public RECT rcMonitor; /** - * Specifies the work area rectangle of the display monitor that can be used by - * applications, expressed in virtual-screen coordinates. Windows uses this rectangle - * to maximize an application on the monitor. The rest of the area in rcMonitor - * contains system windows such as the task bar and side bars. Note that if the - * monitor is not the primary display monitor, some of the rectangle's coordinates + * Specifies the work area rectangle of the display monitor that can be used by + * applications, expressed in virtual-screen coordinates. Windows uses this rectangle + * to maximize an application on the monitor. The rest of the area in rcMonitor + * contains system windows such as the task bar and side bars. Note that if the + * monitor is not the primary display monitor, some of the rectangle's coordinates * may be negative values. */ public RECT rcWork; @@ -1205,8 +1219,8 @@ public class MONITORINFOEX extends Structure public int dwFlags; /** - * A string that specifies the device name of the monitor being used. Most - * applications have no use for a display monitor name, and so can save some bytes + * A string that specifies the device name of the monitor being used. Most + * applications have no use for a display monitor name, and so can save some bytes * by using a MONITORINFO structure. */ public char[] szDevice; @@ -1227,36 +1241,36 @@ protected List getFieldOrder() /** * An application-defined callback function that is called by the {@link User32#EnumDisplayMonitors} function. *

- * You can use the EnumDisplayMonitors function to enumerate the set of display monitors that intersect - * the visible region of a specified device context and, optionally, a clipping rectangle. To do this, + * You can use the EnumDisplayMonitors function to enumerate the set of display monitors that intersect + * the visible region of a specified device context and, optionally, a clipping rectangle. To do this, * set the hdc parameter to a non-NULL value, and set the lprcClip parameter as needed. *

- * You can also use the EnumDisplayMonitors function to enumerate one or more of the display monitors on - * the desktop, without supplying a device context. To do this, set the hdc parameter of + * You can also use the EnumDisplayMonitors function to enumerate one or more of the display monitors on + * the desktop, without supplying a device context. To do this, set the hdc parameter of * EnumDisplayMonitors to NULL and set the lprcClip parameter as needed. *

- * In all cases, EnumDisplayMonitors calls a specified MonitorEnumProc function once for each display - * monitor in the calculated enumeration set. The MonitorEnumProc function always receives a handle to - * the display monitor. If the hdc parameter of EnumDisplayMonitors is non-NULL, the MonitorEnumProc - * function also receives a handle to a device context whose color format is appropriate for the - * display monitor. You can then paint into the device context in a manner that is optimal for the + * In all cases, EnumDisplayMonitors calls a specified MonitorEnumProc function once for each display + * monitor in the calculated enumeration set. The MonitorEnumProc function always receives a handle to + * the display monitor. If the hdc parameter of EnumDisplayMonitors is non-NULL, the MonitorEnumProc + * function also receives a handle to a device context whose color format is appropriate for the + * display monitor. You can then paint into the device context in a manner that is optimal for the * display monitor. */ public interface MONITORENUMPROC extends Callback { /** * @param hMonitor A handle to the display monitor. This value will always be non-NULL. - * @param hdcMonitor A handle to a device context. The device context has color attributes that are - * appropriate for the display monitor identified by hMonitor. The clipping area of the device - * context is set to the intersection of the visible region of the device context identified - * by the hdc parameter of EnumDisplayMonitors, the rectangle pointed to by the lprcClip + * @param hdcMonitor A handle to a device context. The device context has color attributes that are + * appropriate for the display monitor identified by hMonitor. The clipping area of the device + * context is set to the intersection of the visible region of the device context identified + * by the hdc parameter of EnumDisplayMonitors, the rectangle pointed to by the lprcClip * parameter of EnumDisplayMonitors, and the display monitor rectangle. - * @param lprcMonitor A pointer to a RECT structure. If hdcMonitor is non-NULL, this rectangle is the - * intersection of the clipping area of the device context identified by hdcMonitor and the + * @param lprcMonitor A pointer to a RECT structure. If hdcMonitor is non-NULL, this rectangle is the + * intersection of the clipping area of the device context identified by hdcMonitor and the * display monitor rectangle. The rectangle coordinates are device-context coordinates. - * If hdcMonitor is NULL, this rectangle is the display monitor rectangle. The rectangle + * If hdcMonitor is NULL, this rectangle is the display monitor rectangle. The rectangle * coordinates are virtual-screen coordinates. - * @param dwData Application-defined data that EnumDisplayMonitors passes directly to the enumeration + * @param dwData Application-defined data that EnumDisplayMonitors passes directly to the enumeration * function. * @return To continue the enumeration, return TRUE. To stop the enumeration, return FALSE. */ @@ -1264,240 +1278,281 @@ public interface MONITORENUMPROC extends Callback } /* Extendend Exit Windows flags */ - + /** Beginning with Windows 8: You can prepare the system for a faster startup by * combining the EWX_HYBRID_SHUTDOWN flag with the EWX_SHUTDOWN flag. */ int EWX_HYBRID_SHUTDOWN = 0x00400000; - + /** Shuts down all processes running in the logon session of the process that called the ExitWindowsEx function. * Then it logs the user off. This flag can be used only by processes running in an interactive user's logon session. */ int EWX_LOGOFF = 0; - + /** Shuts down the system and turns off the power. The system must support the power-off feature. The calling * process must have the SE_SHUTDOWN_NAME privilege. For more information, see {@link com.sun.jna.platform.win32.User32#ExitWindowsEx}. */ int EWX_POWEROFF = 0x00000008; - + /** Shuts down the system and then restarts the system. The calling process must have the SE_SHUTDOWN_NAME * privilege. For more information, see {@link com.sun.jna.platform.win32.User32#ExitWindowsEx}. */ - int EWX_REBOOT = 0x00000002; + int EWX_REBOOT = 0x00000002; /** Shuts down the system and then restarts it, as well as any applications that have been registered for * restart using the RegisterApplicationRestart function. These application receive the WM_QUERYENDSESSION * message with lParam set to the ENDSESSION_CLOSEAPP value. For more information, see Guidelines for Applications. */ - int EWX_RESTARTAPPS = 0x00000040; + int EWX_RESTARTAPPS = 0x00000040; /** Shuts down the system to a point at which it is safe to turn off the power. All file buffers * have been flushed to disk, and all running processes have stopped. The calling process must have * the SE_SHUTDOWN_NAME privilege. For more information, see {@link com.sun.jna.platform.win32.User32#ExitWindowsEx}. Specifying * this flag will not turn off the power even if the system supports the power-off feature. You must * specify EWX_POWEROFF to do this. - * + * * Windows XP with SP1: If the system supports the power-off feature, specifying this flag turns off the power. */ - int EWX_SHUTDOWN = 0x00000001; - + int EWX_SHUTDOWN = 0x00000001; + /** This flag has no effect if terminal services is enabled. Otherwise, the system does not send the * WM_QUERYENDSESSION message. This can cause applications to lose data. Therefore, you should only * use this flag in an emergency. */ int EWX_FORCE = 0x00000004; - + /** Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION * message within the timeout interval. For more information, see {@link com.sun.jna.platform.win32.User32#ExitWindowsEx}. */ int EWX_FORCEIFHUNG = 0x00000010; - + /* GetClassLong properties */ - /** - * Retrieves an ATOM value that uniquely identifies the window class. This - * is the same atom that the RegisterClassEx function returns. - */ - int GCW_ATOM = -32; - - /** - * Retrieves the size, in bytes, of the extra memory associated with the - * class. - */ - int GCL_CBCLSEXTRA = -20; - - /** - * Retrieves the size, in bytes, of the extra window memory associated with - * each window in the class. For information on how to access this memory, - * see GetWindowLongPtr. - */ - int GCL_CBWNDEXTRA = -18; - - /** - * Retrieves a handle to the background brush associated with the class. - */ - int GCLP_HBRBACKGROUND = -10; - - /** - * Retrieves a handle to the cursor associated with the class. - */ - int GCLP_HCURSOR = -12; - - /** - * Retrieves a handle to the icon associated with the class. - */ - int GCLP_HICON = -14; - - /** - * Retrieves a handle to the small icon associated with the class. - */ - int GCLP_HICONSM = -34; - - /** - * Retrieves a handle to the module that registered the class. - */ - int GCLP_HMODULE = -16; - - /** - * Retrieves the pointer to the menu name string. The string identifies the - * menu resource associated with the class. - */ - int GCLP_MENUNAME = -8; - - /** - * Retrieves the window-class style bits. - */ - int GCL_STYLE = -26; - - /** - * Retrieves the address of the window procedure, or a handle representing - * the address of the window procedure. You must use the CallWindowProc - * function to call the window procedure. - */ - int GCLP_WNDPROC = -24; - - /* SendMessageTimeout properties */ - /** - * The function returns without waiting for the time-out period to elapse if - * the receiving thread appears to not respond or "hangs." - */ - int SMTO_ABORTIFHUNG = 0x0002; - - /** - * Prevents the calling thread from processing any other requests until the - * function returns. - */ - int SMTO_BLOCK = 0x0001; - - /** - * The calling thread is not prevented from processing other requests while - * waiting for the function to return. - */ - int SMTO_NORMAL = 0x0000; - - /** - * The function does not enforce the time-out period as long as the - * receiving thread is processing messages. - */ - int SMTO_NOTIMEOUTIFNOTHUNG = 0x0008; - - /** - * The function should return 0 if the receiving window is destroyed or its - * owning thread dies while the message is being processed. - */ - int SMTO_ERRORONEXIT=0x0020; - - /* GetIconInfo properties */ - - /** - * Standard arrow and small hourglass cursor. - */ - int IDC_APPSTARTING = 32650; - - /** - * Standard arrow cursor. - */ - int IDC_ARROW = 32512; - - /** - * Crosshair cursor. - */ - int IDC_CROSS = 32515; - - /** - * Hand cursor. - */ - int IDC_HAND = 32649; - - /** - * Arrow and question mark cursor. - */ - int IDC_HELP = 32651; - - /** - * I-beam cursor. - */ - int IDC_IBEAM = 32513; - - /** - * Slashed circle cursor. - */ - int IDC_NO = 32648; - - /** - * Four-pointed arrow cursor pointing north, south, east, and west. - */ - int IDC_SIZEALL = 32646; - - /** - * Double-pointed arrow cursor pointing northeast and southwest. - */ - int IDC_SIZENESW = 32643; - - /** - * Double-pointed arrow cursor pointing north and south. - */ - int IDC_SIZENS = 32645; - - /** - * Double-pointed arrow cursor pointing northwest and southeast. - */ - int IDC_SIZENWSE = 32642; - - /** - * Double-pointed arrow cursor pointing west and east. - */ - int IDC_SIZEWE = 32644; - - /** - * Vertical arrow cursor. - */ - int IDC_UPARROW = 32516; - - /** - * Hourglass cursor. - */ - int IDC_WAIT = 32514; - - /** - * Application icon. - */ - int IDI_APPLICATION = 32512; - - /** - * Asterisk icon. - */ - int IDI_ASTERISK = 32516; - - /** - * Exclamation point icon. - */ - int IDI_EXCLAMATION = 32515; - - /** - * Stop sign icon. - */ - int IDI_HAND = 32513; - - /** - * Question-mark icon. - */ - int IDI_QUESTION = 32514; - - /** - * Application icon. Windows 2000: Windows logo icon. - */ - int IDI_WINLOGO = 32517; + /** + * Retrieves an ATOM value that uniquely identifies the window class. This + * is the same atom that the RegisterClassEx function returns. + */ + int GCW_ATOM = -32; + + /** + * Retrieves the size, in bytes, of the extra memory associated with the + * class. + */ + int GCL_CBCLSEXTRA = -20; + + /** + * Retrieves the size, in bytes, of the extra window memory associated with + * each window in the class. For information on how to access this memory, + * see GetWindowLongPtr. + */ + int GCL_CBWNDEXTRA = -18; + + /** + * Retrieves a handle to the background brush associated with the class. + */ + int GCLP_HBRBACKGROUND = -10; + + /** + * Retrieves a handle to the cursor associated with the class. + */ + int GCLP_HCURSOR = -12; + + /** + * Retrieves a handle to the icon associated with the class. + */ + int GCLP_HICON = -14; + + /** + * Retrieves a handle to the small icon associated with the class. + */ + int GCLP_HICONSM = -34; + + /** + * Retrieves a handle to the module that registered the class. + */ + int GCLP_HMODULE = -16; + + /** + * Retrieves the pointer to the menu name string. The string identifies the + * menu resource associated with the class. + */ + int GCLP_MENUNAME = -8; + + /** + * Retrieves the window-class style bits. + */ + int GCL_STYLE = -26; + + /** + * Retrieves the address of the window procedure, or a handle representing + * the address of the window procedure. You must use the CallWindowProc + * function to call the window procedure. + */ + int GCLP_WNDPROC = -24; + + /* SendMessageTimeout properties */ + /** + * The function returns without waiting for the time-out period to elapse if + * the receiving thread appears to not respond or "hangs." + */ + int SMTO_ABORTIFHUNG = 0x0002; + + /** + * Prevents the calling thread from processing any other requests until the + * function returns. + */ + int SMTO_BLOCK = 0x0001; + + /** + * The calling thread is not prevented from processing other requests while + * waiting for the function to return. + */ + int SMTO_NORMAL = 0x0000; + + /** + * The function does not enforce the time-out period as long as the + * receiving thread is processing messages. + */ + int SMTO_NOTIMEOUTIFNOTHUNG = 0x0008; + + /** + * The function should return 0 if the receiving window is destroyed or its + * owning thread dies while the message is being processed. + */ + int SMTO_ERRORONEXIT=0x0020; + + /* GetIconInfo properties */ + + /** + * Standard arrow and small hourglass cursor. + */ + int IDC_APPSTARTING = 32650; + + /** + * Standard arrow cursor. + */ + int IDC_ARROW = 32512; + + /** + * Crosshair cursor. + */ + int IDC_CROSS = 32515; + + /** + * Hand cursor. + */ + int IDC_HAND = 32649; + + /** + * Arrow and question mark cursor. + */ + int IDC_HELP = 32651; + + /** + * I-beam cursor. + */ + int IDC_IBEAM = 32513; + + /** + * Slashed circle cursor. + */ + int IDC_NO = 32648; + + /** + * Four-pointed arrow cursor pointing north, south, east, and west. + */ + int IDC_SIZEALL = 32646; + + /** + * Double-pointed arrow cursor pointing northeast and southwest. + */ + int IDC_SIZENESW = 32643; + + /** + * Double-pointed arrow cursor pointing north and south. + */ + int IDC_SIZENS = 32645; + + /** + * Double-pointed arrow cursor pointing northwest and southeast. + */ + int IDC_SIZENWSE = 32642; + + /** + * Double-pointed arrow cursor pointing west and east. + */ + int IDC_SIZEWE = 32644; + + /** + * Vertical arrow cursor. + */ + int IDC_UPARROW = 32516; + + /** + * Hourglass cursor. + */ + int IDC_WAIT = 32514; + + /** + * Application icon. + */ + int IDI_APPLICATION = 32512; + + /** + * Asterisk icon. + */ + int IDI_ASTERISK = 32516; + + /** + * Exclamation point icon. + */ + int IDI_EXCLAMATION = 32515; + + /** + * Stop sign icon. + */ + int IDI_HAND = 32513; + + /** + * Question-mark icon. + */ + int IDI_QUESTION = 32514; + + /** + * Application icon. Windows 2000: Windows logo icon. + */ + int IDI_WINLOGO = 32517; + + /* Types of devices in RAWINPUTDEVICELIST */ + /** The device is a mouse. */ + int RIM_TYPEMOUSE = 0; + + /** The device is a keyboard. */ + int RIM_TYPEKEYBOARD = 1; + + /** The device is an HID that is not a keyboard and not a mouse. **/ + int RIM_TYPEHID = 2; + + /** + * Contains information about a raw input device. + * @see + */ + public class RAWINPUTDEVICELIST extends Structure { + public HANDLE hDevice; + public int dwType; + + public RAWINPUTDEVICELIST() { + super(); + } + + public RAWINPUTDEVICELIST(Pointer p) { + super(p); + } + + public int sizeof() { + return calculateSize(false); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList("hDevice", "dwType"); + } + + @Override + public String toString() { + return "hDevice=" + hDevice + ", dwType=" + dwType; + } + } } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/User32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/User32UtilTest.java index 3a803bd7b0..7f5cfcbd21 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/User32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/User32UtilTest.java @@ -9,10 +9,13 @@ */ package com.sun.jna.platform.win32; -import junit.framework.TestCase; +import java.util.Collection; import com.sun.jna.Pointer; import com.sun.jna.platform.win32.WinDef.HWND; +import com.sun.jna.platform.win32.WinUser.RAWINPUTDEVICELIST; + +import junit.framework.TestCase; /** * @author markus[at]headcrashing[dot]eu @@ -48,4 +51,18 @@ public final void testCreateWindowEx() { public final void testDestroyWindow() { User32Util.destroyWindow(User32Util.createWindow("Message", null, 0, 0, 0, 0, 0, null, null, null, null)); } + + public final void testGetRawInputDeviceList() { + Collection deviceList = User32Util.GetRawInputDeviceList(); + /* + * NOTE: we do do not check that deviceList.size() > 0 since theoretically + * we could run on a host that has no input devices (keyboard, mouse, etc...). + * We just want to make sure that the call succeeds + */ + assertNotNull("No device list", deviceList); + +// for (RAWINPUTDEVICELIST device : deviceList) { +// System.out.append('\t').append("Found device of type: ").println(device.dwType); +// } + } }