Skip to content

Commit

Permalink
Add support of function SHAppBarMessage from ShellApi.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino authored and dblock committed Jun 23, 2013
1 parent 897b318 commit e0d2079
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 - [@bsorrentinoJ](https://github.com/bsorrentino).
* 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).
Expand Down
39 changes: 39 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Shell32.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,4 +169,42 @@ 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
*
* @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 <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787951(v=vs.85).aspx">ABM_NEW</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787955(v=vs.85).aspx">ABM_REMOVE</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787953(v=vs.85).aspx">ABM_QUERYPOS</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787959(v=vs.85).aspx">ABM_SETPOS</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787947(v=vs.85).aspx">ABM_GETSTATE</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787949(v=vs.85).aspx">ABM_GETTASKBARPOS</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787943(v=vs.85).aspx">ABM_ACTIVATE</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787945(v=vs.85).aspx">ABM_GETAUTOHIDEBAR</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787957(v=vs.85).aspx">ABM_SETAUTOHIDEBAR</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787963(v=vs.85).aspx">ABM_WINDOWPOSCHANGED</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787961(v=vs.85).aspx">ABM_SETSTATE</a>
*
*/
UINT_PTR SHAppBarMessage( DWORD dwMessage, APPBARDATA pData );
}
90 changes: 90 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/ShellAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -115,5 +121,89 @@ 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;

/** 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 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");
}
}

}
79 changes: 79 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@
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.WinDef.UINT_PTR;
import com.sun.jna.ptr.PointerByReference;


/**
* @author dblock[at]dblock[dot]org
* @author markus[at]headcrashing[dot]eu
*/
public class Shell32Test extends TestCase {

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);
}
Expand All @@ -48,4 +56,75 @@ public final void testSHGetSpecialFolderPath() {
assertTrue(Shell32.INSTANCE.SHGetSpecialFolderPath(null, pszPath, ShlObj.CSIDL_APPDATA, false));
assertFalse(Native.toString(pszPath).isEmpty());
}


private void newAppBar() {
APPBARDATA data = new APPBARDATA.ByReference();
data.cbSize.setValue(data.size());
data.uCallbackMessage.setValue(WM_USER + 1);

UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_NEW), data);
assertNotNull(result);
}

private void removeAppBar() {
APPBARDATA data = new APPBARDATA.ByReference();
data.cbSize.setValue(data.size());
UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_REMOVE), data);
assertNotNull(result);

}

private void queryPos(APPBARDATA data) {
UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_QUERYPOS), data);

assertNotNull(h);
assertTrue(h.intValue() > 0);

}

public void testResizeDesktopFromBottom() throws InterruptedException {

newAppBar();

APPBARDATA data = new APPBARDATA.ByReference();

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(data);

UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_SETPOS), data);

assertNotNull(h);
assertTrue(h.intValue() >= 0);

removeAppBar();
}

public void testResizeDesktopFromTop() throws InterruptedException {

newAppBar();

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);

UINT_PTR h = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_SETPOS), data);

assertNotNull(h);
assertTrue(h.intValue() >= 0);

removeAppBar();

}

}

0 comments on commit e0d2079

Please sign in to comment.