Return focus to prev app

Posted on 2006-05-23
Last Modified: 2010-05-01

the app i'm developing runs as an overlay (prints some text on the screen)

now when the user presses ctrl + alt + o they can edit the options.
whenever this options screen closes, focus should not be set to the text displayed on screen, but to the app that had focus before the options screen was opened.

how can i reach this goal?

Question by:Mark_FreeSoftware
    LVL 29

    Accepted Solution

    Private Declare Sub SwitchToThisWindow Lib "user32" ( _
        ByVal hwnd As Long, _
        ByVal fAltTab As Boolean)

    Private Sub Command1_Click()
        SwitchToThisWindow Me.hwnd, False
    End Sub
    LVL 13

    Author Comment


    that's one piece (the switching)

    but how can i know what app had focus before mine?


    i am doing somthing in word,
    than i decide i want to change somthing and i open the options screen.
    i close it, and word doesnt get focus
    however when i just close my app, word is getting focus
    LVL 13

    Author Comment


    thanks for your help this far,

    i'm going to reward you points for trying to help me

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    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…

    779 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

    13 Experts available now in Live!

    Get 1:1 Help Now