Rubrik: Oberfläche · Fenster | VB-Versionen: VB4, VB5, VB6 | 02.11.05 |
Ein beliebiges Fenster zum ChildForm machen Ein bisschen API - und schon lässt sich jedes Fenster zur Laufzeit zum Childformular eines MDI-Formulars machen. | ||
Autor: Dieter Otter | Bewertung: | Views: 13.704 |
www.tools4vb.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Der nachfolgende Tipp zeigt, wie man aus einem beliebigen Form/Fenster zur Laufzeit ein Child-Formular machen kann, das dann direkt innerhalb des MDI-Formulars angezeigt wird.
' benötigte API-Deklarationen 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 Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" ( _ ByVal hwnd As Long, _ ByVal nIndex As Long) As Long Private Declare Function GetParent Lib "user32" _ Alias "GetParent" ( _ ByVal hwnd As Long) As Long Private Const WS_EX_MDICHILD = &H40& Private Const WS_EX_WINDOWEDGE = &H100& Private Const GWL_EXSTYLE = (-20) Private nOldStyle As Long Private nOldParent As Long
' beliebiges Fenster als Child-Form im MDI-Formular anzeigen Public Sub MakeChild(ByVal hWndChild As Long, ByVal hWndMDI As Long) ' zunächst den Original-Fensterstil und Parent merken nOldStyle = GetWindowLong(hWndChild, GWL_EXSTYLE) nOldParent = GetParent(hWndChild) ' jetzt das Fenster zum ChildForm der MDIForm machen SetParent hWndChild, hWndMDI SetWindowLong hWndChild, GWL_EXSTYLE, WS_EX_MDICHILD Or WS_EX_WINDOWEDGE End Sub
Wann immer Sie die Anwendung beenden, sollten Sie das "gekidnappte" Fenster wieder seinem ursprünglichem Eltern-Fenster zurückgeben
SetWindowLong hWndChild, GWL_EXSTYLE, nOldStyle SetParent hWndChild, nOldParent