怎么通过已知句柄,取得VB中正在运行的窗体的实体对象

如何通过已知句柄,取得VB中正在运行的窗体的实体对象
谁能用VB代码实现以下内容:
把正在VB中运行的其他程序(外部程序)的某窗体,通过取到的句柄,取得这个窗体的实例化对象,并对其进行对象操作(主要是取得控件容器对象)。对象可以转化成VB.FORM类型的,或者是VBIDE.VBFORM类型的都行。

即set form1 = <根据已取得句柄的窗体转化成的实例对象>。然后使用form1.属性(或方法)进行各种操作。

------解决方案--------------------
楼主肯定是用过VC哈哈~~觉得强制转换非常爽吧~~
你说的那个基本上不可能~~一个对象要经过初始化等一系列工作非常复杂
用个方法你倒是可以一用但是也不能保证成功你需要定位到对象
你把目标窗体进程拷贝到你的进程空间然后自己定位
用CreateRemoteThread启动什么的或者SetThreadContext
------解决方案--------------------
VC中的CWnd类,其实里面也是封装了一些窗体API函数
你可以自己在VB中建立一个CWnd类,里面也自己封装几个窗体常用属性就得了!

下面给你提供个例子

VB.NET code

'Class CWnd
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As WNDMSG, ByVal wParam As Long, lParam As Any) As Long
Private Enum WNDMSG
    WM_GETICON = &H7F
    WM_SETICON = &H80
End Enum

Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Boolean) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function IsWindowEnabled Lib "user32" (ByVal hWnd As Long) As Boolean
Private Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long, ByVal fEnable As Boolean) As Boolean

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 SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long

Private m_hWnd As Long

Property Get Caption() As String
    Dim szBuffer As String * 255
    Call GetWindowText(m_hWnd, szBuffer, 255)
    Caption = Left$(szBuffer, InStr(szBuffer, vbNullChar) - 1)
End Property

Property Let Caption(ByVal szTitle As String)
    If szTitle <> Caption Then
        Call SetWindowText(m_hWnd, szTitle)
    End If
End Property

Property Get Enabled() As Boolean
    Enabled = IsWindowEnabled(m_hWnd)
End Property

Property Let Enabled(ByVal blnEnable As Boolean)
    Call EnableWindow(m_hWnd, blnEnable)
End Property

Property Get hWnd() As Long
    hWnd = m_hWnd
End Property

Property Let hWnd(ByVal NewWnd As Long)
    m_hWnd = NewWnd
End Property

Property Get Icon() As Long
    'Big Icon
    'Icon = SendMessage(m_hWnd, WM_GETICON, 1, ByVal 0&)
    Icon = SendMessage(m_hWnd, WM_GETICON, 0, ByVal 0&)
End Property

Property Let Icon(ByVal hIcon As Long)
    'Big Icon
    'Call SendMessage(m_hWnd, WM_SETICON, 1, ByVal hIcon)
    Call SendMessage(m_hWnd, WM_SETICON, 0, ByVal hIcon)
End Property

Property Get Left() As Long
    Dim Rc As RECT
    Call GetWindowRect(m_hWnd, Rc)
    Left = Rc.Left
End Property

Property Let Left(ByVal nLeft As Long)
    Dim Rc As RECT
    Call GetWindowRect(m_hWnd, Rc)
    Call MoveWindow(m_hWnd, nLeft, Rc.Top, Rc.Right - Rc.Left, Rc.Bottom - Rc.Top, True)
End Property

Property Get ScaleWidth() As Long
    Dim Rc As RECT
    Call GetClientRect(m_hWnd, Rc)
    ScaleWidth = Rc.Right - Rc.Left
End Property

Property Get Top() As Long
    Dim Rc As RECT
    Call GetWindowRect(m_hWnd, Rc)
    Left = Rc.Top
End Property

Property Let Top(ByVal nTop As Long)
    Dim Rc As RECT
    Call GetWindowRect(m_hWnd, Rc)
    Call MoveWindow(m_hWnd, Rc.Left, nTop, Rc.Right - Rc.Left, Rc.Bottom - Rc.Top, True)
End Property

------解决方案--------------------
有些糊涂.

现在还没有想明白.

IE里面,可以实现根据句柄获取对象~~

看这个显示网页密码的代码: