Solved

Switch focus to minimized app

Posted on 1997-09-30
4
564 Views
Last Modified: 2008-03-17
I wish to switch focus to - and "restore" - a minimized application using a selection from the bar menu of the calling appplication. The "tried and true" methods suggested by MSKB and others: AppActivate "foobar" : sendkeys "% R"
when called by a control on the form work great. The problem is, when called from the bar menu, the popup window for "foobar" is displayed with "restore" higlighted and then everything locks up for from 1 to 30 seconds. When things unlock and "foobar" restores, the MousePointer may or may not be "busy".

Calling App:
        FileMenu_click
        AppActivate "foobar"
        sendkeys "% R"
        end sub

Foobar: Form1_click
        end
        end sub

I have also tried moving all the logic to "foobar" by having the calling app always shell a new app, and having "foobar" check for a previous instance. This produces the same results.
0
Comment
Question by:jwkeller
  • 3
4 Comments
 
LVL 4

Expert Comment

by:Chizl
Comment Utility
I would look into API call SetForegroundWindow instead of AppActivate..   What exacly is "Alt+space+R" supposed to do? Not restore I hope..  sendkeys does nothing, but stuff the keyboard..  When I say stuff the keyboard that means if you hold the Alt+spacebar+R it should do exacly the same thing..  As you can see that doesn't work..

L8r,
Chizl
www.karland.com
0
 
LVL 4

Expert Comment

by:Chizl
Comment Utility
I would look into API call SetForegroundWindow instead of AppActivate..   What exacly is "Alt+space+R" supposed to do? Not restore I hope..  sendkeys does nothing, but stuff the keyboard..  When I say stuff the keyboard that means if you hold the Alt+spacebar+R it should do exacly the same thing..  As you can see that doesn't work..

L8r,
Chizl
www.karland.com
0
 
LVL 5

Expert Comment

by:y96andha
Comment Utility
Alt+SPACE R maybe works in the US version, but in my localized version, the combination is Alt+SPACE Å, so it's not a very good way to do it. I would use
  ShowWindow hwnd, SW_RESTORE
where hwnd is a handle for the window in question.
0
 
LVL 4

Accepted Solution

by:
Chizl earned 100 total points
Comment Utility
You will need to use findwindow to get a handle on the window your looking for..  Then use SetForegroundWindow to set focus on that window.   Then use what andha suggested of ShowWindow..

Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

Declare Function SetForegroundWindow Lib "user32" _
    Alias "SetForegroundWindow" _
   (ByVal hwnd As Long) As Long

Declare Function ShowWindow Lib "user32" _
    Alias "ShowWindow" (ByVal hwnd As Long, _
    ByVal nCmdShow As Long) As Long

You should be on your way..   API calls are always better than the functions built within..  API calls know the operating system not like the fuction calls..

l8r,
Chizl
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now