0
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 Answers1

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");
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
  • I found the assignment and it assigns hWndGlobal via the assignment statement you've used above. However I get the same behavior. I tried to explicitly set it via the FindWindowA method but still the same behavior. Is there something else I'm missing? – Jurassic Beach Aug 17 '16 at 18:53
  • On closer inspection, it looks like the ABM_SETSTATE always apply to the main taskbar. Have you looked at [ABM_SETAUTOHIDEBAR](https://msdn.microsoft.com/en-us/library/windows/desktop/bb787957(v=vs.85).aspx) or its related functions? Also, you can apparently only have one auto-hide bar per edge of screen... – Daniel Widdis Aug 18 '16 at 03:25
  • I've modified the code and placed a debug statement. It seems to always show a value of 0 in the lParam field. (edits above) – Jurassic Beach Aug 18 '16 at 18:10
  • With the edits you added, it's no surprise that it's 0 -- you initialize it new. Did you mean to use the ABM_GETSTATE call somewhere in that sequence? – Daniel Widdis Aug 18 '16 at 20:21
  • I had a ABM_GETSTATE call but it never changed anything. Should that happen in conjunction with the lParam method or something else? I'm kind of only going off what I'm finding in the MSDN but I'm not too familiar overall. – Jurassic Beach Aug 19 '16 at 20:40
  • But the ABM_GETSTATE populates the value of iParam, at least for the Global taskbar. But that doesn't appear to be what you want to manipulate. – Daniel Widdis Aug 20 '16 at 06:23
  • I'm not familiar with this specific application. I am trying to answer only the JNA portions of it. You need to carefully read the docs for each of the functions you are using to see what it manipulates. The GETSTATE and SETSTATE look like they apply to the main taskbar, while the other functions look like they apply to specific windows. – Daniel Widdis Aug 24 '16 at 06:06