PDA

Click to See Complete Forum and Search --> : Modifying form behavior in a multi-form app


stevemelaaron
Oct 22nd, 2001, 11:08 AM
I have a multi-form (non-MDI) app that I'm developing. When the user activates one of the forms in the app by clicking on it, all of the other forms in my app come to the top of the z-order. Is there any way to change this behavior? I would like to make it so that only the form that has been clicked comes to the foreground. I have tried to make an ActiveX .EXE with the thread per instance option out of the form that I'm creating multiple instances of, and this does create the effect that I'm looking for, but after creating 10 or 15 instances of the form, VB issues an "Out of memory" error.

Any ideas?

--Steve
stevemelaaron@msn.com

Hack
Oct 22nd, 2001, 01:18 PM
When your users click on a specific form, do you want that form to be the topmost window? If so, then try this:Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
On Error Goto ErrRtn
If (Topmost) Then
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
SetTopMostWindow = False
End If
Exit Function
ErrRtn:
MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel
End FunctionThen, in your forms putPrivate Sub Form_GotFocus()
SetTopMostWindow Me.hwnd, True
End Sub
Private Sub Form_LostFocus()
SetTopMostWindow Me.hwnd, False
End SubI hope I'm properly understanding your question.