0

We developed a console application which uses ITaskbarList3::SetProgressValue() method that works fine when that application is invoked within cmd.exe but it doesn't show any progress when invoked within Conemu console. No error messages happens anywhere either. The HWND passed as parameter of ITaskbarList3::SetProgressValue() is get like this:

HWND hwnd = GetConsoleWindow();

I have no code to show because I don't know an alternative method to do this or what might be issue. I thought the returned HWND could be conemu's rather my application's so I called GetWindowText() function to check if the window's text was other than my console application but it was a string in same format as cmd's.

Jack
  • 16,276
  • 55
  • 159
  • 284
  • Are you sure you are using the same `HWND` that is actually displayed on the Taskbar? You can't just use any `HWND` you want. And you certainly do not own the console window. You might need to have your console app display its own popup GUI window for progress, then set the Taskbar progress for THAT window – Remy Lebeau Oct 17 '17 at 21:55
  • How do I make sure I''m using same HWND that is displayed on the TaskBar? any Windows tool for that? it does works on cmd.exe the issue is on Conemu. Maybe when using Conemu it return the conemu's handle instead of my application's? – Jack Oct 17 '17 at 22:03
  • Windows knows nothing about Conemu. `GetConsoleWindow()` returns the `HWND` of Windows' own console window, not Conemu's window. Conemu does its work by hooking into the Windows console system, but it doesn't completely replace that system. For what you are attempting to do, you likely need Conemu's `HWND`. Try using `FindWindow()` or `EnumWindows()` to find it. – Remy Lebeau Oct 17 '17 at 22:23
  • @RemyLebeau Thanks for elucidate! I was thinking `GetConsoleWindow()` would return the HWND of the current console in used, the one that invoked the application, in that case, ConEmu. – Jack Oct 18 '17 at 03:56

1 Answers1

1

When you run console application in ConEmu the GetConsoleWindow() returns virtual console HWND rather than native conhost HWND. However both sent suitable for SetProgressValue() because virtual console is a child window of ConEmu (which is shown on the TaskBar) and conhost HWND is not even visible.

Just get parent of the GetConsoleWindow() before calling SetProgressValue().

Maximus
  • 10,751
  • 8
  • 47
  • 65
  • According to title got from `GetWindowText()`, it seems that the HWND is suitable for `SetProgressValue()` but for some reason it doesn't work with ConEmu. On other hand, the window title got from HWND returned by `GetParent()` is empty... what am I missing? – Jack Oct 18 '17 at 03:50
  • Why do you think that title is a proper mark of suitability? It is not sufficient. – Maximus Oct 18 '17 at 07:21
  • Run Spy from Visual Studio to check window. You shall use "root level" window which is shown on the TaskBar. – Maximus Oct 18 '17 at 07:23
  • Thanks! `GetAncestor(GetConsoleWindow(), GA_ROOT)` did it – Jack Oct 18 '17 at 16:19