?
Solved

Switch focus to minimized app

Posted on 1997-09-30
4
Medium Priority
?
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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