Solved

Switch focus to minimized app

Posted on 1997-09-30
4
565 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
ID: 1436191
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
ID: 1436192
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
ID: 1436193
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
ID: 1436194
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

20 Experts available now in Live!

Get 1:1 Help Now