获取任务栏句柄 [英] Obtain Handle to Task Bar

查看:32
本文介绍了获取任务栏句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 WinAPI 函数来检索任务栏的句柄?

Is there a WinAPI function to retrieve a handle to the Task Bar?

目的是确定任务栏停靠设置(ABE_LEFT、ABE_RIGHT、ABE_BOTTOM、ABE_TOP).SHAppBarMessage 函数需要任务栏句柄来检索停靠信息.除非有另一种方法来确定不需要手柄的任务栏停靠设置?

The purpose is to determine the Task Bar docking setting (ABE_LEFT, ABE_RIGHT, ABE_BOTTOM, ABE_TOP). The function SHAppBarMessage requires the taskbar handle to retrieve the docking information. Unless there is another way to determine the task bar docking setting without needing the handle?

我知道这种方法可以正常工作,但我不确定它是否适用于所有 Windows 版本:

I'm aware of this method which works ok but I am not sure it works on all Windows versions:

HWND taskBar = FindWindow("Shell_TrayWnd", NULL);

推荐答案

这似乎是一个文档错误.您不需要在 APPBARDATA 调用 ABM_GETTASKBARPOS 时的结构="https://msdn.microsoft.com/en-us/library/windows/desktop/bb762108.aspx" rel="nofollow">SHAppBarMessage1).

That appears to be a documentation bug. You don't need to provide a window handle in the APPBARDATA structure for the ABM_GETTASKBARPOS when calling SHAppBarMessage1).

以下代码正确返回任务栏的位置(在 Windows 10 x64 上测试):

The following code properly returns the location of the taskbar (tested on Windows 10 x64):

#include <shellapi.h>
#pragma comment(lib, "Shell32.lib")
#include <stdexcept>

RECT GetTaskbarPos() {
    APPBARDATA abd = { 0 };
    abd.cbSize = sizeof( abd );
    if ( !::SHAppBarMessage( ABM_GETTASKBARPOS, &abd ) ) {
        throw std::runtime_error( "SHAppBarMessage failed." );
    }
    return abd.rc;
}

更新:问题实际上是要求对接枚举值.这也被返回:

Update: The question was really asking for the docking enumeration value. That is returned as well:

#include <shellapi.h>
#pragma comment(lib, "Shell32.lib")
#include <stdexcept>

UINT GetTaskbarDockingEdge() {
    APPBARDATA abd = { 0 };
    abd.cbSize = sizeof( abd );
    if ( !::SHAppBarMessage( ABM_GETTASKBARPOS, &abd ) ) {
        throw std::runtime_error( "SHAppBarMessage failed." );
    }
    return abd.uEdge;
}


1) 如果你需要任务栏隐藏的很好的窗口句柄来发送这个消息,那会很尴尬.如果你已经有了窗口句柄,你可以简单地调用 GetWindowRect 代替.

这篇关于获取任务栏句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆