Script to auto tab between 2 differnet screen ever 2 mins

Posted on 2008-11-14
Last Modified: 2012-05-05
Hello I have a single monitor that needs to display 2 different screens at 2 min intervals
screen 1 needs to be maximised and displaying the internet explorer screen for 2 min then minimise or close then screen 2 needs to be maximised and displaying some real time data from a program for 2 mins then minimise or close for 2 mins , this action needs to continually loop ,
Maybe even alt+tab commands could be used to switch between each open screen ever 2 mins

Any help would be appreciated
Question by:transpennine
    LVL 76

    Accepted Solution

    Hi, transpennine.

    Here's how to do this.
    Private lngWnd1 As Long, lngWnd2 As Long, bolWnd1 As Boolean, bolWnd2 As Boolean, intPass As Integer
    Private Sub Command1_Click()
        'Change the window title on the following line to one of the two windows'
        lngWnd1 = FindWindow(vbNullString, "Untitled - Notepad")
        bolWnd1 = True
        'Change the window title on the following line to the other of the two windows'
        lngWnd2 = FindWindow(vbNullString, "Google - Windows Internet Explorer")
        bolWnd2 = False
        Timer1.Interval = 60000
        Timer1.Enabled = True
    End Sub
    Private Sub Command2_Click()
        Timer1.Enabled = False
    End Sub
    Private Sub Timer1_Timer()
        intPass = intPass + 1
        If intPass = 2 Then
            If bolWnd1 Then
                SendMessage lngWnd1, WM_SYSCOMMAND, SC_MAXIMIZE, NIL
                BringWindowToTop lngWnd1
                SendMessage lngWnd2, WM_SYSCOMMAND, SC_MINIMIZE, NIL
                SendMessage lngWnd2, WM_SYSCOMMAND, SC_MAXIMIZE, NIL
                BringWindowToTop lngWnd2
                SendMessage lngWnd1, WM_SYSCOMMAND, SC_MINIMIZE, NIL
            End If
            bolWnd1 = Not bolWnd1
            bolWnd2 = Not bolWnd2
            intPass = 0
        End If
    End Sub
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
    Public Const SC_MAXIMIZE = &HF030&
    Public Const SC_MINIMIZE = &HF020&
    Public Const WM_SYSCOMMAND = &H112
    Public Const NILL = 0&

    Open in new window


    Author Comment

    Thanks Bluedevilfan this code has been most useful and I have managed using it to do what was required thanks for the time taken to help

    Regards Transpennine
    LVL 76

    Expert Comment

    by:David Lee
    You're welcome.  Glad I could help.  Please don't forget to close the question if you're happy with the answer.

    Author Comment

    thanks for all your help sorry for the delay
    LVL 76

    Expert Comment

    by:David Lee
    No problem on the delay.  Please don't forget to close the question if you're satisfied with the solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    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

    12 Experts available now in Live!

    Get 1:1 Help Now