Spidey
Spidey

Reputation: 2589

How can I debug a constantly losing focus window (dialog, for instance) in MFC?

I am maintaining I big and mature application, without background on MFC paradigm and layout. I have experience with Qt, OO designs and UI frameworks (I'm aware of each thread responsibility, event loops, event handling hierarchies, etc.

I'm stuck with a settings CDialog window losing focus constantly, while I'm trying to configure my application. I also have a file explorer dialog that behaves exactly the same way. Both are activated by DoModal calls.

I've read that this is probably because I have two modal dialogs competing for focus. How can I debug that? What function could I break on to get a helpful callstack, so I can find the offending code? Is there an MFC::focusWindow(WHND window) or something that I could intercept?

Upvotes: 1

Views: 1562

Answers (3)

Jeff D.
Jeff D.

Reputation: 328

The problem according to your description is that you 'have two modal dialogs competing for focus'. This should normally not be possible because by definition a modal dialog takes over the application and does not return control to its launch point until the dialog is closed. Without knowing the architecture of the application, the simplest solution would be to make the settings dialog modeless (create it then call ShowWindow(SW_SHOW) instead of DoModal. This will allow the message loop to run for the other modal dialog but not take focus from your settings dialog unless it is doing it explicitly in its own methods.

Upvotes: 1

rrirower
rrirower

Reputation: 4590

Use Spy++ to spy the messages/events that occurring in the dialog.

Upvotes: 1

PankajM
PankajM

Reputation: 417

You can use SetFocus function, please refer to http://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx

Upvotes: -1

Related Questions