VB 6.0 - Moving multiple forms so that all forms have the same position

Asked By Kathy Lori on 02-Apr-12 10:23 AM
I'm pretty close on this one, but still have one issue.  I put the code in a zip file.  Basically, I bring up form 1.  Form1 defaults to center screen.  I move form1 from the center spot and hit the bring up form 2 button.  When I do that, I want form 2 to be on top of form 1 ( form2 also defaults to center screen).  Since I'm trapping the WM_NCLBUTTONDOWN event, if I click on the title bar for form 2, form 1 will move under it and I can move both of them.  But I want form 2 to start out on top of form 1.  That's where I'm stuck.  I hope that putting it up in a zip file makes it easier than just listing the code ( that's my hope at least ).  It's just a vb6 project with 2 very simple forms and one bas module.  Any help is very much appreciated.  Thanks.

Kathy Lori

[)ia6l0 iii replied to Kathy Lori on 02-Apr-12 11:01 AM
Do you have a TopMost property for a form?
Kathy Lori replied to [)ia6l0 iii on 02-Apr-12 11:23 AM
Nope.  Nobody is using a topmost property.  Basically, these windows are like a deck of cards.  Each new one pops on top of the others.  The display that this app runs on is constrained wrt size, so it couldn't allow for users to drag or resize.  But, we can now run this app on a pc, so we can make the whole deck of cards moveable.
[)ia6l0 iii replied to Kathy Lori on 02-Apr-12 12:20 PM
Okay. Looking at the SetWindowPos function, maybe this should work. 

Declare the SetWindowPos function. 
Declare Sub 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)

Add these constants.
Global Const HWND_TOPMOST = -1
Global Const SWP_NOMOVE = 2
Global Const SWP_NOSIZE = 1

Call this code snippet in your other function.
SetWindowPos frm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS

Hope this helps.
Kathy Lori replied to [)ia6l0 iii on 02-Apr-12 01:19 PM
Where exactly should I be calling the SetWindowPos function?
[)ia6l0 iii replied to Kathy Lori on 02-Apr-12 09:07 PM
I would have done this on Form Load, but in your case I guess Form's Activate event is the right place.

Private Sub Form_Activate()
End Sub
Kathy Lori replied to [)ia6l0 iii on 04-Apr-12 08:53 AM
Thanks.  That did the trick.
[)ia6l0 iii replied to Kathy Lori on 04-Apr-12 09:58 AM
Glad to help!