Reputation: 32922
I created child process from console application
CreateProcess(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, &in, &out);
Where
command
is the command line for the application I run pvw32 img.jpg
(pictView to show some image).in
is a STARTUPINFO struct (I tried STARTF_USESHOWWINDOW flag but tough luck, pictView steals focus by some of it's processess)I tried to give the pictView some time and then kindly take the focus back
Sleep(1000);
SwitchToThisWindow(hwnd,TRUE);
I got the focus (the cursor is blinking again in my console), but the icon in the task bar flashes several times and the input is not allowed until I hit Alt+Tab.
I also tried to set the z-order, to launch the pictView minimized, even to suspend it, but he just doesn't want to give up easily. The only way how to get the focus back is to kill the pictView.
Is there any way how to get the focus back without bothering the user with Alt+Tab?
Note: there was no focus-stealing problem with simpView, but I'd like to stay with pictView for performance reasons.
Upvotes: 4
Views: 679
Reputation: 32922
As Remy Lebeau points out, SetForegroundWindow() outlines the requirements for setting a foreground to the foreground. pictView played dirty, so I used dirty tricks too:
LockSetForegroundWindow(LSFW_LOCK);
executed from the console application prevented pictView to steal its focus. Everything run smoothly now.
Upvotes: 5