Hi my previous answer - must be still being moderated - can be ignored.
Basically windows 7, 8 and 10 have changed the behaviour of windows popping up. So now in lots of applications you´ll see the window flashing in the taskbar and the user has to click on it (that is if he sees it and doesn´t call you to say the app is hanging).
SetActive... Setforeground.. etc windows apis: I´ve tried them all, it doesn´t work, unless you get in "deep and start to attach and or hook processes, something that I don´t want to. Too complicated and not recommended).
The problem of not having control, since the window you just opened (flashing in taskbar or behind your app), is a modal one. You only get control back in your script by closing it. That I tried to get around with a small oleautomated app, kept blowing up. Then I tried to use a Timer() event, fired just before the blocking window being popped up/behind. Neither worked, the apis fail to do the job. (Same code works on a powerbuilder test window I open, so not a matter of incorrect api declarations or calls).
The problem with the API functions, is that for an app to be able to bring a window to front, it has to be done by the a window that at that time, is the foreground window itself, Microsoft explains it better, but now I understand why it didn´t work, not even when using oleautomation, timers, etc.
Please check this link: SetForegroundWindow function (Windows)
Let me describe my problem and solution: might help someone
- we use outlook OLE and MAPI to send mail (smtp not allowed due to security rules)
1- With MAPI we have the problem that (pb 12.6) the application freezes after sending an email, then logging off, closing the mailsession, closing the application and then trying to run the application again. This happens running the EXE we make, from Powerbuilder GUI, eventually Outlook does close, but also .. it takes too long. (there seem to be lots of differences in OLE using exe or not in PB12.6)
2- with OLE, we have the problem of our AddressList that we try to .Display(), staying behind the application or flashing in the taskbar.
So, since the mapi does bring the addresslist to the front without flashing or staying behind our app, I use MAPI only to display the addresslist. (in the case of MAPI the Display is done using a function called "mailAddress()"), for the rest I use OLEobjects of outlook. It works for all versions of Outlook except for 64 bit versions of MS-Office since MAPI seems to be 32bit only.
HTH,
MiguelL