[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

Switch focus to minimized app

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
jwkeller
Asked:
jwkeller
  • 3
1 Solution
 
ChizlCommented:
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
 
ChizlCommented:
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
 
y96andhaCommented:
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
 
ChizlCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now