Reputation: 149
I am using Visual Studio 2015 to update an application. The application was written 15 years ago, and I would like to add a progress bar overlay to the taskbar button, something that Windows 7 now provides. I have followed all the tutorials I can find, such as
http://www.codeproject.com/KB/vista/SevenGoodiesTaskbarStatus.aspx
and
https://www.codeproject.com/Articles/80082/Windows-How-to-display-progress-bar-on-taskbar-i
However they both seem to use outdated namespaces, such as
MESSAGE_HANDLER_EX
which gives me a whole bunch of errors. Does anyone know how to do this?
Upvotes: 3
Views: 3796
Reputation: 124
As already mentioned here, the sample projects you have pointed don't use MFC but WTL, which is an extension of ATL, not currently shipped with Visual Studio. So, to make them compile you have to download WTL, install and got rid of some deprecated stuff.
But of course, the ITaskbarList3 interface can be used in an MFC application, as well. For starting, here is a brief example:
class CMainDialog : public CDialog
{
// ...
CComPtr<ITaskbarList3> m_spTaskbarList;
};
BOOL CMainDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// ...
HRESULT hr = ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
__uuidof(ITaskbarList3), reinterpret_cast<void**>(&m_spTaskbarList));
if(SUCCEDDED(hr))
{
hr = m_spTaskbarList->HrInit();
}
// ...
return TRUE;
}
....and of course, do not forget to call AfxOleInit in application's class InitInstance method.
[ LATER EDIT ]
Sorry, my previous example is wrong! According to documentation, must handle "TaskbarButtonCreated" registered message, to be sure that taskbar button is in place, before calling any ITaskbarList3 method.
UINT WM_TASKBAR_BUTTON_CREATED = ::RegisterWindowMessage(_T("TaskbarButtonCreated"));
BEGIN_MESSAGE_MAP(CMainDialog, CDialogEx)
// ...
ON_REGISTERED_MESSAGE(WM_TASKBAR_BUTTON_CREATED, OnTaskbarButtonCreated)
END_MESSAGE_MAP()
LRESULT CMainDialog::OnTaskbarButtonCreated(WPARAM wParam, LPARAM lParam)
{
HRESULT hr = ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
IID_ITaskbarList3, reinterpret_cast<void**>(&m_spTaskbarList));
if (FAILED(hr))
{
// handle error
return 0;
}
hr = m_spTaskbarList->HrInit();
// ....
// ... other taskbar list stuff.
return 0;
}
See also this article: Windows 7: Adding toolbar buttons to taskbar button flyout.
Upvotes: 4
Reputation: 6566
The MESSAGE_HANDLER_EX
macro is a part of WTL. It is defined in atlcrack.h
.
Most likely you need to get the latest WTL in order to compile the project in Visual Studio 2015.
As ISun already mentioned the task bar progress can be implemented based on API described in this MSDN article: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#progress
There is a nice wrapper for ITaskbarList3
interface: https://www.codeproject.com/Articles/42345/Windows-Goodies-in-C-Taskbar-Progress-and-Status
Upvotes: 2