Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Jun 18, 2013
1 parent 2d7971a commit a22beae
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 1 deletion.
61 changes: 61 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 @@ -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 );
}
66 changes: 66 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,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");
}

}

}
105 changes: 104 additions & 1 deletion contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() );

}

}

0 comments on commit a22beae

Please sign in to comment.