Foxtable(狐表)用户栏目专家坐堂 → 窗口嵌套


  共有10239人关注过本帖树形打印复制链接

主题:窗口嵌套

帅哥哟,离线,有人找我吗?
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:732 积分:5491 威望:0 精华:14 注册:2011/8/28 12:49:00
  发帖心情 Post By:2012/9/23 1:05:00 [显示全部帖子]

 先上个效果图:

图片点击可在新窗口打开查看此主题相关图片如下:无标题.png
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:untitled.gif
图片点击可在新窗口打开查看

建一个空白的窗口,类型为独立窗口或者模式窗口,往上面各拖一个Button与Panel控件,panel设置一下背景颜色突出显示,并锚定到窗口的上下左右

全局代码:

Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowCallBack, ByVal lParam As Integer) As Integer
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Integer) As Integer
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Long) As Integer
Delegate Function EnumWindowCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOP = 0

Public IntCalcHandle As Integer

Public Function EnumWindowProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
    If IsWindowVisible(hwnd) Then
        Dim StrCaption As String = New String(Chr(0), 255)
        GetWindowText(hwnd, StrCaption, 256)
        StrCaption = StrCaption.Replace(Chr(0), "")
        If StrCaption <> "" Then
            If StrCaption = "计算器" Then
                IntCalcHandle = hwnd
                Return 0
            End If
        End If
    End If
    Return 1
End Function

窗口上的Button1的Click事件代码:

Dim Proc As New Process
Proc.File = "calc.exe"
Proc.Start()
IntCalcHandle = 0
Proc.WaitForInputIdle()
System.Threading.Thread.Sleep(200)
EnumWindows(AddressOf EnumWindowProc, 0)
If IntCalcHandle = 0 Then Return
SetWindowPos(IntCalcHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE)
SetParent(IntCalcHandle, e.Form.Controls("Panel1").BaseControl.Handle.ToInt32)

[此贴子已经被作者于2012-9-23 1:06:48编辑过]

 回到顶部