Discussion:
How to bring window to foreground on Mac OS
leo.zhou
2014-02-20 04:06:52 UTC
Permalink
Hi,
I have an app running in the background and only having an icon on system
status bar. When users plug in certain usb hardware, the main window should
pop up and get user input. I think this behavior is not abrupt and expected
by users. Here's the code.

pMainFrame = new MyFrame;
pMainFrame->Show();
pMainFrame->RequestUserAttention();

void MyFrame::OnActivate(wxActivateEvent& event)
{
if (event.GetActive())
{
wxUIActionSimulator sim;

sim.MouseMove(m_pText->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick(wxMOUSE_BTN_LEFT);

}
}

void MyFrame::OnShow(wxShowEvent& event)
{
if (event.IsShown())
{
wxUIActionSimulator sim;

sim.MouseMove(m_pText->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick(wxMOUSE_BTN_LEFT);
}
}


I use wxSTAY_ON_TOP flag to show the window on top, but it doesn't get
activated automatically, so I cannot set focus on textctrl. Move the code
to wxShowEvent handler doesn't work either. Seems that wxUIActionSimulator
only works when my frame has been activated already. Is there a way to
activate my main frame programmingly on Mac OS? Or any tricky way to do so?
Thanks!

Leo
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Igor Korot
2014-02-20 05:38:20 UTC
Permalink
Hi, leo,
Post by leo.zhou
Hi,
I have an app running in the background and only having an icon on
system status bar. When users plug in certain usb hardware, the main window
should pop up and get user input. I think this behavior is not abrupt and
expected by users. Here's the code.
3 questions:

1, What is your wx version?
2. How did you build wx?
3. How did you build an app: as a bundle or not?

Thank you.
Post by leo.zhou
pMainFrame = new MyFrame;
pMainFrame->Show();
pMainFrame->RequestUserAttention();
void MyFrame::OnActivate(wxActivateEvent& event)
{
if (event.GetActive())
{
wxUIActionSimulator sim;
sim.MouseMove(m_pText->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick(wxMOUSE_BTN_LEFT);
}
}
void MyFrame::OnShow(wxShowEvent& event)
{
if (event.IsShown())
{
wxUIActionSimulator sim;
sim.MouseMove(m_pText->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick(wxMOUSE_BTN_LEFT);
}
}
I use wxSTAY_ON_TOP flag to show the window on top, but it doesn't get
activated automatically, so I cannot set focus on textctrl. Move the code
to wxShowEvent handler doesn't work either. Seems that wxUIActionSimulator
only works when my frame has been activated already. Is there a way to
activate my main frame programmingly on Mac OS? Or any tricky way to do so?
Thanks!
Leo
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
leo.zhou
2014-02-20 07:16:04 UTC
Permalink
Post by leo.zhou
Hi,
I have an app running in the background and only having an icon on
system status bar. When users plug in certain usb hardware, the main window
should pop up and get user input. I think this behavior is not abrupt and
expected by users. Here's the code.
pMainFrame = new MyFrame;
pMainFrame->Show();
pMainFrame->RequestUserAttention();
void MyFrame::OnActivate(wxActivateEvent& event)
{
if (event.GetActive())
{
wxUIActionSimulator sim;
sim.MouseMove(m_pText->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick(wxMOUSE_BTN_LEFT);
}
}
void MyFrame::OnShow(wxShowEvent& event)
{
if (event.IsShown())
{
wxUIActionSimulator sim;
sim.MouseMove(m_pText->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick(wxMOUSE_BTN_LEFT);
}
}
I use wxSTAY_ON_TOP flag to show the window on top, but it doesn't get
activated automatically, so I cannot set focus on textctrl. Move the code
to wxShowEvent handler doesn't work either. Seems that wxUIActionSimulator
only works when my frame has been activated already. Is there a way to
activate my main frame programmingly on Mac OS? Or any tricky way to do so?
Thanks!
Leo
Hi,
1. I use the latest trunk version from github, seems 3.1.0.
2. I build the static library using this options.
../configure -prefix="$(pwd)" --disable-shared --enable-unicode
--with-cocoa --with-macosx-version-min=10.7
--with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
--enable-macosx_arch=x86_64 CXXFLAGS="-std=c++0x -stdlib=libc++"
CPPFLAGS="-stdlib=libc++" LIBS=-lc++
3. I create a self contained bundle after building using makefile. The app
works without any problems on Mac OS. I just want to steal the focus when I
show my main frame. In windows, there is a tricky way to accomplish this.
But on Mac, I have no idea. Thanks!

Leo
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...