Vartana
asked on
VB.net How to normalize other minimized applications ( I enumerate all open windows)
How to normalize other minimized applications ( I enumerate all open windows)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SendKeys.Send("%{TAB}") how do i say which window or number to goto ?
Hello Vartana,
Let us say you have 8 windows open, and the 1rst is your own program, the code to normalize all windows is in this case:
(Here you return to your own window):
-------------------------- ---------- ---------- ----------
Dim n As Integer
Dim tabs As String
For n = 2 To 9
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")") '>>> In this case the command is: SendKeys.Send("%({tab}{tab }{tab}{tab }{tab}{tab }{tab}{tab }{tab})")
-------------------------- ---------- ---------- ----------
NOTE: Let n=2 !! Since our own program is always window 1, you can better start off with n=2. The 9 means: 9-8=1 You return to window 1.
>> IF you want to go to window 2:
-------------------------- ---------- ---------- ----------
Dim n As Integer
Dim tabs As String
For n = 2 To 2
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")")
-------------------------- ---------- ---------- ----------
This means you execute the ALT-TAB commando once.
>> AND if you want to go to window 6:
-------------------------- ---------- ---------- ----------
Dim n As Integer
Dim tabs As String
For n = 2 To 6
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")")
-------------------------- ---------- ---------- ----------
But if you want to go to window 6, also this code works:
>> AND if you want to go to window 6:
-------------------------- ---------- ---------- ----------
Dim n As Integer
Dim tabs As String
For n = 2 To 14
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")")
-------------------------- ---------- ---------- ----------
Since: 14-8=6
Let us say you have 8 windows open, and the 1rst is your own program, the code to normalize all windows is in this case:
(Here you return to your own window):
--------------------------
Dim n As Integer
Dim tabs As String
For n = 2 To 9
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")") '>>> In this case the command is: SendKeys.Send("%({tab}{tab
--------------------------
NOTE: Let n=2 !! Since our own program is always window 1, you can better start off with n=2. The 9 means: 9-8=1 You return to window 1.
>> IF you want to go to window 2:
--------------------------
Dim n As Integer
Dim tabs As String
For n = 2 To 2
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")")
--------------------------
This means you execute the ALT-TAB commando once.
>> AND if you want to go to window 6:
--------------------------
Dim n As Integer
Dim tabs As String
For n = 2 To 6
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")")
--------------------------
But if you want to go to window 6, also this code works:
>> AND if you want to go to window 6:
--------------------------
Dim n As Integer
Dim tabs As String
For n = 2 To 14
tabs = tabs & "{tab}"
Next
SendKeys.Send("%(" & tabs & ")")
--------------------------
Since: 14-8=6
btw, use this page if u wanna know more about keystrokes and how they work:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformssendkeysclasstopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformssendkeysclasstopic.asp
Btw.: you might need you app to wait in between the keystrokes. This is because the keystroke need some time to execute. Use this module like this:
wait(300) 'wait 300 msec
So you code would be:
--------------------------
Dim n as integer
for n=1 to Number_of_Windows
SendKeys.Send("%{TAB}")
Wait(300)
Next
--------------------------
The module you have to add to your project:
--------------------------
Module mWait
Private Declare Function CreateWaitableTimer Lib "kernel32" Alias "CreateWaitableTimerA" (ByVal lpSemaphoreAttributes As Integer, ByVal bManualReset As Integer, ByVal lpName As String) As Integer
Private Declare Function OpenWaitableTimer Lib "kernel32" Alias "OpenWaitableTimerA" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal lpName As String) As Integer
'UPGRADE_WARNING: Structure FILETIME may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.2003/co
Private Declare Function SetWaitableTimer Lib "kernel32" (ByVal hTimer As Integer, ByRef lpDueTime As FILETIME, ByVal lPeriod As Integer, ByVal pfnCompletionRoutine As Integer, ByVal lpArgToCompletionRoutine As Integer, ByVal fResume As Integer) As Integer
Private Declare Function CancelWaitableTimer Lib "kernel32" (ByVal hTimer As Integer) As Object
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Integer, ByVal dwMilliseconds As Integer) As Integer
Private Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As Integer, ByRef pHandles As Integer, ByVal fWaitAll As Integer, ByVal dwMilliseconds As Integer, ByVal dwWakeMask As Integer) As Integer
' Wait Module code
Private Structure FILETIME
Dim dwLowDateTime As Integer
Dim dwHighDateTime As Integer
End Structure
Private Const WAIT_ABANDONED As Integer = &H80
Private Const WAIT_ABANDONED_0 As Integer = &H80
Private Const WAIT_FAILED As Integer = -1
Private Const WAIT_IO_COMPLETION As Integer = &HC0
Private Const WAIT_OBJECT_0 As Integer = 0
Private Const WAIT_OBJECT_1 As Integer = 1
Private Const WAIT_TIMEOUT As Integer = &H102
Private Const INFINITE As Short = &HFFFFS
Private Const ERROR_ALREADY_EXISTS As Short = 183
Private Const QS_HOTKEY As Integer = &H80S
Private Const QS_KEY As Integer = &H1S
Private Const QS_MOUSEBUTTON As Integer = &H4S
Private Const QS_MOUSEMOVE As Integer = &H2S
Private Const QS_PAINT As Integer = &H20S
Private Const QS_POSTMESSAGE As Integer = &H8S
Private Const QS_SENDMESSAGE As Integer = &H40S
Private Const QS_TIMER As Integer = &H10S
Private Const QS_MOUSE As Integer = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT As Integer = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS As Integer = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY)
Private Const QS_ALLINPUT As Integer = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY)
Public Sub Wait(ByRef lNumberOfSeconds As Integer)
Dim ft As FILETIME
Dim lBusy As Integer
Dim lRet As Integer
Dim dblDelay As Double
Dim dblDelayLow As Double
Dim dblUnits As Double
Dim hTimer As Integer
hTimer = CreateWaitableTimer(0, True, VB6.GetExeName() & "Timer")
If Err.LastDllError = ERROR_ALREADY_EXISTS Then
' If the timer already exists, it does not hurt to open it
' as long as the person who is trying to open it has the
' proper access rights.
Else
ft.dwLowDateTime = -1
ft.dwHighDateTime = -1
lRet = SetWaitableTimer(hTimer, ft, 0, 0, 0, 0)
End If
' Convert the Units to nanoseconds.
dblUnits = CDbl(&H10000) * CDbl(&H10000)
dblDelay = CDbl(lNumberOfSeconds) * 1000 * 10 '3 Nulletjes weggehaald voor het aantal 1000dersten seconden
' By setting the high/low time to a negative number, it tells
' the Wait (in SetWaitableTimer) to use an offset time as
' opposed to a hardcoded time. If it were positive, it would
' try to convert the value to GMT.
ft.dwHighDateTime = -CInt(dblDelay / dblUnits) - 1
dblDelayLow = -dblUnits * (dblDelay / dblUnits - Fix(dblDelay / dblUnits))
If dblDelayLow < CDbl(&H80000000) Then
' &H80000000 is MAX_LONG, so you are just making sure
' that you don't overflow when you try to stick it into
' the FILETIME structure.
dblDelayLow = dblUnits + dblDelayLow
End If
ft.dwLowDateTime = CInt(dblDelayLow)
lRet = SetWaitableTimer(hTimer, ft, 0, 0, 0, False)
Do
' QS_ALLINPUT means that MsgWaitForMultipleObjects will
' return every time the thread in which it is running gets
' a message. If you wanted to handle messages in here you could,
' but by calling Doevents you are letting DefWindowProc
' do its normal windows message handling---Like DDE, etc.
lBusy = MsgWaitForMultipleObjects(
System.Windows.Forms.Appli
Loop Until lBusy = WAIT_OBJECT_0
' Close the handles when you are done with them.
CloseHandle(hTimer)
End Sub
End Module
--------------------------