What would be the shortest code to set the state of a Windows 7 taskbar button for a known window handle?
The goal is to write a console utility that changes the progress and state (colour) of the console window taskbar item from a batch script. While the script performs different tasks, the taskbar item of its console window should represent the current state.
I get the window handle with the GetConsoleWindow() function, but then it seems to require loads of COM and Shell API stuff that I don't understand. One example I've found uses a whole GUI application with MFC to demonstrate the API, but most of it is way too complicated for my little tool and I don't understand it well enough to remove the stuff I don't need.
The tool should compile on Windows 7 with VS2010 (C++) but also run on earlier Windows versions (doing nothing if a feature is not available).
Note you still need to call
RegisterWindowMessage("TaskbarButtonCreated")
andChangeWindowMessageFilterEx()
to setup an message filter beforeSetProgressValue()
can work.According to the MSDN docs you are supposed to recreate your object each time you get the created message but I found I just had to do the
ChangeWindowMessageFilterEx()
and it works fine for normal circumstances.I created a class to set the progress in the Win7 taskbar for a project at one time. This is the code I dug up: