HOW TO

Force a Visual Basic form to stay on top of ArcMap or ArcCatalog

Last Published: January 19, 2021

Summary

Note:
This article pertains to ArcGIS versions 8.x only. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.
Note:
ArcGIS versions 10.5 and later do not include the Microsoft VBA compatibility setup.

Users creating an ActiveX DLL occasionally need to load a Visual Basic form as part of the application. The form, when first displayed, appears in front of the primary application. By default, the Visual Basic form is then repositioned behind ArcMap or ArcCatalog when a user interacts with ArcMap's or ArcCatalog's GUI.

Procedure

Follow the steps below to make sure the Visual Basic form always stays on top of the primary application.

Customize even more by making direct calls to SetWindowPos. For more information on SetWindowPos, visit Microsoft MSDN.

  1. In the Visual Basic ActiveX DLL project, add a new standard module and copy this code into the module.
Code:
Option Explicit 

' WINDOW POSITIONING 
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 

' SetWindowPos Flags 

Public Const SWP_NOSIZE = &H1 
Public Const SWP_NOMOVE = &H2 
Public Const SWP_NOZORDER = &H4 
Public Const SWP_NOREDRAW = &H8 
Public Const SWP_NOACTIVATE = &H10 
Public Const SWP_FRAMECHANGED = &H20 
Public Const SWP_SHOWWINDOW = &H40 
Public Const SWP_HIDEWINDOW = &H80 
Public Const SWP_NOCOPYBITS = &H100 
Public Const SWP_NOOWNERZORDER = &H200 
Public Const SWP_DRAWFRAME = SWP_FRAMECHANGED 
Public Const SWP_NOREPOSITION = SWP_NOOWNERZORDER 
Public Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE 
Public Const HWND_TOP = 0 
Public Const HWND_BOTTOM = 1 
Public Const HWND_TOPMOST = -1 
Public Const HWND_NOTOPMOST = -2 
Public Sub SetWin_NOTOPMOST(hWnd As Long) 
SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS 
End Sub 

Public Sub SetWin_TOPMOST(hWnd As Long) 
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS 
End Sub 

( 
  1. In Form_Load add:
SetWin_TOPMOST Me.hWnd

Article ID:000004399

Software:
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic