|
-
Aug 20th, 2001, 02:40 PM
#1
Thread Starter
New Member
Getting the handle of the active window
How do I get the handle of the window that is currently focused?
-
Aug 20th, 2001, 02:52 PM
#2
New Member
Use the API call GetForegroundWindow()
This returns the handle of the window that currently has focus. First you need to paste this into your code so you have access to the call:
Public Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Then you can call this without any parameters. The return value is a long
-
Aug 20th, 2001, 02:55 PM
#3
PowerPoster
I think you need the GetForegroundWindow API...
VB Code:
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Activate()
Dim Ret As Long
Do
'Get the handle of the foreground window
Ret = GetForegroundWindow()
'Get the foreground window's device context
Ret = GetDC(Ret)
'draw an ellipse
Ellipse Ret, 0, 0, 200, 200
DoEvents
Loop
End Sub
That is an example that draws an ellipse on the active window
-
Aug 20th, 2001, 03:01 PM
#4
Thread Starter
New Member
Thanks
Thanks that did the trick.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|