AppActivate problem in Windows 7
I am testing an application developed using VB6 on a computer with Windows 7. That application uses AppActivate in order to activate MS Excel so the user can select a cell and then go back to my application. The problem is with Windows 7, because AppActivate keeps Excel flashing in the task bar and the expected behavior was that the Excel main window became the top window with the focus on it. The same code works as expected with Windows XP.
Does anybody know if there is a workaround for Windows 7?
Thank you in advance for your help.
Re: AppActivate problem in Windows 7
You may need to use SetForegroundWindow api:
Sample 1
Sample 2
Re: AppActivate problem in Windows 7
Quote:
Originally Posted by
RhinoBull
Thank you for your suggestions.. but no luck :(, both approaches work well on XP but neither of them on W7.
Sample1 - ForceForegroundWindow on W7 simply does nothing
Sample2 - What I get after executing RestoreWindow is a flashing window in the task bar, exactly the same behavior than AppActivate
Re: AppActivate problem in Windows 7
This one:
http://vb.mvps.org/samples/ForceFore/
Works for me on Windows7 Profession 32-bit - it is by the same author in the first link (PDF), but maybe he updated it on his website? I didn't compare the code.
If it doesn't work for you - what version of Windows 7 are you using?
Re: AppActivate problem in Windows 7
Quote:
Originally Posted by
jpbro
This one:
http://vb.mvps.org/samples/ForceFore/
Works for me on Windows7 Profession 32-bit - it is by the same author in the first link (PDF), but maybe he updated it on his website? I didn't compare the code.
If it doesn't work for you - what version of Windows 7 are you using?
Yes, that sample application works for me too.
Then the problem may be my app, because I copied the same code and the result is the flashing window in the task bar.
This extrange behaviour happens with W7 64-bit.
I'll review my code for 64-bit.
Re: AppActivate problem in Windows 7
Question: Why do you need to select a cell in the first place? Depending upon your needs, you could acess the cell's value using Excel Automation and end up with something like...
Text.Text = oCell.Value 'etc where oCell is instanciated with code.
Re: AppActivate problem in Windows 7
Quote:
Originally Posted by
RobDog888
Question: Why do you need to select a cell in the first place? Depending upon your needs, you could acess the cell's value using Excel Automation and end up with something like...
Text.Text = oCell.Value 'etc where oCell is instanciated with code.
Because first the user selects an element data in my app, then my app activates Excel and the user picks a cell where he wants to copy the data. The "selection changed" event causes the data being copied, and my app is activated again, allowing the user to select another data, and so on.
Re: AppActivate problem in Windows 7
Ok then perhaps it might be easier to do it all in VBA so you can use an Excel UserForm? Then there wont be any back and forth focus issues but this depends upon your source app.
If you are just doing SetForegroundWindow you may need to check first if your window is minimized (IsIconic) first. If it is then restore the window and THEN set it with SetForegroundWindow.
Re: AppActivate problem in Windows 7
Thanks for the info RobDog888
I am trying several approaches, focused in W7 64-bit
If I find a sucessfull solution I'll tell you in this thread