您的位置:首页 > 编程语言 > VB

VB控制子窗体(外部程序)在Picture控件上

2008-11-21 22:01 357 查看
在VB新建一工程,有两个窗体,FORM1,FORM2

FORM1有一个PIC控件和一个按钮控件

代码如下:
Option Explicit

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE = (-16)

Private Const WS_CLIPSIBLINGS = &H4000000

Private Const WS_VISIBLE = &H10000000
Private Sub Command1_Click()

Dim handle As Long, Ret As Long

'获取窗体句柄

handle = Form2.hwnd
' handle =FindWindow(vbNullString, "TheWorld") '示例手工输入外部窗体标题,如记事本

Ret = SetWindowLong(handle, GWL_STYLE, WS_VISIBLE Or WS_CLIPSIBLINGS)

'插入指定的窗体

SetParent handle, Picture1.hwnd

Form2.Move Picture1.ScaleLeft, Picture1.ScaleTop

End Sub

Private Sub Form_Unload(Cancel As Integer)

End

End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐