Results 1 to 3 of 3

Thread: Capture Active Window

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    Does anyone know of a code which specifically captures the active window of the desktop ?

  2. #2
    Guest
    This code will tell you the title of the Active Window.

    Code:
    Private Declare Function GetForegroundWindow _
    Lib "user32" () As Long
    
    Private Declare Function GetWindowTextLength Lib "user32" _
    Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    
    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 GetParent Lib "user32" (ByVal hwnd _
    As Long) As Long
    
    
    Private Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
       Dim i As Long
       Dim j As Long
    
       i = GetForegroundWindow
    
    
       If ReturnParent Then
          Do While i <> 0
             j = i
             i = GetParent(i)
          Loop
    
          i = j
       End If
    
       GetActiveWindowTitle = GetWindowTitle(i)
    End Function
    
    Private Function GetWindowTitle(ByVal hwnd As Long) As String
       Dim l As Long
       Dim s As String
    
       l = GetWindowTextLength(hwnd)
       s = Space(l + 1)
    
       GetWindowText hwnd, s, l + 1
    
       GetWindowTitle = Left$(s, l)
    End Function

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    how abt tis?

    Code:
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_SNAPSHOT = &H2C
    Private Const VK_MENU = &H12
    
    Private Sub Command1_Click()
        'Capture the Active Window
        keybd_event VK_MENU, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, 0, 0
        keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
        keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
    
        'Load Image into the PictureBox
        Picture1.Picture = Clipboard.GetData()
    
        'Save new image file
        SavePicture Picture1, "C:\picture1.bmp"
    End Sub

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