To apply a subform to a tab control, place a picture box on your form where you want the subform to be on your tab.
Place this code in a bas module:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
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
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Sub 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)
Public Sub OpenSubForm(SubForm As Form, HostHWND As Long)
'***********************************************************************
Dim DispRec As RECT
Dim Style As Long
' Get Display Rectangle dimentions
GetClientRect HostHWND, DispRec
' Load subform
Load SubForm
' Get current window style
Style = GetWindowLong(SubForm.hwnd, GWL_STYLE)
' Append "WS_CHILD" style to the hWnd window style
Style = Style Or WS_CHILD
' Add new style to window
SetWindowLong SubForm.hwnd, GWL_STYLE, Style
' Set host window as parent window
SetParent SubForm.hwnd, HostHWND
' Save the hWnd Parent in hWnd's window struct.
SetWindowLong SubForm.hwnd, GWL_HWNDPARENT, HostHWND
' Save the hWnd Parent in hWnd's window struct.
' Display the subform
SetWindowPos SubForm.hwnd, _
HWND_TOP, 0&, 0&, DispRec.Right, DispRec.Bottom, _
SWP_NOZORDER Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
Finally, create the borderless form as your subform.
Attach your form to the tabbed control calling the opensubform like this:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.