Option Explicit'新建两个窗体、一个按钮、一个图片框。 '// Window attribute functions Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long '// Z-order and placement APIs Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long 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 Long) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long'// Focus and activation functions Private Declare Function winSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long Private Declare Function winGetFocus Lib "user32" Alias "GetFocus" () As LongPrivate Const GWL_STYLE = (-16) Private Const WS_CHILD = &H40000000' SetWindowPos Flags Private Const SWP_NOSIZE = &H1 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOZORDER = &H4 Private Const SWP_NOREDRAW = &H8 Private Const SWP_NOACTIVATE = &H10 Private Const SWP_FRAMECHANGED = &H20 Private Const SWP_SHOWWINDOW = &H40 Private Const SWP_HIDEWINDOW = &H80 Private Const SWP_NOCOPYBITS = &H100 Private Const SWP_NOOWNERZORDER = &H200Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER' SetWindowPos() hwndInsertAfter values Private Const HWND_TOP = 0 Private Const HWND_BOTTOM = 1 Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2Private Sub Command1_Click() Dim hWndPage As Long Dim hForm As VB.Form Dim hWndBin As Long Dim dwStyle As Long Set hForm = New Form2 Load hForm hWndPage = hForm.hwnd hWndBin = Picture1.hwnd dwStyle = GetWindowLong(hWndPage, GWL_STYLE) dwStyle = dwStyle Or WS_CHILD Call SetWindowLong(hWndPage, GWL_STYLE, dwStyle) Call SetParent(hWndPage, hWndBin) Call SetWindowPos(hWndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE) hForm.Visible = True End Sub================================================================ 我是一个兵,来自老百姓。
建议不要用MDI窗体,麻烦S了
MainForm.SetFocus
'// Window attribute functions
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'// Z-order and placement APIs
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
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 Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long'// Focus and activation functions
Private Declare Function winSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Private Declare Function winGetFocus Lib "user32" Alias "GetFocus" () As LongPrivate Const GWL_STYLE = (-16)
Private Const WS_CHILD = &H40000000' SetWindowPos Flags
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOOWNERZORDER = &H200Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER' SetWindowPos() hwndInsertAfter values
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2Private Sub Command1_Click()
Dim hWndPage As Long
Dim hForm As VB.Form
Dim hWndBin As Long
Dim dwStyle As Long
Set hForm = New Form2
Load hForm
hWndPage = hForm.hwnd
hWndBin = Picture1.hwnd
dwStyle = GetWindowLong(hWndPage, GWL_STYLE)
dwStyle = dwStyle Or WS_CHILD
Call SetWindowLong(hWndPage, GWL_STYLE, dwStyle)
Call SetParent(hWndPage, hWndBin)
Call SetWindowPos(hWndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE)
hForm.Visible = True
End Sub================================================================
我是一个兵,来自老百姓。