0
votes

We have an MFC MDI app that during the process of operation can set the focus on a given control, e.g. it might change the active tab if the result of the operation is more appropriate for a different tab.

If the app has focus when the SetFocus occurs this is fine, tab changes and the correct control has focus. However, if the app does not have focus (ie the user has clicked on another app while waiting for the operation to finish) the SetFocus on the child window causes an OnActivate to occur in the parent MDI frame and the app becomes the foreground window.

How do we SetFocus to a child window without the whole app from becoming the foreground window if the user is working in another app.

1
Well, strange, shouldn't happen. Is anybody messing with AttachThreadInput()?Hans Passant
Not that I'm aware of but this is MFC, and there's a hell of lot going on in the background.snowdude
I have never seen this happen in years of MFC programming. You should post the code that you use to set the focus. Are you calling this from the GUI thread or from another thread? Are you calling this from an event handler of any Windows message? Does it also happen if you set the focus in a WM_TIMER event? What operating system are you using? On Windows 10 it is not allowed anymore to bring an application programmatically into foreground while the user is working with another application. A workaround would be not to set the focus while the app is not in foreground.Elmue
I have had a similar problem with a C# tab control. When changing the selected tab programmatically the entire dialog came to the front stealing the focus from the currently active window. Maybe this helps: stackoverflow.com/questions/4044711/…Elmue

1 Answers

0
votes

Did you try to change focus using CDialog::GotoDlgCtrl ?