Script to auto tab between 2 differnet screen ever 2 mins

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
transpennineAsked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
Hi, transpennine.

Here's how to do this.
'FORM CODE'
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
        Else
            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
 
'MODULE CODE'
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

0
 
transpennineAuthor Commented:
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
0
 
David LeeCommented:
You're welcome.  Glad I could help.  Please don't forget to close the question if you're happy with the answer.
0
 
transpennineAuthor Commented:
thanks for all your help sorry for the delay
0
 
David LeeCommented:
No problem on the delay.  Please don't forget to close the question if you're satisfied with the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.