diff --git a/CHANGES.md b/CHANGES.md index 3fef7e1a1f..43540fdb2b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Features * [#333](https://github.com/twall/jna/pull/333): Added `CoTaskMemAlloc`, `CoTaskMemRealloc` and `CoTaskMemFree` to `com.sun.jna.platform.win32.Ole32` - [@msteiger](https://github.com/msteiger). * [#334](https://github.com/twall/jna/pull/334): Added `com.sun.jna.platform.win32.Shell32.SHGetKnownFolderPath` and `KnownFolders` GUID constants - [@msteiger](https://github.com/msteiger). * [#338](https://github.com/twall/jna/pull/338): Added `com.sun.jna.platform.mac.XAttr` and `com.sun.jna.platform.mac.XAttrUtil` JNA wrapper for `` for Mac OS X - [@rednoah](https://github.com/rednoah) +* [#339](https://github.com/twall/jna/pull/339): Added `GetWindowPlacement`, `SetWindowPlacement`, `AdjustWindowRect`(Ex), `ExitWindowsEx`, and `LockWorkstation` to `com.sun.jna.platform.win32.User32` - [@Timeroot](https://github.com/Timeroot) Bug Fixes --------- diff --git a/contrib/platform/.classpath b/contrib/platform/.classpath index a7a6de01e9..91a28a2ee6 100644 --- a/contrib/platform/.classpath +++ b/contrib/platform/.classpath @@ -5,6 +5,6 @@ - + diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java b/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java index 462e0c4cca..5d0d31fc5c 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java @@ -48,10 +48,10 @@ public interface Dxva2 extends StdCallLibrary, PhysicalMonitorEnumerationAPI, Hi put(Library.OPTION_TYPE_MAPPER, new DefaultTypeMapper() { { - addTypeConverter(MC_POSITION_TYPE.class, new EnumConverter<>(MC_POSITION_TYPE.class)); - addTypeConverter(MC_SIZE_TYPE.class, new EnumConverter<>(MC_SIZE_TYPE.class)); - addTypeConverter(MC_GAIN_TYPE.class, new EnumConverter<>(MC_GAIN_TYPE.class)); - addTypeConverter(MC_DRIVE_TYPE.class, new EnumConverter<>(MC_DRIVE_TYPE.class)); + addTypeConverter(MC_POSITION_TYPE.class, new EnumConverter(MC_POSITION_TYPE.class)); + addTypeConverter(MC_SIZE_TYPE.class, new EnumConverter(MC_SIZE_TYPE.class)); + addTypeConverter(MC_GAIN_TYPE.class, new EnumConverter(MC_GAIN_TYPE.class)); + addTypeConverter(MC_DRIVE_TYPE.class, new EnumConverter(MC_DRIVE_TYPE.class)); } }); } 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 4c3ce26af9..9b25ea27e6 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/User32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/User32.java @@ -40,16 +40,13 @@ public interface User32 extends StdCallLibrary, WinUser, WinNT { * Handle for message-only window. */ public static final HWND HWND_MESSAGE = new HWND(Pointer.createConstant(-3)); - + /** The cs globalclass. */ int CS_GLOBALCLASS = 0x4000; /** The ws ex topmost. */ int WS_EX_TOPMOST = 0x00000008; - - /** The ws overlapped. */ - int WS_OVERLAPPED = 0x00000000; - + /** The hRecipient parameter is a window handle. */ int DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000; @@ -1689,7 +1686,8 @@ HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient, boolean UnregisterDeviceNotification(HDEVNOTIFY Handle); /** - * Defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages. + * Defines a new window message that is guaranteed to be unique throughout the system. + * The message value can be used when sending or posting messages. * * @param string * The message to be registered. @@ -1778,6 +1776,7 @@ HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient, * region of a device context. EnumDisplayMonitors calls an application-defined MonitorEnumProc callback * function once for each monitor that is enumerated. Note that GetSystemMetrics (SM_CMONITORS) counts * only the display monitors. + * * @param hdc A handle to a display device context that defines the visible region of interest. If this * parameter is NULL, the hdcMonitor parameter passed to the callback function will be NULL, and * the visible region of interest is the virtual screen that encompasses all the displays on the @@ -1793,4 +1792,162 @@ HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient, * is zero. */ BOOL EnumDisplayMonitors(HDC hdc, RECT lprcClip, MONITORENUMPROC lpfnEnum, LPARAM dwData); + + /** + * Retrieves the show state and the restored, minimized, and maximized + * positions of the specified window. + * + * @param hwnd A handle to the window. + * @param dest A pointer to the WINDOWPLACEMENT structure that receives the + * show state and position information. + * @return The number of characters copied to the specified buffer indicates + * success. Zero indicates failure. To get extended error + * information, call GetLastError. + */ + BOOL GetWindowPlacement(HWND hwnd, WINDOWPLACEMENT lpwndpl); + + /** + * Sets the show state and the restored, minimized, and maximized positions + * of the specified window. + * + * @param hwnd A handle to the window. + * @param dest A pointer to a WINDOWPLACEMENT structure that specifies the + * new show state and window positions. + * @return The number of characters copied to the specified buffer indicates + * success. Zero indicates failure. To get extended error + * information, call GetLastError. + */ + BOOL SetWindowPlacement(HWND hwnd, WINDOWPLACEMENT lpwndpl); + + /** + * Calculates the required size of the window rectangle, based on the desired + * client-rectangle size. The window rectangle can then be passed to the CreateWindow + * function to create a window whose client area is the desired size. + * + * To specify an extended window style, use the AdjustWindowRectEx function. + * + * A client rectangle is the smallest rectangle that completely encloses a + * client area. A window rectangle is the smallest rectangle that completely + * encloses the window, which includes the client area and the nonclient area. + * + * The AdjustWindowRect function does not add extra space when a menu bar wraps + * to two or more rows. + * + * The AdjustWindowRect function does not take the WS_VSCROLL or WS_HSCROLL + * styles into account. To account for the scroll bars, call the GetSystemMetrics + * function with SM_CXVSCROLL or SM_CYHSCROLL. + * + * @param lpRect A pointer to a RECT structure that contains the coordinates + * of the top-left and bottom-right corners of the desired client area. + * When the function returns, the structure contains the coordinates + * of the top-left and bottom-right corners of the window to accommodate + * the desired client area. + * @param dwStyle The window style of the window whose required size is to be + * calculated. Note that you cannot specify the WS_OVERLAPPED style. + * @param bMenu Indicates whether the window has a menu. + * @return The number of characters copied to the specified buffer indicates + * success. Zero indicates failure. To get extended error + * information, call GetLastError. + */ + BOOL AdjustWindowRect(RECT lpRect, DWORD dwStyle, BOOL bMenu); + + /** + * Calculates the required size of the window rectangle, based on the desired + * client-rectangle size. The window rectangle can then be passed to the CreateWindowEx + * function to create a window whose client area is the desired size. + * + * A client rectangle is the smallest rectangle that completely encloses a + * client area. A window rectangle is the smallest rectangle that completely + * encloses the window, which includes the client area and the nonclient area. + * + * The AdjustWindowRectEx function does not add extra space when a menu bar wraps + * to two or more rows. + * + * The AdjustWindowRectEx function does not take the WS_VSCROLL or WS_HSCROLL + * styles into account. To account for the scroll bars, call the GetSystemMetrics + * function with SM_CXVSCROLL or SM_CYHSCROLL. + * + * @param lpRect A pointer to a RECT structure that contains the coordinates + * of the top-left and bottom-right corners of the desired client area. + * When the function returns, the structure contains the coordinates + * of the top-left and bottom-right corners of the window to accommodate + * the desired client area. + * @param dwStyle The window style of the window whose required size is to be + * calculated. Note that you cannot specify the WS_OVERLAPPED style. + * @param bMenu Indicates whether the window has a menu. + * @param dwExStyle The extended window style of the window whose required size + * is to be calculated. + * @return The number of characters copied to the specified buffer indicates + * success. Zero indicates failure. To get extended error + * information, call GetLastError. + */ + BOOL AdjustWindowRectEx(RECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle); + + /** + * Logs off the interactive user, shuts down the system, or shuts down and restarts + * the system. It sends the WM_QUERYENDSESSION message to all applications to + * determine if they can be terminated. + * + * When this function is called, the caller must specify whether or not applications + * with unsaved changes should be forcibly closed. If the caller chooses not to force + * these applications to close and an application with unsaved changes is running on + * the console session, the shutdown will remain in progress until the user logged + * into the console session aborts the shutdown, saves changes, closes the application, + * or forces the application to close. During this period, the shutdown may not be + * aborted except by the console user, and another shutdown may not be initiated. + * + * Calling this function with the value of the uFlags parameter set to EWX_FORCE avoids + * this situation. Remember that doing this may result in loss of data. + * + * To set a shutdown priority for an application relative to other applications in the + * system, use the SetProcessShutdownParameters function. + * + * During a shutdown or log-off operation, running applications are allowed a specific + * amount of time to respond to the shutdown request. If this time expires before all + * applications have stopped, the system displays a user interface that allows the user + * to forcibly shut down the system or to cancel the shutdown request. If the EWX_FORCE + * value is specified, the system forces running applications to stop when the time expires. + * + * If the EWX_FORCEIFHUNG value is specified, the system forces hung applications to close + * and does not display the dialog box. + * + * Console processes receive a separate notification message, CTRL_SHUTDOWN_EVENT or + * CTRL_LOGOFF_EVENT, as the situation warrants. A console process routes these messages + * to its HandlerRoutine function. ExitWindowsEx sends these notification messages + * asynchronously; thus, an application cannot assume that the console notification messages + * have been handled when a call to ExitWindowsEx returns. + * + * To shut down or restart the system, the calling process must use the {@link com.sun.jna.platform.Advapi32.AdjustTokenPrivileges} + * function to enable the SE_SHUTDOWN_NAME privilege. For more information, see Running with Special Privileges. + * + * @param uFlags The shutdown type. This parameter must include one of EWX_HYBRID_SHUTDOWN, + * EWX_LOGOFF, EWX_POWEROFF, EWX_REBOOT, EWX_RESTARTAPPS, or EWX_SHUTDOWN. This + * parameter can optionally include one of EWX_FORCE or EWX_FORCEIFHUNG. + * @param dReason The reason for initiating the shutdown. This parameter must be one + * of the system shutdown reason codes. If this parameter is zero, the + * SHTDN_REASON_FLAG_PLANNED reason code will not be set and therefore the + * default action is an undefined shutdown that is logged as "No title for + * this reason could be found". By default, it is also an unplanned shutdown. + * Depending on how the system is configured, an unplanned shutdown triggers + * the creation of a file that contains the system state information, which + * can delay shutdown. Therefore, do not use zero for this parameter. + * @return If the function succeeds, the return value is nonzero. Because the function + * executes asynchronously, a nonzero return value indicates that the shutdown has been + * initiated. It does not indicate whether the shutdown will succeed. It is possible + * that the system, the user, or another application will abort the shutdown. If the + * function fails, the return value is zero. To get extended error information, call GetLastError. + */ + BOOL ExitWindowsEx(UINT uFlags, DWORD dReason); + + /** + * Locks the workstation's display. Locking a workstation protects it from unauthorized use. The + * LockWorkStation function is callable only by processes running on the interactive desktop. + * In addition, the user must be logged on, and the workstation cannot already be locked. + * + * @return If the function succeeds, the return value is nonzero. Because the function executes + * asynchronously, a nonzero return value indicates that the operation has been initiated. + * It does not indicate whether the workstation has been successfully locked. If the + * function fails, the return value is zero. To get extended error information, call GetLastError. + */ + BOOL LockWorkStation(); } 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 f6a5d44ef9..0e03bd22c9 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java @@ -91,7 +91,7 @@ public class GUITHREADINFO extends Structure { public HWND hwndCaret; public RECT rcCaret; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "flags", "hwndActive", "hwndFocus", "hwndCapture", "hwndMenuOwner", "hwndMoveSize", "hwndCaret", "rcCaret" }); @@ -110,36 +110,222 @@ public class WINDOWINFO extends Structure { public short atomWindowType; public short wCreatorVersion; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "rcWindow", "rcClient", "dwStyle", "dwExStyle", "dwWindowStatus", "cxWindowBorders", "cyWindowBorders", "atomWindowType", "wCreatorVersion" }); } } + + /** + * 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"}); + } + } + /* Get/SetWindowLong properties */ int GWL_EXSTYLE = -20; int GWL_STYLE = -16; int GWL_WNDPROC = -4; int GWL_HINSTANCE = -6; int GWL_ID = -12; int GWL_USERDATA = -21; - int DWL_DLGPROC = 4; - + int GWL_HWNDPARENT = -8; + + int DWL_DLGPROC = Pointer.SIZE; int DWL_MSGRESULT = 0; - int DWL_USER = 8; - - int WS_MAXIMIZE = 0x01000000; - int WS_VISIBLE = 0x10000000; - int WS_MINIMIZE = 0x20000000; - int WS_CHILD = 0x40000000; - int WS_POPUP = 0x80000000; + int DWL_USER = 2*Pointer.SIZE; + + /* Window Styles */ + + /** The window has a thin-line border. */ + int WS_BORDER = 0x800000; + + /** The window has a title bar (includes the WS_BORDER style). */ + 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; + + /** Same as the WS_CHILD style. */ + 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 + * to be updated. If WS_CLIPSIBLINGS is not specified and child windows + * 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; + + /** 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; + + /** 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 + * usually has the WS_TABSTOP style so that the user can move from group to + * group. The user can subsequently change the keyboard focus from one control + * in the group to the next control in the group by using the direction keys + * . + * 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. + */ + int WS_GROUP = 0x20000; + + /** The window has a horizontal scroll bar. */ + int WS_HSCROLL = 0x100000; + + /** The window is initially minimized. Same as the WS_MINIMIZE style. */ + int WS_ICONIC = 0x20000000; + + /** The window is initially maximized. */ + 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; + + /** The window is initially minimized. Same as the WS_ICONIC style. */ + 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; + + /** 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; + + /** The window has a window menu on its title bar. The WS_CAPTION style must also be specified. */ + int WS_SYSMENU = 0x80000; + + /** The window has a sizing border. Same as the WS_SIZEBOX style. */ + 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); + + /** 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); + + /** The window has a sizing border. Same as the WS_THICKFRAME style. */ + 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; + + /** 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; + + /** 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); + + /** The window is initially visible. This style can be turned on and off + * by using the ShowWindow or SetWindowPos function. */ + int WS_VISIBLE = 0x10000000; + + /** The window has a vertical scroll bar. */ + int WS_VSCROLL = 0x200000; + + /* Extended Window Styles */ int WS_EX_COMPOSITED = 0x20000000; int WS_EX_LAYERED = 0x80000; int WS_EX_TRANSPARENT = 32; + /* Layered Window Attributes flags */ int LWA_COLORKEY = 1; int LWA_ALPHA = 2; + + /* Update Layered Window flags */ int ULW_COLORKEY = 1; int ULW_ALPHA = 2; int ULW_OPAQUE = 4; @@ -152,20 +338,20 @@ public class MSG extends Structure { public int time; public POINT pt; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "hWnd", "message", "wParam", "lParam", "time", "pt" }); } } public class FLASHWINFO extends Structure { - public int cbSize; + public int cbSize = size(); public HANDLE hWnd; public int dwFlags; public int uCount; public int dwTimeout; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "hWnd", "dwFlags", "uCount", "dwTimeout" }); } @@ -192,7 +378,7 @@ public SIZE(int w, int h) { this.cy = h; } - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "cx", "cy" }); } } @@ -208,7 +394,7 @@ public class BLENDFUNCTION extends Structure { public byte SourceConstantAlpha; public byte AlphaFormat; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "BlendOp", "BlendFlags", "SourceConstantAlpha", "AlphaFormat" }); } @@ -321,12 +507,13 @@ public class KBDLLHOOKSTRUCT extends Structure { public int time; public ULONG_PTR dwExtraInfo; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "vkCode", "scanCode", "flags", "time", "dwExtraInfo" }); } } + /* System Metrics */ int SM_CXSCREEN = 0; int SM_CYSCREEN = 1; int SM_CXVSCROLL = 2; @@ -564,7 +751,7 @@ public HARDWAREINPUT(Pointer memory) { public WinDef.WORD wParamL; public WinDef.WORD wParamH; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "uMsg", "wParamL", "wParamH" }); } } @@ -600,7 +787,7 @@ public INPUT(Pointer memory) { public WinDef.DWORD type; public INPUT_UNION input = new INPUT_UNION(); - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "type", "input" }); } @@ -698,7 +885,7 @@ public KEYBDINPUT(Pointer memory) { */ public BaseTSD.ULONG_PTR dwExtraInfo; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "wVk", "wScan", "dwFlags", "time", "dwExtraInfo" }); } @@ -734,7 +921,7 @@ public MOUSEINPUT(Pointer memory) { public WinDef.DWORD time; public BaseTSD.ULONG_PTR dwExtraInfo; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "dx", "dy", "mouseData", "dwFlags", "time", "dwExtraInfo" }); } @@ -749,7 +936,7 @@ public static class LASTINPUTINFO extends Structure { // Tick count of when the last input event was received. public int dwTime; - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "dwTime" }); } } @@ -825,13 +1012,7 @@ public WNDCLASSEX(Pointer memory) { /** The h icon sm. */ public HICON hIconSm; - /* - * (non-Javadoc) - * - * @see com.sun.jna.Structure#getFieldOrder() - */ - @Override - protected List getFieldOrder() { + protected List getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "style", "lpfnWndProc", "cbClsExtra", "cbWndExtra", "hInstance", "hIcon", "hCursor", "hbrBackground", "lpszMenuName", @@ -1067,4 +1248,45 @@ public interface MONITORENUMPROC extends Callback public int apply(HMONITOR hMonitor, HDC hdcMonitor, RECT lprcMonitor, LPARAM dwData); } + /* 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; + + /** 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; + + /** 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; + + /** 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; } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java index 72823ef4df..ede5762f99 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java @@ -18,13 +18,20 @@ import java.awt.Robot; import java.awt.event.KeyEvent; -import junit.framework.TestCase; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.JUnitCore; +import static org.junit.Assert.*; + +import com.sun.jna.platform.win32.WinDef.BOOL; +import com.sun.jna.platform.win32.WinDef.DWORD; import com.sun.jna.platform.win32.WinDef.HDC; import com.sun.jna.platform.win32.WinDef.HWND; import com.sun.jna.platform.win32.WinDef.LPARAM; import com.sun.jna.platform.win32.WinDef.POINT; import com.sun.jna.platform.win32.WinDef.RECT; +import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinUser.HMONITOR; import com.sun.jna.platform.win32.WinUser.LASTINPUTINFO; import com.sun.jna.platform.win32.WinUser.MONITORENUMPROC; @@ -34,17 +41,19 @@ /** * @author dblock[at]dblock[dot]org */ -public class User32Test extends TestCase { +public class User32Test { public static void main(String[] args) { - junit.textui.TestRunner.run(User32Test.class); + JUnitCore.runClasses(User32Test.class); } + @Test public void testGetSystemMetrics() { int cursorWidth = INSTANCE.GetSystemMetrics(WinUser.SM_CXCURSOR); assertTrue(cursorWidth > 0); } + @Test public void testRegisterHotKey() { int vk = KeyEvent.VK_D; int id = 1; @@ -106,6 +115,7 @@ private WinUser.MSG waitForMessage(int timeout) { return null; } + @Test public void testGetLastInputInfo() throws Exception { LASTINPUTINFO plii = new LASTINPUTINFO(); assertEquals(plii.size(), plii.cbSize); @@ -115,11 +125,13 @@ public void testGetLastInputInfo() throws Exception { assertTrue(plii.dwTime > 0); } + @Test public final void testRegisterWindowMessage() { final int msg = User32.INSTANCE.RegisterWindowMessage("RM_UNITTEST"); assertTrue(msg >= 0xC000 && msg <= 0xFFFF); } + @Test public final void testMonitorFromPoint() { int dwFlags = WinUser.MONITOR_DEFAULTTOPRIMARY; @@ -127,12 +139,14 @@ public final void testMonitorFromPoint() { assertNotNull(User32.INSTANCE.MonitorFromPoint(pt, dwFlags)); } + @Test public final void testMonitorFromRect() { int dwFlags = WinUser.MONITOR_DEFAULTTOPRIMARY; RECT lprc = new RECT(); assertNotNull(User32.INSTANCE.MonitorFromRect(lprc, dwFlags)); } + @Test public final void testMonitorFromWindow() { int dwFlags = WinUser.MONITOR_DEFAULTTOPRIMARY; @@ -140,6 +154,7 @@ public final void testMonitorFromWindow() { assertNotNull(User32.INSTANCE.MonitorFromWindow(hwnd, dwFlags)); } + @Test public final void testGetMonitorInfo() { HMONITOR hMon = User32.INSTANCE.MonitorFromPoint(new POINT(0, 0), WinUser.MONITOR_DEFAULTTOPRIMARY); @@ -148,6 +163,7 @@ public final void testGetMonitorInfo() { assertTrue(User32.INSTANCE.GetMonitorInfo(hMon, new MONITORINFOEX()).booleanValue()); } + @Test public final void testEnumDisplayMonitors() { assertTrue(User32.INSTANCE.EnumDisplayMonitors(null, null, new MONITORENUMPROC() { @@ -159,4 +175,32 @@ public int apply(HMONITOR hMonitor, HDC hdc, RECT rect, LPARAM lparam) } }, new LPARAM(0)).booleanValue()); } + + @Test + public final void testAdjustWindowRect() { + RECT lpRect = new RECT(); + lpRect.left = 100; + lpRect.top = 200; + lpRect.bottom = 300; + lpRect.right = 500; + + assertTrue(User32.INSTANCE.AdjustWindowRect(lpRect, new DWORD(WinUser.WS_THICKFRAME), new BOOL(1)).booleanValue()); + + assertTrue(lpRect.left < 100); + assertTrue(lpRect.top < 200); + assertTrue(lpRect.bottom > 300); + assertTrue(lpRect.right > 500); + } + + @Ignore("Locks the workstation") + @Test + public final void testLockWorkStation() { + assertTrue(User32.INSTANCE.LockWorkStation().booleanValue()); + } + + @Ignore("Shutsdown the workstation") + @Test + public final void testExitWindows() { + assertTrue(User32.INSTANCE.ExitWindowsEx(new UINT(WinUser.EWX_LOGOFF), new DWORD(0x00030000)).booleanValue()); //This only tries to log off. + } } diff --git a/lib/junit.jar b/lib/junit.jar index 674d71e89e..aaf7444849 100755 Binary files a/lib/junit.jar and b/lib/junit.jar differ