MapPoint control does not allow bringing other VB form to foreground



When a MapPoint ActiveX control is placed on a VB6 windows form, other non modal forms that you open cannot be brought to foreground.

Note :

1. The issue has also been reported with Delphi forms.

2. This issue DOES NOT occur with .Net windows forms.



Consider you have VB6 Standard EXE project which shows MapPoint ActiveX control. The form has a button to show other non-modal forms. Now with MapPoint control being shown on one form, when you show other non-modal forms, these appear in the background. Even if you switch to the non-modal form, and try to bring it foreground by dragging it, the form again goes back to background.




This is an issue with MapPoint ActiveX control when placed on a VB6 form.




Use win32 API SetWindowPos after calling show method of VB6 form.


Sample VB6 code to work around this issue:


Private Sub FixedShowNonModalForm()

SetWindowPos NonModalForm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
SetWindowPos NonModalForm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

End Sub


Make sure you have added following declarations to your form code:


Private Declare Function CoAllowSetForegroundWindow Lib "ole32.dll" (ByVal pUnk As Object, ByVal lpvReserved As Long) As Long
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 HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1