以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  窗口嵌套  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=23889)

--  作者:baxiu
--  发布时间:2012/9/22 22:25:00
--  窗口嵌套
 版主,你好,我想实现一个问题,使用狐表做到:

在狐表中引用一个程序,例“扫雷”,如何让此程序在狐表的一个选项卡中操作。

注:此程序为全屏程序。

--  作者:飞
--  发布时间: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编辑过]

--  作者:小猪鑫鑫
--  发布时间:2012/9/23 9:15:00
--  
飞:你真牛,学习收藏!