| View previous topic :: View next topic |
| Author |
Message |
kikuvac Master Cheater
Reputation: 0
Joined: 09 Jan 2007 Posts: 320
|
Posted: Fri Aug 15, 2008 6:19 am Post subject: [Help] hWND Active app check |
|
|
hi guys im currently trying to learn anvanced vb and for a project im doing i need to know if i handle a window how can i check if its active.
here is an example of what i need.
Timer1()
somthing to handle the window
if window check = true then MsgBox("Window Active") Else Textbox1.text = "Waiting on window"
end sub
end if
i know there are probably some mistakes in here but i am not on my computer and dont have my compiler with me thanks so much if you help
_________________
Respect for: Coders, Anti Spoon feeders, nice people.
MapleHost |
|
| Back to top |
|
 |
Xt3hb4nd1tX Festering pile of crap
Reputation: 0
Joined: 12 Mar 2007 Posts: 953 Location: Beer Sheva, Israel
|
|
| Back to top |
|
 |
Codeslinger I post too much
Reputation: 1
Joined: 11 Oct 2007 Posts: 3652 Location: Midwest, United States of America
|
Posted: Fri Aug 15, 2008 10:31 pm Post subject: |
|
|
MSDN is your friend
And this is not maple related
And this is not advanced VB
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Aug 16, 2008 5:33 am Post subject: |
|
|
FindWindow / GetForegroundWindow will do what you need.
On Form1, add 1 textbox. Then add 1 module to the project.
Form1 Code
| Code: | Option Explicit
Private Sub Form_Load()
'//
'// Create a timer that loops every 10 miliseconds..
'//
SetTimer Me.hwnd, 0, 10, AddressOf TimerProc
End Sub |
Module1 Code
| Code: | Option Explicit
'// Window API
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
'// Timer API
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Dim hWnd_Notepad As Long
Dim hWnd_Current As Long
hWnd_Notepad = FindWindow("Notepad", vbNullString)
hWnd_Current = GetForegroundWindow()
If (hWnd_Notepad = hWnd_Current) Then
KillTimer Form1.hwnd, 0
Form1.Text1.Text = "Notepad is active!"
Exit Sub
End If
Form1.Text1.Text = "Notepad is not active!"
End Sub |
_________________
- Retired. |
|
| Back to top |
|
 |
|