English

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

Summary

Users creating an ActiveX DLL will occasionally want to load a Visual Basic form as part of their application. The form, when first displayed, will appear in front of the parent application. By default, the Visual Basic form will then be repositioned behind ArcMap or ArcCatalog when a user interacts with ArcMap's or ArcCatalog's GUI.

Procedure

By following the steps below, the Visual Basic form will always stay on top of the parent application.

You can customize even more by making direct calls to SetWindowPos. For more information on SetWindowPos, visit Microsoft MSDN through the link below.

  1. In your 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

    (

  2. In Form_Load add:

    SetWin_TOPMOST Me.hWnd

Related Information