From a22beae1c0bbf7ee82ce367cbf1b4b70e0c808f1 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Tue, 18 Jun 2013 22:09:12 +0200 Subject: [PATCH 1/3] Issue #241 --- .../com/sun/jna/platform/win32/Shell32.java | 61 ++++++++++ .../com/sun/jna/platform/win32/ShellAPI.java | 66 +++++++++++ .../sun/jna/platform/win32/Shell32Test.java | 105 +++++++++++++++++- 3 files changed, 231 insertions(+), 1 deletion(-) diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java b/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java index 321a20c416..540b782a82 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java @@ -168,4 +168,65 @@ INT_PTR ShellExecute(HWND hwnd, String lpOperation, String lpFile, String lpPara * @return {@code true} if successful; otherwise, {@code false}. */ boolean SHGetSpecialFolderPath(HWND owner, char[] path, int csidl, boolean create); + + + /** + * SHAppBarMessage function +4 out of 8 rated this helpful - Rate this topic +Sends an appbar message to the system. +Syntax +C++ + +UINT_PTR SHAppBarMessage( + _In_ DWORD dwMessage, + _Inout_ PAPPBARDATA pData +); + +Parameters +dwMessage [in] +Type: DWORD +Appbar message value to send. This parameter can be one of the following values. +ABM_NEW (0x00000000) +Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. +ABM_REMOVE (0x00000001) +Unregisters an appbar, removing the bar from the system's internal list. +ABM_QUERYPOS (0x00000002) +Requests a size and screen position for an appbar. +ABM_SETPOS (0x00000003) +Sets the size and screen position of an appbar. +ABM_GETSTATE (0x00000004) +Retrieves the autohide and always-on-top states of the Windows taskbar. +ABM_GETTASKBARPOS (0x00000005) +Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app barsÑthe working area available to your applicationÑ, use the GetMonitorInfo function. +ABM_ACTIVATE (0x00000006) +Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate. +ABM_GETAUTOHIDEBAR (0x00000007) +Retrieves the handle to the autohide appbar associated with a particular edge of the screen. +ABM_SETAUTOHIDEBAR (0x00000008) +Registers or unregisters an autohide appbar for an edge of the screen. +ABM_WINDOWPOSCHANGED (0x00000009) +Notifies the system when an appbar's position has changed. +ABM_SETSTATE (0x0000000A) +Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes. +pData [in, out] +Type: PAPPBARDATA +A pointer to an APPBARDATA structure. The content of the structure on entry and on exit depends on the value set in the dwMessage parameter. See the individual message pages for specifics. +Return value +Type: UINT_PTR +This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar message sent. Links to those documents are given in the See Also section. +Requirements +Minimum supported client +Windows XP [desktop apps only] +Minimum supported server +Windows 2000 Server [desktop apps only] +Header +Shellapi.h +Library +Shell32.lib +DLL +Shell32.dll (version 4.0 or later) + + */ + + HANDLE SHAppBarMessage( DWORD dwMessage, APPBARDATA pData ); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java b/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java index 76c1af27b7..2645e092fd 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java @@ -19,7 +19,13 @@ import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.WString; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.HWND; +import com.sun.jna.platform.win32.WinDef.LPARAM; +import com.sun.jna.platform.win32.WinDef.RECT; +import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.sun.jna.platform.win32.WinNT.PSID; import com.sun.jna.win32.StdCallLibrary; /** @@ -115,5 +121,65 @@ public String encodePaths(String[] paths) { } return encoded + "\0"; } + + } + + // Appbar message value to send. This parameter can be one of the following values. + int ABM_NEW = 0x00000000; + //Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. + int ABM_REMOVE = 0x00000001; + //Unregisters an appbar, removing the bar from the system's internal list. + int ABM_QUERYPOS = 0x00000002; + //Requests a size and screen position for an appbar. + int ABM_SETPOS = 0x00000003; + //Sets the size and screen position of an appbar. + int ABM_GETSTATE = 0x00000004; + //Retrieves the autohide and always-on-top states of the Windows taskbar. + int ABM_GETTASKBARPOS = 0x00000005; + //Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app barsÑthe working area available to your applicationÑ, use the GetMonitorInfo function. + int ABM_ACTIVATE = 0x00000006; + //Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate. + int ABM_GETAUTOHIDEBAR = 0x00000007; + //Retrieves the handle to the autohide appbar associated with a particular edge of the screen. + int ABM_SETAUTOHIDEBAR = 0x00000008; + //Registers or unregisters an autohide appbar for an edge of the screen. + int ABM_WINDOWPOSCHANGED = 0x00000009; + //Notifies the system when an appbar's position has changed. + int ABM_SETSTATE = 0x0000000A; + + int ABE_LEFT = 0; // Left edge. + int ABE_TOP = 1; // Top edge. + int ABE_RIGHT = 2; // Right edge. + int ABE_BOTTOM = 3; // Bottom edge. + + /** + * Contains information about a system appbar message. + */ + public static class APPBARDATA extends Structure { + public static class ByReference extends APPBARDATA implements Structure.ByReference {} + + public DWORD cbSize; + public HWND hWnd; + public UINT uCallbackMessage; + public UINT uEdge; + public RECT rc; + public LPARAM lParam; + + public APPBARDATA() { + super(); + } + + public APPBARDATA(Pointer p) { + super(p); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList("cbSize", "hWnd", "uCallbackMessage", "uEdge", + "rc", "lParam"); + } + + } + } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java index 00d855a10d..1002c12896 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java @@ -15,18 +15,32 @@ import junit.framework.TestCase; import com.sun.jna.Native; +import com.sun.jna.platform.win32.ShellAPI.APPBARDATA; +import com.sun.jna.platform.win32.WinDef.DWORD; +import com.sun.jna.platform.win32.WinDef.RECT; +import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.PointerByReference; + /** * @author dblock[at]dblock[dot]org * @author markus[at]headcrashing[dot]eu */ public class Shell32Test extends TestCase { - public static void main(String[] args) { + private static final int RESIZE_HEIGHT = 500; + private static final int WM_USER = 0x0400; + + public static void main(String[] args) { junit.textui.TestRunner.run(Shell32Test.class); } + public void setup() { + + APPBARDATA ABData = new APPBARDATA(); + + + } public void testSHGetFolderPath() { char[] pszPath = new char[WinDef.MAX_PATH]; assertEquals(W32Errors.S_OK, Shell32.INSTANCE.SHGetFolderPath(null, @@ -48,4 +62,93 @@ public final void testSHGetSpecialFolderPath() { assertTrue(Shell32.INSTANCE.SHGetSpecialFolderPath(null, pszPath, ShlObj.CSIDL_APPDATA, false)); assertFalse(Native.toString(pszPath).isEmpty()); } + + private boolean AppBar_Register() { + DWORD dwABM = new DWORD(); + + APPBARDATA ABData = new APPBARDATA.ByReference(); + ABData.uCallbackMessage.setValue( WM_USER + 1); + ABData.cbSize.setValue( ABData.size() ); + dwABM.setValue(ShellAPI.ABM_NEW); + + return (null!=Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData)); + } + + private boolean AppBar_Unregister() { + DWORD dwABM = new DWORD(); + APPBARDATA ABData = new APPBARDATA.ByReference(); + ABData.cbSize.setValue( ABData.size() ); + dwABM.setValue(ShellAPI.ABM_REMOVE); + return (null!=Shell32.INSTANCE.SHAppBarMessage(dwABM, ABData)); + } + + public void queryPos( APPBARDATA ABData ) { + DWORD dwABM = new DWORD(); + + dwABM.setValue(ShellAPI.ABM_QUERYPOS); + HANDLE h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); + + assertNotNull(h); + + System.out.printf( "ABData.rc[%d,%d,%d,%d]\n", + ABData.rc.top, + ABData.rc.left, + ABData.rc.bottom, + ABData.rc.right); + + } + + public void testResizeDesktopFromBottom() throws InterruptedException { + + DWORD dwABM = new DWORD(); + + assertTrue( AppBar_Register() ); + + APPBARDATA ABData = new APPBARDATA.ByReference(); + System.out.printf( "APPBARDATA sizeof [%d]\n", ABData.size()); + + ABData.uEdge.setValue(ShellAPI.ABE_BOTTOM); + ABData.rc.top = User32.INSTANCE.GetSystemMetrics(User32.SM_CYFULLSCREEN) - RESIZE_HEIGHT; + ABData.rc.left = 0; + ABData.rc.bottom = User32.INSTANCE.GetSystemMetrics(User32.SM_CYFULLSCREEN); + ABData.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN); + + queryPos(ABData); + + dwABM.setValue(ShellAPI.ABM_SETPOS); + HANDLE h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); + + assertNotNull(h); + + + Thread.sleep( 5 * 1000 ); + assertTrue( AppBar_Unregister() ); + + } + + public void testResizeDesktopFromTop() throws InterruptedException { + + DWORD dwABM = new DWORD(); + + assertTrue( AppBar_Register() ); + + APPBARDATA ABData = new APPBARDATA.ByReference(); + ABData.uEdge.setValue(ShellAPI.ABE_TOP); + ABData.rc.top = 0; + ABData.rc.left = 0; + ABData.rc.bottom = RESIZE_HEIGHT; + ABData.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN); + + queryPos(ABData); + + dwABM.setValue(ShellAPI.ABM_SETPOS); + HANDLE h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); + + assertNotNull(h); + + Thread.sleep( 5 * 1000 ); + assertTrue( AppBar_Unregister() ); + + } + } From eca04440566651879bdf35fdef6802fee2b6115e Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Fri, 21 Jun 2013 12:59:30 +0200 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 2ee88bd265..eb4d9dadaa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ NOTE: JNI native support is typically incompatible between minor versions, and a Features -------- +* [##241](https://github.com/twall/jna/issues/241) - Add support function SHAppBarMessage from ShellApi * Added ASL licensing to facilitate distribution - [@twall](https://github.com/twall). * [#109](https://github.com/twall/jna/issues/109): Set default Java compatibility level to 1.6 - [@twall](https://github.com/twall). * [#209](https://github.com/twall/jna/issues/209): Improved default performance saving last error results - [@twall](https://github.com/twall). From 3183f00f87f89f43a0aea4ff32254cc607946ef5 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Fri, 21 Jun 2013 13:10:25 +0200 Subject: [PATCH 3/3] Issue #241 javadoc refactoring unit test refactoring CHANGES.md update --- CHANGES.md | 2 +- .../com/sun/jna/platform/win32/Shell32.java | 89 +++++++----------- .../com/sun/jna/platform/win32/ShellAPI.java | 92 ++++++++++++------- .../sun/jna/platform/win32/Shell32Test.java | 85 ++++++++--------- 4 files changed, 131 insertions(+), 137 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index eb4d9dadaa..85cb9c89ac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,7 @@ NOTE: JNI native support is typically incompatible between minor versions, and a Features -------- -* [##241](https://github.com/twall/jna/issues/241) - Add support function SHAppBarMessage from ShellApi +* [#241](https://github.com/twall/jna/issues/241) - Add support function SHAppBarMessage from ShellApi * Added ASL licensing to facilitate distribution - [@twall](https://github.com/twall). * [#109](https://github.com/twall/jna/issues/109): Set default Java compatibility level to 1.6 - [@twall](https://github.com/twall). * [#209](https://github.com/twall/jna/issues/209): Improved default performance saving last error results - [@twall](https://github.com/twall). diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java b/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java index 540b782a82..302766d272 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Shell32.java @@ -16,6 +16,7 @@ import com.sun.jna.platform.win32.WinDef.DWORD; import com.sun.jna.platform.win32.WinDef.HWND; import com.sun.jna.platform.win32.WinDef.INT_PTR; +import com.sun.jna.platform.win32.WinDef.UINT_PTR; import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.ptr.PointerByReference; @@ -172,61 +173,39 @@ INT_PTR ShellExecute(HWND hwnd, String lpOperation, String lpFile, String lpPara /** * SHAppBarMessage function -4 out of 8 rated this helpful - Rate this topic -Sends an appbar message to the system. -Syntax -C++ - -UINT_PTR SHAppBarMessage( - _In_ DWORD dwMessage, - _Inout_ PAPPBARDATA pData -); - -Parameters -dwMessage [in] -Type: DWORD -Appbar message value to send. This parameter can be one of the following values. -ABM_NEW (0x00000000) -Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. -ABM_REMOVE (0x00000001) -Unregisters an appbar, removing the bar from the system's internal list. -ABM_QUERYPOS (0x00000002) -Requests a size and screen position for an appbar. -ABM_SETPOS (0x00000003) -Sets the size and screen position of an appbar. -ABM_GETSTATE (0x00000004) -Retrieves the autohide and always-on-top states of the Windows taskbar. -ABM_GETTASKBARPOS (0x00000005) -Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app barsÑthe working area available to your applicationÑ, use the GetMonitorInfo function. -ABM_ACTIVATE (0x00000006) -Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate. -ABM_GETAUTOHIDEBAR (0x00000007) -Retrieves the handle to the autohide appbar associated with a particular edge of the screen. -ABM_SETAUTOHIDEBAR (0x00000008) -Registers or unregisters an autohide appbar for an edge of the screen. -ABM_WINDOWPOSCHANGED (0x00000009) -Notifies the system when an appbar's position has changed. -ABM_SETSTATE (0x0000000A) -Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes. -pData [in, out] -Type: PAPPBARDATA -A pointer to an APPBARDATA structure. The content of the structure on entry and on exit depends on the value set in the dwMessage parameter. See the individual message pages for specifics. -Return value -Type: UINT_PTR -This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar message sent. Links to those documents are given in the See Also section. -Requirements -Minimum supported client -Windows XP [desktop apps only] -Minimum supported server -Windows 2000 Server [desktop apps only] -Header -Shellapi.h -Library -Shell32.lib -DLL -Shell32.dll (version 4.0 or later) - + * + * @param dwMessage + * Appbar message value to send. This parameter can be one of the following values. + * {@link ShellAPI#ABM_NEW} Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. + * {@link ShellAPI#ABM_REMOVE} Unregisters an appbar, removing the bar from the system's internal list. + * {@link ShellAPI#ABM_QUERYPOS} Requests a size and screen position for an appbar. + * {@link ShellAPI#ABM_SETPOS} Sets the size and screen position of an appbar. + * {@link ShellAPI#ABM_GETSTATE} Retrieves the autohide and always-on-top states of the Windows taskbar. + * {@link ShellAPI#ABM_GETTASKBARPOS} Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app barsÑthe working area available to your applicationÑ, use the GetMonitorInfo function. + * {@link ShellAPI#ABM_ACTIVATE} Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate. + * {@link ShellAPI#ABM_GETAUTOHIDEBAR} Retrieves the handle to the autohide appbar associated with a particular edge of the screen. + * {@link ShellAPI#ABM_SETAUTOHIDEBAR} Registers or unregisters an autohide appbar for an edge of the screen. + * {@link ShellAPI#ABM_WINDOWPOSCHANGED} Notifies the system when an appbar's position has changed. + * {@link ShellAPI#ABM_SETSTATE} Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes. + * + * @param pData + * A pointer to an APPBARDATA structure. The content of the structure on entry and on exit depends on the value set in the dwMessage parameter. See the individual message pages for specifics. + * + * @return This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar message sent. + * + * @see ABM_NEW + * @see ABM_REMOVE + * @see ABM_QUERYPOS + * @see ABM_SETPOS + * @see ABM_GETSTATE + * @see ABM_GETTASKBARPOS + * @see ABM_ACTIVATE + * @see ABM_GETAUTOHIDEBAR + * @see ABM_SETAUTOHIDEBAR + * @see ABM_WINDOWPOSCHANGED + * @see ABM_SETSTATE + * */ - HANDLE SHAppBarMessage( DWORD dwMessage, APPBARDATA pData ); + UINT_PTR SHAppBarMessage( DWORD dwMessage, APPBARDATA pData ); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java b/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java index 2645e092fd..0ce46115d7 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java @@ -125,61 +125,85 @@ public String encodePaths(String[] paths) { } - // Appbar message value to send. This parameter can be one of the following values. + /** + * Appbar message value to send. This parameter can be one of the following + * values. + */ int ABM_NEW = 0x00000000; - //Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar. + /** + * Registers a new appbar and specifies the message identifier that the + * system should use to send notification messages to the appbar. + */ int ABM_REMOVE = 0x00000001; - //Unregisters an appbar, removing the bar from the system's internal list. + /** Unregisters an appbar, removing the bar from the system's internal list.*/ int ABM_QUERYPOS = 0x00000002; - //Requests a size and screen position for an appbar. + /** Requests a size and screen position for an appbar. */ int ABM_SETPOS = 0x00000003; - //Sets the size and screen position of an appbar. + /** Sets the size and screen position of an appbar. */ int ABM_GETSTATE = 0x00000004; - //Retrieves the autohide and always-on-top states of the Windows taskbar. + /** Retrieves the autohide and always-on-top states of the Windows taskbar. */ int ABM_GETTASKBARPOS = 0x00000005; - //Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app barsÑthe working area available to your applicationÑ, use the GetMonitorInfo function. + /** + * Retrieves the bounding rectangle of the Windows taskbar. Note that this + * applies only to the system taskbar. Other objects, particularly toolbars + * supplied with third-party software, also can be present. As a result, + * some of the screen area not covered by the Windows taskbar might not be + * visible to the user. To retrieve the area of the screen not covered by + * both the taskbar and other app barsÑthe working area available to your + * applicationÑ, use the GetMonitorInfo function. + */ int ABM_ACTIVATE = 0x00000006; - //Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate. + /** + * Notifies the system to activate or deactivate an appbar. The lParam + * member of the APPBARDATA pointed to by pData is set to TRUE to activate + * or FALSE to deactivate. + */ int ABM_GETAUTOHIDEBAR = 0x00000007; - //Retrieves the handle to the autohide appbar associated with a particular edge of the screen. + /** + * Retrieves the handle to the autohide appbar associated with a particular + * edge of the screen. + */ int ABM_SETAUTOHIDEBAR = 0x00000008; - //Registers or unregisters an autohide appbar for an edge of the screen. + /** Registers or unregisters an autohide appbar for an edge of the screen. */ int ABM_WINDOWPOSCHANGED = 0x00000009; - //Notifies the system when an appbar's position has changed. + /** Notifies the system when an appbar's position has changed. */ int ABM_SETSTATE = 0x0000000A; - int ABE_LEFT = 0; // Left edge. - int ABE_TOP = 1; // Top edge. - int ABE_RIGHT = 2; // Right edge. - int ABE_BOTTOM = 3; // Bottom edge. - + /** Left edge. */ + int ABE_LEFT = 0; + /** Top edge. */ + int ABE_TOP = 1; + /** Right edge. */ + int ABE_RIGHT = 2; + /** Bottom edge. */ + int ABE_BOTTOM = 3; + /** * Contains information about a system appbar message. */ public static class APPBARDATA extends Structure { - public static class ByReference extends APPBARDATA implements Structure.ByReference {} + public static class ByReference extends APPBARDATA implements Structure.ByReference { + } - public DWORD cbSize; - public HWND hWnd; - public UINT uCallbackMessage; - public UINT uEdge; - public RECT rc; - public LPARAM lParam; + public DWORD cbSize; + public HWND hWnd; + public UINT uCallbackMessage; + public UINT uEdge; + public RECT rc; + public LPARAM lParam; - public APPBARDATA() { - super(); + public APPBARDATA() { + super(); } - public APPBARDATA(Pointer p) { - super(p); - } + public APPBARDATA(Pointer p) { + super(p); + } - @Override - protected List getFieldOrder() { - return Arrays.asList("cbSize", "hWnd", "uCallbackMessage", "uEdge", - "rc", "lParam"); - } - + @Override + protected List getFieldOrder() { + return Arrays.asList("cbSize", "hWnd", "uCallbackMessage", "uEdge", "rc", "lParam"); + } } } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java index 1002c12896..a5f932e2a4 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java @@ -18,7 +18,7 @@ import com.sun.jna.platform.win32.ShellAPI.APPBARDATA; import com.sun.jna.platform.win32.WinDef.DWORD; import com.sun.jna.platform.win32.WinDef.RECT; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.sun.jna.platform.win32.WinDef.UINT_PTR; import com.sun.jna.ptr.PointerByReference; @@ -35,12 +35,6 @@ public static void main(String[] args) { junit.textui.TestRunner.run(Shell32Test.class); } - public void setup() { - - APPBARDATA ABData = new APPBARDATA(); - - - } public void testSHGetFolderPath() { char[] pszPath = new char[WinDef.MAX_PATH]; assertEquals(W32Errors.S_OK, Shell32.INSTANCE.SHGetFolderPath(null, @@ -62,8 +56,9 @@ public final void testSHGetSpecialFolderPath() { assertTrue(Shell32.INSTANCE.SHGetSpecialFolderPath(null, pszPath, ShlObj.CSIDL_APPDATA, false)); assertFalse(Native.toString(pszPath).isEmpty()); } + - private boolean AppBar_Register() { + private void newAppBar() { DWORD dwABM = new DWORD(); APPBARDATA ABData = new APPBARDATA.ByReference(); @@ -71,83 +66,79 @@ private boolean AppBar_Register() { ABData.cbSize.setValue( ABData.size() ); dwABM.setValue(ShellAPI.ABM_NEW); - return (null!=Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData)); + UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData); + assertNotNull(result ); } - private boolean AppBar_Unregister() { + private void removeAppBar() { + DWORD dwABM = new DWORD(); APPBARDATA ABData = new APPBARDATA.ByReference(); ABData.cbSize.setValue( ABData.size() ); dwABM.setValue(ShellAPI.ABM_REMOVE); - return (null!=Shell32.INSTANCE.SHAppBarMessage(dwABM, ABData)); + UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData); + assertNotNull(result ); + } - public void queryPos( APPBARDATA ABData ) { + private void queryPos( APPBARDATA ABData ) { DWORD dwABM = new DWORD(); dwABM.setValue(ShellAPI.ABM_QUERYPOS); - HANDLE h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); + UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); assertNotNull(h); + assertTrue(h.intValue()>0); - System.out.printf( "ABData.rc[%d,%d,%d,%d]\n", - ABData.rc.top, - ABData.rc.left, - ABData.rc.bottom, - ABData.rc.right); - } public void testResizeDesktopFromBottom() throws InterruptedException { + newAppBar(); + DWORD dwABM = new DWORD(); - assertTrue( AppBar_Register() ); - APPBARDATA ABData = new APPBARDATA.ByReference(); - System.out.printf( "APPBARDATA sizeof [%d]\n", ABData.size()); + APPBARDATA data = new APPBARDATA.ByReference(); - ABData.uEdge.setValue(ShellAPI.ABE_BOTTOM); - ABData.rc.top = User32.INSTANCE.GetSystemMetrics(User32.SM_CYFULLSCREEN) - RESIZE_HEIGHT; - ABData.rc.left = 0; - ABData.rc.bottom = User32.INSTANCE.GetSystemMetrics(User32.SM_CYFULLSCREEN); - ABData.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN); + data.uEdge.setValue(ShellAPI.ABE_BOTTOM); + data.rc.top = User32.INSTANCE.GetSystemMetrics(User32.SM_CYFULLSCREEN) - RESIZE_HEIGHT; + data.rc.left = 0; + data.rc.bottom = User32.INSTANCE.GetSystemMetrics(User32.SM_CYFULLSCREEN); + data.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN); - queryPos(ABData); + queryPos(data); dwABM.setValue(ShellAPI.ABM_SETPOS); - HANDLE h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); + UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage( dwABM, data ); assertNotNull(h); - - - Thread.sleep( 5 * 1000 ); - assertTrue( AppBar_Unregister() ); - + assertTrue(h.intValue()>=0); + + removeAppBar(); } public void testResizeDesktopFromTop() throws InterruptedException { + newAppBar(); DWORD dwABM = new DWORD(); - assertTrue( AppBar_Register() ); - - APPBARDATA ABData = new APPBARDATA.ByReference(); - ABData.uEdge.setValue(ShellAPI.ABE_TOP); - ABData.rc.top = 0; - ABData.rc.left = 0; - ABData.rc.bottom = RESIZE_HEIGHT; - ABData.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN); - - queryPos(ABData); + APPBARDATA data = new APPBARDATA.ByReference(); + data.uEdge.setValue(ShellAPI.ABE_TOP); + data.rc.top = 0; + data.rc.left = 0; + data.rc.bottom = RESIZE_HEIGHT; + data.rc.right = User32.INSTANCE.GetSystemMetrics(User32.SM_CXFULLSCREEN); + + queryPos(data); dwABM.setValue(ShellAPI.ABM_SETPOS); - HANDLE h = Shell32.INSTANCE.SHAppBarMessage( dwABM, ABData ); + UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage( dwABM, data ); assertNotNull(h); + assertTrue(h.intValue()>=0); - Thread.sleep( 5 * 1000 ); - assertTrue( AppBar_Unregister() ); + removeAppBar(); }