Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a better kludge for SetForegroundWindow?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00671245
Message ID:
00671939
Views:
15
Mike,

In my comment I wanted to say that this behavior of SetForegroundWindow is "by design" and attempts to evade this behaviour may be not a good idea.
There are two reasons why SetForegroundWindow may fail:
1. The foreground is locked (as in case of explorer.exe). Calls to SetForegroundWindow are disabled by calling the LockSetForegroundWindow. Probably application has some reasons for it.
2. The timeout since last user input hasn't expired. It means that user is interacting with application and switching to another application may be undesirable. For example, your code will work with notepad.exe till user is not interacting with it.
BTW, your code works on WindowsXP.

Alexander

>Oh yes, I read the instructions, but here's a corollary to Cahn's Axiom: the more you read, the less you understand. Meanwhile, I doubt you'd find any mention of the ShowWindow MINIMIZE/RESTORE approach anywhere in Microsoft's documentation. Do you know if SystemParametersInfo actually works in the context I described, and what specific changes are required to demonstrate this technique in my sample VFP program?
>
>The documentation for SetForegroundWindow lists a number of conditions, any one of which should permit its use. Reading what they say about SystemParametersInfo, the implication appears to be that this is a global setting that should be changed upon installing my application, with a warning to the user. Maybe the SPI_SETFOREGROUNDLOCKTIMEOUT setting could briefly be changed and then restored. But the seeming catch-22 that "the SystemParametersInfo call fails unless the calling thread can change the foreground window" does not inspire confidence in this approach.
>
>Since I had doubts about the feasibility of using SystemParametersInfo, I investigated (briefly) the use of the AllowSetForegroundWindow function and the LockSetForegroundWindow function with the LSFW_UNLOCK option. These functions did not make any difference, and they gave no indication that the problem has anything to do with the SPI_SETFOREGROUNDLOCKTIMEOUT setting, so I haven't pursued SystemParametersInfo further. Since none of this mumbo-jumbo is comprehensible or consistent with the "documentation" of SetForegroundWindow, I decided to search for an answer on Google Groups.
>
>I was amazed at the number of postings about similar problems people have had with the new and "improved" SetForegroundWindow, solutions that don't work, and more possible remedies that might work. I have posted a clear, concise description of an approach the definitely does work. Now I'm tired of experimenting with other "possible" solutions, so I'm asking if anyone can demonstrate a better alternative that they know for a fact does work. Thanks for your suggestion, and I may investigate this approach further if I have the time. With luck, someone who already knows the answer may save us the time of further research and testing.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform