Multiple Forms Problem

andrem
09-16-2003, 04:02 AM
Hi,

This must have been discussed before, but I couldn't find anything with the Search. I have MP2002 Control on a form. Whenever I show 2 modeless instances of the form, the focus/zorder goes funny - clicking on one form brings the other forward. This does not happen when I remove the OCXes, so it must be a control code bug? Here's my code: (Click on Cammand1 twice to open two instances of Form2 (with MapPoint OCX). Then try to click any of the instances. see what I mean? HELP!

Form1:
Option Explicit

Private Sub Command1_Click()
Dim frm As Form2

Set frm = New Form2

frm.Show vbModeless

End Sub

Form2:
Option Explicit

Private Sub Form_Initialize()

MapViewer.NewMap geoMapEurope

End Sub

Ninjas
09-16-2003, 04:04 PM
http://www.avdf.com/multimedia/samp_modeless.html

andrem
09-17-2003, 01:56 AM
Thanks Ninjas, but I know what a modeless dialog is. In this case I have a normal modeless forms. Replace the MapPoint control with a textbox, click the button twice, and it works fine. Add back mappoint ctl and do the same - the form that loses focus jumps to the top.

Martel
09-24-2003, 06:52 PM
I noticed that the problem does not exist if you use an MDIForm and your Mappoint control in the child forms. However, you can imitate this somewhat using the following code. Be forwarned that whatever window is last activated will stay on top of all other applications as well as other windows in your current application!


Create a module:

Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long


Public Declare Function SetWindowPos Lib "user32" _
(ByVal iWinHandle As Long, _
ByVal hWinInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal uFlags As Long) As Long

CONST TOPMOST = -1
CONST NOMOVE = &H2
CONST NOSIZE = &H1
CONST NOCHANGE = NOMOVE OR NOSIZE

Public Sub SetFormOnTop(frmHandle as long)
Call SetWindowPos(frmHandle, -1, 0, 0, 0, 0, NOCHANGE)
End Sub



On your form (I think you used Form2 in your example, but you will need it on ANY form that you want to have focus while your application is running) :

Private Sub Form_Activate()
'Debug.Print Me.Caption & " activated " & Me.hWnd
Call SetFormOnTop(Me.hWnd)
End Sub

 
Web mp2kmag.com
mapforums.com