Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

c++ - How can I prevent a window from being deactivated?

Is there any way to prevent a window from being deactivated? The window is in a different process then mine.

This is for Windows.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Doing this can be dangerous, but the solution is to handle the WM_ACTIVATE message and check if the wParam is WA_INACTIVE. This means the window has been deactivated. When this happens, you can just reactivate it.

In order to do this for another process's window, you will need to install a message hook with SetWindowsHookEx.

However, it is possible that another application could do the same thing, putting each other in an endless loop of activation/deactivation.

This is also something that should never be done by software that is meant to run on a personal computer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...