forked from itay-grudev/SingleApplication
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Primary PID support (itay-grudev#36)
* Added the ability to bring the primary application window to the foreground on Windows systems by adding an option flag. THis option can only be used in Windows development and in applications derived from QApplication with a QMainWindow object. Because the primary application needs to be instructed to go to the foreground, the option SecondaryNotification must also be set to use this functionality * Changed the ability to bring the primary application window to the front as discussed in itay-grudev#31. Now the process ID of the primary application get stored and is accessible for other instances of the application. It is to the developer to bring the applications windows to the front. For convenience the accompanying readme now contains a paragraph with example of how to do this on Windows systems. * v3.0.9 Added SingleApplicationPrivate::primaryPid()
- Loading branch information
1 parent
6fbf6bf
commit 4f03651
Showing
7 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Windows Specific Implementations | ||
================================ | ||
|
||
Setting the foreground window | ||
----------------------------- | ||
|
||
In the `instanceStarted()` example in the `README` we demonstrated how an | ||
application can bring it's primary instance window whenever a second copy | ||
of the application is started. | ||
|
||
On Windows the ability to bring the application windows to the foreground is | ||
restricted, see [`AllowSetForegroundWindow()`][AllowSetForegroundWindow] for more | ||
details. | ||
|
||
The background process (the primary instance) can bring its windows to the | ||
foreground if it is allowed by the current foreground process (the secondary | ||
instance). To bypass this `SingleApplication` must be initialized with the | ||
`allowSecondary` parameter set to `true` and the `options` parameter must | ||
include `Mode::SecondaryNotification`, See `SingleApplication::Mode` for more | ||
details. | ||
|
||
Here is an example: | ||
|
||
```cpp | ||
if( app.isSecondary() ) { | ||
// This API requires LIBS += User32.lib to be added to the project | ||
AllowSetForegroundWindow( DWORD( app.getPrimaryPid() ) ); | ||
} | ||
|
||
if( app.isPrimary() ) { | ||
QObject::connect( | ||
&app, | ||
&SingleApplication::instanceStarted, | ||
this, | ||
&App::instanceStarted | ||
); | ||
} | ||
``` | ||
|
||
```cpp | ||
void App::instanceStarted() { | ||
QApplication::setActiveWindow( [window/widget to set to the foreground] ); | ||
} | ||
``` | ||
|
||
[AllowSetForegroundWindow]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632668.aspx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters