Window, focus and activation problem

58 views
Skip to first unread message

QuentinC

unread,
Feb 26, 2021, 10:02:48 AM2/26/21
to wx-u...@googlegroups.com
Hello,

I'm sorry, the subject line is maybe not very clear.

I have a dialog box in which I have a wxWebView with IE backend.
I'm trying to determine when the web view takes the focus for the first
time in order to do something specific at that moment, but I don't
manage to do it correctly.

As long as the user has the focus on the application frame when the
dialog box is opened, everything is fine.
I can whether bind to wxEVT_INIT_DIALOG on the dialog box,
wxEVT_ACTIVATE on the dialog, or wxEVT_SET_FOCUS on the wxWebView, the
event is dispatched and I can do what I want.

However, it doesn't work as I wish if the dialog box is opened while I'm
doing something else in another application.
wxEVT_ACTIVATE on the dialog box and wxEVT_SET_FOCUS are both triggered
even if I'm on another application, and this isn't the right moment. IN
that case, I would like something to be triggered only when I come back
to my application with Alt+Tab or click somewhere inside the dialog box.

So far, I have observed that:
1. wxEVT_ACTIVATE is triggered immediately when the dialog box is shown,
even if the focus is another application. e.GetActive() returns true,
which is incorrect from my point of view. I can't count on this event.
2. wxEVT_SET_FOCUS is also triggered immediately when the dialog box is
open, even if I'm another application, too. So it doesn't work either
for me.
3. More strange: wxEVT_ACTIVATE is **NOT** triggered the first time I
come back to the dialog box with Alt+Tab. After this first time, it
works correctly for the next times, i.e. e.GetActive() returns false
when leaving the dialog box, and true when going back to it again.

I tried a few alternatives to achieve what I want, with no more luck:
1. IsShown() and IsShownOnScreen() both return true, both for the
webview and the dialog box itself, even if I'm in another application. I
don't well understand why but bad luck.
2. ? I tried to find a function which would return a wxWindow* given
screen coordinates, but didn't find anything. I would have tried to use
such a function to determine if really my dialog box is fully visible.
If it has the focus but isn't fully visible, it means that in fact it
hasn't the focus and hance it isn't the right moment to trigger my
action. Trying the four corners of the dialog box like this may help me,
at least I guess so, if there isn't anything simpler.


Is there something I haven't correctly understood with focus and
activation events ?
Do you have a suggestion on how I can achieve what I want ?

Note that
I'm under windows 10, compiling with MinGW-W64. Currently using
WXWidgets 3.1.4. I can give the constructor of my dialog box if needed.
IT is shown with ShowModal().

Thank you for your answers.


Vadim Zeitlin

unread,
Feb 28, 2021, 5:07:59 PM2/28/21
to wx-u...@googlegroups.com
On Fri, 26 Feb 2021 16:02:39 +0100 QuentinC wrote:

Q> However, it doesn't work as I wish if the dialog box is opened while I'm
Q> doing something else in another application.

FWIW I'd try to avoid opening a dialog box non-interactively in the first
place. People usually don't like when dialogs pop up on their own.

Q> wxEVT_ACTIVATE on the dialog box and wxEVT_SET_FOCUS are both triggered
Q> even if I'm on another application, and this isn't the right moment. IN
Q> that case, I would like something to be triggered only when I come back
Q> to my application with Alt+Tab or click somewhere inside the dialog box.

You might be able to use wxEVT_ACTIVATE_APP to detect this.

Q> So far, I have observed that:
Q> 1. wxEVT_ACTIVATE is triggered immediately when the dialog box is shown,
Q> even if the focus is another application. e.GetActive() returns true,
Q> which is incorrect from my point of view. I can't count on this event.

I admit I'm surprised by this too but, without debugging it, I'd guess
it's MSW itself which sends WM_ACTIVATE and so there is probably not much
we can do about it.

Q> 3. More strange: wxEVT_ACTIVATE is **NOT** triggered the first time I
Q> come back to the dialog box with Alt+Tab.

I think this is a consequence of (1) above, if it's already active, it's
not going to become active again.

Q> I tried a few alternatives to achieve what I want, with no more luck:
Q> 1. IsShown() and IsShownOnScreen() both return true, both for the
Q> webview and the dialog box itself, even if I'm in another application. I
Q> don't well understand why but bad luck.

These functions just check that the window is not hidden. They don't check
if it's not obstructed by other windows.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Reply all
Reply to author
Forward
0 new messages