user9543846
user9543846

Reputation:

Combine two windows so that they have single input focus?

Is it possible to combine two windows (Forms) so that they have single input focus, and one form don't become inactive when switching to another form? Focus here (and only here) is an Active or Foreground state of Win API, not the cursor.

Upvotes: 0

Views: 2638

Answers (2)

Drake Wu
Drake Wu

Reputation: 7170

According to the Active Window Document:

An active window is the top-level window of the application with which the user is currently working. To allow the user to easily identify the active window, the system places it at the top of the z-order and changes the color of its title bar and border to the system-defined active window colors. Only a top-level window can be an active window. When the user is working with a child window, the system activates the top-level parent window associated with the child window.

Only one top-level window in the system is active at a time.

The MDI windows also has only one active window.

To create a window like MDI(which will show header color of both as active), you could try to add the WS_CHILD style to the child window.

If you also want to realize that one thread shares its input state with another thread, you can try AttachThreadInput.

Upvotes: 0

SilverWarior
SilverWarior

Reputation: 8331

The answer is no! You can't have focus on multiple windows at the same time - that's the way how Windows is designed.

There are still some ways for your application(s) to react to input (keyboard, mouse...) even if your application does not have focus.

If you only need to react to a keystroke you can register a global hotkey with your application and then handle what happens when that specific hotkey is pressed, even when your application is not active.

But if you need to react to every keyboard or mouse input then you will have to register system-wide hooks accordingly. The main advantage of hooks is that you will be able to detect keyboard and mouse events even before the active application does and thus, if needed, also intercept them entirely so that other applications won't receive them at all/anymore.

But beware that when implementing hooks incorrectly you could cause havoc to the computer since you are working on a low level approach that could even lead to system crashes if not done correctly.

Upvotes: 1

Related Questions