Christoph Meißner
Christoph Meißner

Reputation: 1622

How to let the parent window of a child window (a.k.a. owned window) stay active with winapi?

I am writing a small C application using winapi. There I've got a window with a child window (toolbox). I am able to keep it inside this window and so on, but my question is: How to keep the main window active, if the child window gets focused?

The main window gets grayed out in this moment.

The windows get created by:

hMainWindow = DialogBoxParam(.......);
hChildWindow = CreateDialogParam(..., hMainWindow, ...); 
ShowWindow (hChildWindow, SW_SHOW);

Here a little image of the behaviour of the two windows:

The behaviour of the windows

Upvotes: 3

Views: 1148

Answers (3)

Christoph Meißner
Christoph Meißner

Reputation: 1622

I've found out that simply creating it as WS_CHILD and explicitly NOT as WS_POPUP solves that. It also turns the absolute window coordinates to relative ones so that I dont have to care about the window position anymore by moving the parent window.

// Solved

Upvotes: 3

Adrian McCarthy
Adrian McCarthy

Reputation: 47954

Sorry, that's just the way Windows works: one active window at a time.

You can see this in Visual Studio if you bring up Find and Replace as a tool window, you'll see that it gets activated and the main VS window goes inactive.

Trying to have them both active at the same time could confuse users and accessibility tools like screen readers.

Upvotes: 1

Mike Kwan
Mike Kwan

Reputation: 24447

Create the child window as a modeless dialog box instead of a modal one. So instead of using DialogBox, use CreateDialog

Upvotes: 1

Related Questions