Application re-launch, elevated "runas", does not capture TaskbarButtonCreated Msg before ITaskbarList use?

277 Views Asked by At

Using Borland C++ Builder.

Before I use ITaskbarList3, I do as Windows requires:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd391692.aspx

Your application should call RegisterWindowMessage(L"TaskbarButtonCreated") and handle that message in its wndproc. That message must be received by your application before it calls any ITaskbarList3 method.

However this doesn't seem to work always for me, the message I'm waiting for never comes, even though RegisterWindowMessage() was successful.

After some digging I found that the problem is related to when my application relaunches itself with "runas", immediately after starting, when based on user settings, the application needs to run elevated.

The second (now elevated) run, the message I'm waiting for never comes.

I assume this is because Windows has sent this message already and it is not doing it again, even though a new instance is created ??

How safe is it to assume the message must have been sent already on a second (elevated) run, and proceed with using ITaskbarList3 anyway ?

1

There are 1 best solutions below

10
Ruslan Garipov On

Your application code must call ChangeWindowMessageFilterEx function after creating the top window and registering "TaskbarButtonCreated" message. This will allow for the second (elevated) instance to receive "TaskbarButtonCreated" message.

UINT nTaskbarButtonCreatedMessage = RegisterWindowMessage(TEXT("TaskbarButtonCreated"));
HWND hWnd = {create the top main window and get handle to it}.
ChangeWindowMessageFilterEx(hWnd, nTaskbarButtonCreated, MSGFLT_ALLOW, nullptr);

(this is a code for VC++ but I believe it will work for Borland C++ Builder too)