|
|
|
Starting with VB5, the Show method supports a second optional argument, that lets you specify which form owns the form that is about to be displayed: |
A owned form is always displayed in front of its owner, and when the owner is unloaded, VB automatically unloads the owned form as well. The second argument is mostly used only when the form is being displayed not modally, because modal forms are always displayed in front of their owners. The problem with this approach, however, is that it can't work with forms contained in ActiveX DLLs and EXEs, because form references don't work across project boundaries. The answer is the following API function: |
The SetOwner function returns the handle of the previous owner of the window, so you must restore it before exiting. In the following example this function is used with a form included in the current project, but you can easily extend it to work with forms from other applications. The only thing to do is letting the external application have the hWnd of the form in the main application that must become the owner window:
|
Click here to copy the following block | Dim frm As Form2 Dim oldOwner As Long
Private Sub cmdShowForm_Click() Set frm = Form2 frm.Show oldOwner = SetOwner(frm.hwnd, Me.hwnd) End Sub
Private Sub cmdUnloadForm_Click() SetOwner frm.hwnd, oldOwner Unload frm End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|