如何在C++生成器中创建 ITaskbarList3
How can I create an ITaskbarList3 in C++ Builder?
我正在尝试使用Windows 7引入的ITaskbarList3界面,以便我可以在任务栏图标中显示冗长任务的任务进度。 文档指出,在尝试初始化我的 ITaskbarList3 组件之前,我应该等待 TaskbarButtonCreated 消息,但我似乎没有收到任何 TaskbarButtonCreated 消息。
这是我到目前为止所拥有的:
我的.cpp文件中有一个全局变量来存储任务栏按钮创建的自定义消息ID。
static const UINT m_uTaskbarBtnCreatedMsg =
RegisterWindowMessage( _T("TaskbarButtonCreated") );
我创建了一个单独的 WndProc 函数来处理新消息。
void __fastcall TForm1::WndProcExt(TMessage &Message)
{
if(Message.Msg == uTaskbarBtnCreatedMsg && uTaskbarBtnCreatedMsg != 0) {
OnTaskbarBtnCreated();
}
else {
WndProc(Message);
}
}
在我的窗体构造函数中,第一行将 WindowProc 属性设置为 WndProcExt 以路由消息。 我还尝试在ChangeWindowMessageFilter中折腾,以查看TaskbarButtonCreated消息是否由于某种原因而被过滤。
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
WindowProc = WndProcExt;
ChangeWindowMessageFilterEx(Handle, uTaskbarBtnCreatedMsg, MSGFLT_ALLOW, NULL);
...
}
在调试器中,来自 ChangeWindowMessageFilterEx 的返回值始终为 true。 我还确认我的WndProcExt函数接收各种Windows消息,只是不是我要找的那个。 OnTaskbarBtnCreated 函数永远不会被调用。
我错过了一步吗? 消息是否在我的消息处理程序准备就绪之前被筛选掉或发送?
让 TForm 为其自己的 WindowProc
属性分配值不是一个好主意。 对于初学者来说,由于 DFM 流,Handle
窗口可能在进入构造函数之前就已经分配了,因此在构造函数开始运行之前,您将错过窗口的所有初始消息(可能有几个)。 您需要重写虚拟WndProc()
方法,并将 TaskbarButtonCreated 消息传递给默认处理程序,不要阻止它:
static const UINT m_uTaskbarBtnCreatedMsg = RegisterWindowMessage( _T("TaskbarButtonCreated") );
void __fastcall TForm1::WndProc(TMessage &Message)
{
TForm::WndProc(Message);
if ((Message.Msg == uTaskbarBtnCreatedMsg) && (uTaskbarBtnCreatedMsg != 0))
OnTaskbarBtnCreated();
}
至于ChangeWindowMessageFilterEx()
,您需要在每次 TForm 的Handle
窗口被(重新)分配时调用它(在表单的生命周期中可能会发生多次),因此您需要重写虚拟CreateWnd()
方法:
void __fastcall TForm1::CreateWnd()
{
TForm::CreateWnd();
if (CheckWin32Version(6, 1) && (uTaskbarBtnCreatedMsg != 0))
ChangeWindowMessageFilterEx(Handle, uTaskbarBtnCreatedMsg, MSGFLT_ALLOW, NULL);
// any other Handle-specific registrations, etc...
}
void __fastcall TForm1::DestroyWindowHandle()
{
// any Handle-specific de-registrations, etc...
TForm::DestroyWindowHandle();
}
最后,在创建MainForm
之前,将项目的WinMain()
函数中的 TApplication::ShowMainFormOnTaskbar
属性设置为true
,以便其窗口(而不是TApplication
窗口)管理任务栏按钮(并启用其他与 Vista+ 相关的功能,如翻转 3D 和任务栏预览)。 否则,您将不得不使用 TApplication::HookMainWindow()
方法来拦截可能发送到TApplication
窗口的任何"任务栏按钮创建"消息。
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 试图在visual studio上用C++创建一个桌面应用程序
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 如何在C++20中创建模板别名的推导指南
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 链接到自行创建的dll失败
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++类内存结构中创建"spacer"?
- 终端不会为C++文件创建.exe文件吗
- 如何在C++生成器中创建 ITaskbarList3