Windows任务栏探究

您所在的位置:网站首页 windows的任务栏可用于什么程序中运行 Windows任务栏探究

Windows任务栏探究

2024-07-13 15:36| 来源: 网络整理| 查看: 265

首先任务栏有两个主要功能: 1、为用户提供了用于访问应用程序的按钮 2、显示用户正在运行的程序 首先安装完系统后,任务栏中默认有开始菜单、搜索、网络、音量、输入法、日期等按钮,这些是系统默认添加的。有些可以根据需求用户可以自己选择是否显示(搜索、工具栏等),有些是系统默认用户无法删除或隐藏(开始、日期等)。 ==将程序快捷方式添加到任务栏==  对于用户自己实现将程序添加到任务栏,最常见的方式是右键桌面快捷方式或者开始菜单中快捷方式,选择固定到任务栏即可,取消的话则直接右键任务栏中快捷方式按钮选择从任务栏取消固定即可。 与桌面快捷方式相同的是:任务栏中的快捷方式按钮也是以文件的形式存在,快捷方式文件存放在:C:\Users\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar文件夹下 但是与桌面快捷方式等不同的是,对于桌面快捷方式直接将快捷方式放到桌面文件夹下后,在桌面上立即就会显示该快捷方式,删除同理。而对于任务栏文件夹下文件,直接添加快捷方式文件或者删除文件都不会体现在任务栏中(删除文件夹下文件,在点击任务栏会报错提示删除)。

在win10之前,Windows提供了一个API可以方便快捷的调用接口实现将程序固定到任务栏或者从任务栏取消: ``` lang = c++ /* shortcut:快捷方式位置 */ ShellExecute(NULL, L"taskbarpin", shortcut,NULL, NULL, 0) //固定到任务栏 ShellExecute(NULL, L"taskbarunpin",shortcut, NULL, NULL, 0) //从任务栏取消

ShellExecute(NULL, L"startpin", shortcut,NULL, NULL, 0) //固定到开始菜单 ShellExecute(NULL, L"startunpin",shortcut, NULL, NULL, 0) //从开始菜单取消

/* Qt方式 */ QFile::link(srcFile, taskBarPath); // 指定快捷方式位置和指向目标位置

 ``` 到win10后:Have just recieved this reply from MS support: "The items that are pinned to the Start menu or taskbar is a user preference. Applications should not be overriding the user’s preferences. In the long term, programmatically pinning items to the taskbar or Start menu in Windows 10 will not be supported. Only the user will be able to pin items." So it is no longer supported to pin/unpin items in the taskbar.... We will now to make a request for change the enable programmatic pinning and unpinning of programs in the Enterprise edition of Windows 10, and/or using group policies.(windows认为固定到任务栏功能是属于用户的操作,程序不应当越过用户进行操作,因此在win10上不再支持该接口)

其中上述两种功能只是我们最常见也是最基本的功能,任务栏按钮还能实现以下功能。

但是到了Qt6.x版本以后,Qt 6 是有意识地努力使框架更加高效和易于使用的结果。我们尝试在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为更好的框架,一些更改是不可避免的。其中一项更改是删除特定于平台的 Extras 模块,以确保 Qt 6 的跨平台故事和未来具有凝聚力。 即Qt6.x版本以后不再维护一些功能模块,其中便删除了QWinTaskbarButton和QWinTaskbarProgress 类。 官方文档:QWinTaskbarButton The QWinTaskbarButton and QWinTaskbarProgress classes have been removed due to warranting a cross-platform solution. See QTBUG-94009 and QTBUG-94008 for details. 在windows和macos兼容性存在问题,以下内容qt6.x版本均已移除。可以寻找第三方API实现。

==覆盖图标和进度指示器== 在我们使用一些软件时,尤其是注重下载或上传功能的程序时,该程序的任务栏图标往往会有下载或上传进度提示,而在Qt5.x版本上也是提供了该功能。主要使用QtWinExtras模块下的QWinTaskbarButton与QWinTaskbarProgress类。可以实现设置任务栏覆盖图标、进度显示功能。 ``` lang = c++ #include #include "ui_QtWidgetsApplication1.h"

#include #include #include

class QtWidgetsApplication1 : public QMainWindow {     Q_OBJECT

public:     QtWidgetsApplication1(QWidget *parent = Q_NULLPTR);

private:     Ui::QtWidgetsApplication1Class ui;

    QTimer *pTimer = nullptr;     QWinTaskbarButton *pWinTaskbarButton = nullptr;     QWinTaskbarProgress *pWinTaskbarProgress = nullptr;

private slots:     void onTimeout();     void startDownload(); };  ```  ``` lang = c++ #include "QtWidgetsApplication1.h"

QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)     : QMainWindow(parent) {     ui.setupUi(this);     connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(startDownload()));

    setWindowIcon(QIcon(":/QtWidgetsApplication1/IPCApp.ico")); }

void QtWidgetsApplication1::onTimeout() {     /* 更新进度 */     pWinTaskbarProgress->setValue(pWinTaskbarProgress->value() + 1);     pWinTaskbarProgress->show();

    if (pWinTaskbarProgress->value() == 100)     {         pTimer->stop();         /* 下载完成重置进度 */         pWinTaskbarProgress->reset();         /* 下载完成清除图标 */         pWinTaskbarButton->clearOverlayIcon();     } }

void QtWidgetsApplication1::startDownload() {     /* 计时器模拟进度 */     pTimer = new QTimer;     pTimer->setInterval(100);     pTimer->setSingleShot(false);     connect(pTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));

    /* 初始化任务栏按钮 */     pWinTaskbarButton = new QWinTaskbarButton(this);     pWinTaskbarButton->setWindow(windowHandle());

    /* 设置覆盖图标 */     pWinTaskbarButton->setOverlayIcon(QIcon(":/QtWidgetsApplication1/E:/test.ico"));     pWinTaskbarButton->setOverlayAccessibleDescription("downloading");

    /* 初始化任务栏进度控件 */     pWinTaskbarProgress = pWinTaskbarButton->progress();     pWinTaskbarProgress->setRange(0, 100);

    /* 开始模拟进度 */     pTimer->start(); }

 ```

==跳转列表== 对于固定在任务栏的图标,右键菜单一般默认有两个选项:程序名称、从任务栏取消固定,对于正在运行的程序多了一个关闭窗口选项: 而对于一些软件,例如邮件、浏览器就会有更多的选项: {F5739376}  ``` lang = c++ QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)     : QMainWindow(parent) {     ui.setupUi(this);     connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(startDownload()));     connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(OpenFile()));

    setWindowIcon(QIcon(":/QtWidgetsApplication1/IPCApp.ico"));

    QWinJumpList jumplist;     QWinJumpListCategory *tasks = jumplist.tasks();

    /* 添加项目创建新程序 */     QWinJumpListItem *newProject = new QWinJumpListItem(QWinJumpListItem::Link);     newProject->setTitle(tr("Create new Project"));     newProject->setIcon(QIcon(":/QtWidgetsApplication1/E:/test.ico"));     newProject->setFilePath(QDir::toNativeSeparators(QCoreApplication::applicationFilePath()));     newProject->setArguments(QStringList("--new-project"));     tasks->addItem(newProject);

    /* 添加连接 打开NotePad++ */     tasks->addLink(tr("Start NotePad++"), "C:\\Program Files (x86)\\Notepad++\\notepad++.exe");

    tasks->setVisible(true); }  ```

四、缩略图工具栏 当鼠标停留在任务栏图标上时,会显示缩略图: 但对于一些媒体播放类程序,会发现在缩略图下方会有一些按钮,此时如果窗口处于最小化状态,就可以帮助用户实现不激活窗口的情况下控制程序,比如常见的上一曲、下一曲、暂停、开始等。 在Qt的QtWinExtras模块下同样提供了一些接口方便我们使用:  ``` lang = c++

QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)     : QMainWindow(parent) {     ui.setupUi(this);     connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(startDownload()));

    setWindowIcon(QIcon(":/QtWidgetsApplication1/IPCApp.ico"));

    tasks->setVisible(true);

    /* 先显示主页面 只有主页面show了之后windowHandle()获取到的才是有效对象 */     this->show();     /* 初始化工具栏 */     QWinThumbnailToolBar *pThumbbar = new QWinThumbnailToolBar(this);     pThumbbar->setWindow(windowHandle());     /* 初始化按钮 */     QWinThumbnailToolButton *pBtnPlay = new QWinThumbnailToolButton(pThumbbar);     pBtnPlay->setToolTip("Play");     pBtnPlay->setIcon(QIcon(":/QtWidgetsApplication1/E:/play.ico"));     connect(pBtnPlay, SIGNAL(clicked()), this, SLOT(play()));

    QWinThumbnailToolButton *pBtnPause = new QWinThumbnailToolButton(pThumbbar);     pBtnPause->setToolTip("Pause");     pBtnPause->setIcon(QIcon(":/QtWidgetsApplication1/E:/test.ico"));     connect(pBtnPause, SIGNAL(clicked()), this, SLOT(pause()));     /* 将按钮添加到工具栏 */     pThumbbar->addButton(pBtnPlay);     pThumbbar->addButton(pBtnPause); }

void QtWidgetsApplication1::play() {     if (pTimer)     {         pTimer->start();     } }

void QtWidgetsApplication1::pause() {     if (pTimer && pTimer->isActive())     {         pTimer->stop();     } }  ```



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3