Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect which MDI Child form to close 1

Status
Not open for further replies.

1todd1

Programmer
Jan 19, 2002
17
NZ
I have a set of MDI Child forms that open maxamized inside a MDI form. On the MID form there is a toolbar that says “close” form. I want to be able to click this button on the MDI form and close the open active form (MDI form on top of the other MDI forms with the focus or active). Am not sure how to reference.


I tried to do this with out success

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Dim frm As Form
Dim blnFormOpen
Dim nexts As Long

Const GW_CHILD = 5

'assume form not open
blnFormOpen = False

For Each frm In Forms
' exclude MDIForm
If Not TypeOf frm Is MDIForm Then
' only looking at MDIChild forms
nexts = GetWindow(frm.hwnd, 5)

‘ Am lost about here

'If nexts = Then
MsgBox "top" & frm.Name
End If
End If
Next

Any thoughts or comments would be appreciated thanks

Todd :)
 
from MSDN:

ActiveForm Property


Returns the form that is the active window. If an MDIForm object is active or is referenced, it specifies the active MDI child form.

Syntax

object.ActiveForm

The object placeholder represents an object expression that evaluates to an object in the Applies To list.

Remarks

Use the ActiveForm property to access a form's properties or to invoke its methods — for example, Screen.ActiveForm.MousePointer = 4.

This property is especially useful in a multiple-document interface (MDI) application where a button on a toolbar must initiate an action on a control in an MDI child form. When a user clicks the Copy button on the toolbar, your code can reference the text in the active control on the MDI child form — for example, ActiveForm.ActiveControl.SelText.

When a control on a form has the focus, that form is the active form on the screen (Screen.ActiveForm). In addition, an MDIForm object can contain one child form that is the active form within the context of the MDI parent form (MDIForm.ActiveForm). The ActiveForm on the screen isn't necessarily the same as the ActiveForm in the MDI form, such as when a dialog box is active. For this reason, specify the MDIForm with ActiveForm when there is a chance of a dialog box being the ActiveForm property setting.

Note When an active MDI child form isn't maximized, the title bars of both the parent form and the child form appear active.

If you plan to pass Screen.ActiveForm or MDIForm.ActiveForm to a procedure, you must declare the argument in that procedure with the generic type (As Form) rather than a specific form type (As MyForm) even if ActiveForm always refers to the same type of form.

The ActiveForm property determines the default value for the ProjectTemplate object.

 
Thanks Justin

I've been a VBA programmer and was trying to do something like cycle through the forms collection and then seeing if the form is active

if formName.active = true then

Hehe silly really. Ironically I came across the Activeform statement as soon as I posted this question. Although you hit the nail on the head.

Thanks for your comments Todd


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top