Pergunta

I am making an taskbar and I need to know when the active window is changed. I don't want to use a timer. I'm thinking that maybe there is a WndProc message I can intercept.

I'm using C#

Foi útil?

Solução

That requires a hook set by SetWindowsHookEx, WH_SHELL. The callback gets notifications like HSHELL_WINDOWACTIVATED and HSHELL_WINDOWCREATED so that you can know what's happening with the top-level windows. Check out the SDK article for "ShellProc" for the full list of notifications you can get. Just about all of them are relevant to implementing your own taskbar.

That was the good news. The bad news is that WH_SHELL is a global hook. It requires a DLL that can be injected into another process. Problem is, you can't write that DLL in managed code. Injecting managed code into an unmanaged process is not possible.

Back to good news again, somebody has solved that problem and has created an unmanaged DLL that is injectable and can interop with managed code. The project is here. No idea how good it is. I suspect it might not be quite UAC proof.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top