Add wxProcess::Activate() and implement it for MSW.

When launching child processes it can be convenient to be able to switch to
them later, provide a method in wxProcess to do it.

Currently this is only implemented in wxMSW but could almost certainly be done
for wxOSX too (it can be done using Apple Script, so presumably there is a way
to do it programmatically as well) and could be also made to work at least
under some Unix systems by emulating what wmctrl does (or just launching it?).
This commit is contained in:
Vadim Zeitlin
2015-03-10 20:28:22 +01:00
parent d161a74f67
commit fe33cfc83f
5 changed files with 55 additions and 0 deletions

View File

@@ -69,6 +69,7 @@ All (GUI):
- Add wxAddRemoveCtrl.
- Add wxAppProgressIndicator for MSW (Chaobin Zhang) and OS X (Tobias Taschner).
- Add wxEVT_MAGNIFY mouse event (Joost Nieuwenhuijse).
- Add wxProcess::Activate().
- Make results of wxDC::DrawEllipticArc() consistent across all platforms.
- XRC handler for wxAuiToolBar added (Kinaou Hervé, David Hart).
- Add wxCursor::GetHotSpot().

View File

@@ -77,6 +77,12 @@ public:
// before the process it started terminates
void Detach();
// Activates a GUI process by bringing its (main) window to the front.
//
// Currently only implemented in wxMSW, simply returns false under the
// other platforms.
bool Activate() const;
#if wxUSE_STREAMS
// Pipe handling
wxInputStream *GetInputStream() const { return m_inputStream; }

View File

@@ -80,6 +80,20 @@ public:
*/
virtual ~wxProcess();
/**
Activates a GUI process by bringing up its main window to the front.
This is a convenient method which tries to bring this process to the
users attention.
Currently this is implemented in wxMSW only and simply returns @false
under the other platforms. Notice that this function can also return
@false under MSW if, for example, the process doesn't have any windows.
@since 3.1.0
*/
bool Activate() const;
/**
Closes the output stream (the one connected to the stdin of the child
process).

View File

@@ -176,6 +176,18 @@ bool wxProcess::Exists(int pid)
}
}
bool wxProcess::Activate() const
{
#ifdef __WINDOWS__
// This function is defined in src/msw/utils.cpp.
extern bool wxMSWActivatePID(long pid);
return wxMSWActivatePID(m_pid);
#else
return false;
#endif
}
void wxProcess::SetPriority(unsigned priority)
{
wxCHECK_RET( priority <= wxPRIORITY_MAX,

View File

@@ -795,6 +795,28 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
return 0;
}
// This is used by wxProcess::Activate().
extern
bool wxMSWActivatePID(long pid)
{
wxFindByPidParams params;
params.pid = (DWORD)pid;
if ( ::EnumWindows(wxEnumFindByPidProc, (LPARAM)&params) != 0 )
{
// No windows corresponding to this PID were found.
return false;
}
if ( !::BringWindowToTop(params.hwnd) )
{
wxLogLastError(wxS("BringWindowToTop"));
return false;
}
return true;
}
// By John Skiff
int wxKillAllChildren(long pid, wxSignal sig, wxKillError *krc)
{