Convert a Child Form


‘Declaration

Private Declare Function GetMenuItemInfo Lib “user32” Alias “GetMenuItemInfoA” (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Long, lpmii As MENUITEMINFO) As Long
Private Declare Function GetMenuItemCount Lib “user32” (ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib “user32” (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib “user32” (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
‘ Menu flags
Private Const MF_BYPOSITION As Long = &H400
Private Const MF_REMOVE As Long = &H1000
Private Const MIIM_ID As Long = &H2
Private Const MIIM_TYPE As Long = &H10
Private Const MFT_STRING As Long = &H0
‘ Menu structure
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
‘ Dichiarazioni API per la conversione di un form Child in una window popup
Private Declare Function SetParent Lib “user32” (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SetFocus Lib “user32” (ByVal hwnd 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
‘ Flag opzione stile di SetWindowLong
Private Const GWL_STYLE = (-16)
‘ Attributi SetWindowLong per impostare una window popup
Private Const WS_OVERLAPPED = &H0&
Private Const WS_THICKFRAME = &H40000
Private Const WS_SYSMENU = &H80000
Private Const WS_CAPTION = &HC00000 ‘ WS_BORDER Or WS_DLGFRAME
Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTIO Or WS_SYSMENU Or WS_THICKFRAME)

Form
Private Sub Command1_Click()
Dim i As Integer
Dim hMenu As Long, iTop As Long
Dim mInfo As MENUITEMINFO

‘ Attiva lo stato del form child e disattiva il form parent MDI
SetFocus formHwnd
‘ Elimina il riferimento al form parent MDI
SetParent formHwnd, 0&
‘ Sostituisce il bit WS_OVERLAPPEDWINDOW dagli attributi del form
SetWindowLong formHwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW
‘ Preleva l’handle del menu di sistema del form
hMenu = GetSystemMenu(formHwnd, 0)
‘ Preleva il numero totale di voci presenti nel menu di sistema
iTop = GetMenuItemCount(hMenu)
‘ Iterazione per eliminare Successivo e il separatore
For i = iTop To (iTop – 2) Step -1
With mInfo
.cbSize = Len(mInfo)
.fMask = MIIM_TYPE Or MIIM_ID
.fType = MFT_STRING
.dwTypeData = Space$(256)
.cch = Len(mInfo.dwTypeData)
End With
If GetMenuItemInfo(hMenu, i, True, mInfo) = 1 Then
‘ Rimozione della voce corrente
Call RemoveMenu(hMenu, i, MF_REMOVE Or MF_BYPOSITION)
End If
Next i
Form1.Show
End Sub

Private Sub Command2_Click()
‘ Visualizzazione come child form
Form1.Show
End Sub

2 responses to “Convert a Child Form

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s