VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Get foreground window using GetForegroundWindow API. Very useful to develop security programs and

by Karthikeyan (187 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 23rd January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

'Get foreground window using GetForegroundWindow API. Very useful to develop security programs and system logger programs

API Declarations


Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long


Rate 'Get foreground window using GetForegroundWindow API. Very useful to develop security programs and



'http://www.geocities.com/marskarthik
'http://marskarthik.virtualave.net
'Email: [email protected]
Private Sub Form_Load()
'Set window on top
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 1
End Sub
' Display the title bar text of the foreground window.
Private Sub Timer1_Timer()
Dim hwnd As Long
Dim length As Long
Dim wntxt As String
Dim rval As Long
hwnd = GetForegroundWindow() 'Get the foreground window
length = GetWindowTextLength(hwnd) + 1
wntxt = Space(length)
rval = GetWindowText(hwnd, wntxt, length) 'Get title bar text
wntxt = Left(wntxt, length - 1)
Label1.Caption = wntxt
End Sub

Download this snippet    Add to My Saved Code

'Get foreground window using GetForegroundWindow API. Very useful to develop security programs and Comments

No comments have been posted about 'Get foreground window using GetForegroundWindow API. Very useful to develop security programs and . Why not be the first to post a comment about 'Get foreground window using GetForegroundWindow API. Very useful to develop security programs and .

Post your comment

Subject:
Message:
0/1000 characters