问题
public void toggleAutoHide()
{
APPBARDATA data = new APPBARDATA.ByReference();
data.hWnd = hWndGlobal;
data.cbSize.setValue(data.size());
data.lParam.setValue(Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_GETSTATE), data).longValue());
data.lParam.setValue(data.lParam.intValue() ^ 0x0000001);
UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_SETSTATE), data);
}
I have the code above that is supposed to autohide a created appbar, but somehow instead of doing this to the actual bar I'm creating, it's actually changing the status of the main Windows taskbar. Any clue what step I'm missing?
EDIT:
I've modified the code and changed the call but I'm getting the same values all the time, regardless of what I set the values to.
public void toggleAutoHide()
{
APPBARDATA data = new APPBARDATA.ByReference();
data.hWnd = hWndGlobal;
data.cbSize.setValue(data.size());
data.uEdge.setValue(ShellAPI.ABE_TOP);
System.out.println("LParam [byte, int]: " + data.lParam.byteValue() + " -- " + data.lParam.intValue());
//lParam always shows 0
if(data.lParam.intValue() == 1)
{
data.lParam.setValue(0);
}
else
{
data.lParam.setValue(1);
}
UINT_PTR result = Shell32.INSTANCE.SHAppBarMessage(new DWORD(ShellAPI.ABM_SETAUTOHIDEBAR), data);
System.out.println("Result = " + result.intValue()); //always returns 1
}
回答1:
The ABM_SETSTATE call is using your data.hWnd
variable to decide which window handle gets your changes. You assign that to the value a variable hWndGlobal
but don't explain where that came from.
The fact that it's named "global" seems to imply somewhere earlier in the code you gave it the value for the Windows taskbar. Hunt down that assignment.
You probably want something like:
data.hWnd = User32.INSTANCE.FindWindowA(null, "Title of your new appbar");
来源:https://stackoverflow.com/questions/38961782/shappbarmessage-and-autohide