Attribute VB_Name = "mWindow"
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Global KeyFile As String
Global screenfile As String
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Public Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal hStretchMode As Long) As Long
Public Const STRETCHMODE = vbPaletteModeNone
Public Type POINTAPI
        x As Long
        y As Long
End Type

Public Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Public Const SW_NORMAL = 1
Public Const SW_OTHERZOOM = 2
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Public Const WM_CLOSE = &H10


Public Function GetWindows(ByVal hwnd As Long, ByVal lParam As Boolean) As Long
    Dim lTextBuf As Long
    Dim clsName As Long
    Dim strName As String * 256
    Dim clsWnd As String * 256
    Dim IsWndVis As Boolean
    Dim iPlace As Integer
    Dim sPlacement As String
    Dim PID As Long
    Dim sBuff As Long
    Dim iIcon As Integer
    
    IsWndVis = IsWindowVisible(hwnd)
    
    If IsWndVis = lParam Then
        lTextBuf = GetWindowText(hwnd, strName, 256)
            If lTextBuf Then
                iPlace = GetWindowState(strName)

            
            sBuff = Len(PID)
            PID = GetWindowThreadProcessId(hwnd, sBuff)
       
    Frmain.Text1.Text = Frmain.Text1.Text & "##" & strName  ' & hwnd & "##"
        Frmain.Text1.Text = Frmain.Text1.Text & "///" & hwnd
    
    End If
End If
    
    GetWindows = 1
End Function

Public Function CloseWindow(hwnd As String, Focus As String)
Dim WndVar As Long

WndVar = FindWindow(vbNullString, hwnd)

Call SendMessage(WndVar, Focus, 0, 0)
End Function

Public Function SetWindow(lWnd As String, sFocus As Long)
Dim WNDPLACE As WINDOWPLACEMENT, hwnd As Long

hwnd = FindWindow(vbNullString, lWnd)

With WNDPLACE
    .Length = Len(WNDPLACE)
    .showCmd = sFocus
End With
    
Call SetWindowPlacement(hwnd, WNDPLACE)

End Function

Public Function GetWindowState(lWnd As String) As Integer
Dim WNDPLACE As WINDOWPLACEMENT, hWndPlace As Long, hwnd As Long

hwnd = FindWindow(vbNullString, lWnd)

hWndPlace = GetWindowPlacement(hwnd, WNDPLACE)

GetWindowState = WNDPLACE.showCmd
End Function
Public Function GetCaption(WindowHandle As Long) As String
On Error Resume Next
Dim buffer As String, TextLength As Long
TextLength& = GetWindowTextLength(WindowHandle&)
buffer$ = String(TextLength&, 0&)
Call GetWindowText(WindowHandle&, buffer$, TextLength& + 1)
GetCaption$ = buffer$
End Function

