VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Convert a Child form in a popup Window

by Dino Amoruso (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 10th March 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Convert a Child form in a popup Window

API Declarations


' Aggiungere un controllo picture all'MDIForm e due commandbutton
' Inserire un form standard e impostare la proprietà MDIChild su True
' --- Codice form MDI ---

' Dichiarazioni API per eliminare la voce Successivo dal menu di sistema di un form child
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_CAPTION Or WS_SYSMENU Or WS_THICKFRAME)

Rate Convert a Child form in a popup Window



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


Download this snippet    Add to My Saved Code

Convert a Child form in a popup Window Comments

No comments have been posted about Convert a Child form in a popup Window. Why not be the first to post a comment about Convert a Child form in a popup Window.

Post your comment

Subject:
Message:
0/1000 characters