SHAppBarMessage和AutoHide

SHAppBarMessage和AutoHide

本文介绍了SHAppBarMessage和AutoHide的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我上面的代码应该自动隐藏已创建的应用程序栏,但是不以某种方式代替我正在创建的实际栏,它实际上是在更改Windows主任务栏的状态.知道我缺少什么步骤吗?

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?

我已经修改了代码并更改了调用,但是无论我将值设置为什么,我一直都在获得相同的值.

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
    }

推荐答案

ABM_SETSTATE 调用正在使用您的data.hWnd变量来确定哪个窗口句柄可以获取您的更改.您将其分配给变量hWndGlobal的值,但不解释其来源.

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.

它被命名为"global"的事实似乎暗示您在代码中为Windows任务栏赋予了该值的某个位置.寻找该任务.

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

这篇关于SHAppBarMessage和AutoHide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:52