Results 1 to 4 of 4

Thread: Getting the handle of the active window

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    8

    Lightbulb Getting the handle of the active window

    How do I get the handle of the window that is currently focused?

  2. #2
    New Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    6
    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

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    I think you need the GetForegroundWindow API...
    VB Code:
    1. Private Declare Function GetForegroundWindow Lib "user32" () As Long
    2. 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
    3. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    4. Private Sub Form_Activate()
    5.  
    6. Dim Ret As Long
    7.  
    8. Do
    9.     'Get the handle of the foreground window
    10.     Ret = GetForegroundWindow()
    11.     'Get the foreground window's device context
    12.     Ret = GetDC(Ret)
    13.     'draw an ellipse
    14.     Ellipse Ret, 0, 0, 200, 200
    15.     DoEvents
    16. Loop
    17.  
    18. End Sub
    That is an example that draws an ellipse on the active window

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    8

    Thumbs up 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
  •  



Click Here to Expand Forum to Full Width