Step 1 声明如下说明 Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Step 2 在主窗体上放置Frame控件(fraContainer), 以放置堆叠页面的容器 Step 3 建立函数InitializePage Private Sub InitializePage(frmPage As Form, hWndParent As Long) Dim dwStyle As Long
SetParent frmPage.hwnd, hWndParent End Sub Step 4 建立需要切换的页面Form1 和 Form2, 修改为无边框,并将相应的起始属性(StartUpPosition)改为Manual,Left Top 均为0 Step 5 建立页初始化函数 Public Sub InitializePages() Set frm1 = New Form1 Set frm2 = New Form2
InitializePage frm1, frmMain.fraContainer.hwnd InitializePage frm2, frmMain.fraContainer.hwnd End Sub Step 6 建立全局变量frmActive 保存当前活动的页面 Step 7 建立切换页面切换函数 Public Sub ChangePage(frmChange as Form) If frmChange Is Nothing Then Exit Sub
If Not frmActive Is Nothing Then If frmActive.hWnd <> frmChange.hWnd Then frmActive.Hide frmChange.Show 0, Me Set frmActive = frmChange End If Else frmChange.Show 0, Me Set frmActive = frmChange End If End Sub