Skip to content

Tools - Window Utility Class ​

cToolsWindow - Window Operation Tools ​

Overview ​

Provides window topmost, window switching, forced focus acquisition, and other functionality.

Methods ​

TopMost ​

Sets window to topmost/remove topmost.

vb
Public Sub TopMost(ByVal hWnd As Long, Optional Cancel As Boolean)

Parameters:

ParameterTypeDescription
hWndLongWindow handle
CancelBooleanWhether to cancel topmost (default False)

Example:

vb
' Set to topmost
VBMAN.ToolsWindow.TopMost Me.hWnd

' Remove topmost
VBMAN.ToolsWindow.TopMost Me.hWnd, True

SwitchToThis ​

Switches to specified window (simulates Alt+Tab effect).

vb
Public Sub SwitchToThis(ByVal hWnd As Long, Optional IsAltTab As Boolean = True)

Example:

vb
' Switch to current window
VBMAN.ToolsWindow.SwitchToThis Me.hWnd

ActiveForm ​

Forcibly sets window as foreground window (bypasses system restrictions).

vb
Public Sub ActiveForm(ByVal hWnd As Long)

Description:

This method bypasses Windows restrictions on SetForegroundWindow by simulating Alt key press. It is recommended to call in Form_LostFocus event to achieve the effect of window never losing focus.

Example:

vb
Private Sub Form_LostFocus()
    ' Force acquire focus
    VBMAN.ToolsWindow.ActiveForm Me.hWnd
End Sub

Complete Example ​

vb
Private Sub Form_Load()
    ' Window topmost
    VBMAN.ToolsWindow.TopMost Me.hWnd
    
    ' Switch to this window
    VBMAN.ToolsWindow.SwitchToThis Me.hWnd
End Sub

Private Sub cmdToggleTopmost_Click()
    Static IsTopmost As Boolean
    IsTopmost = Not IsTopmost
    
    VBMAN.ToolsWindow.TopMost Me.hWnd, Not IsTopmost
    
    cmdToggleTopmost.Caption = IIf(IsTopmost, "Remove Topmost", "Set Topmost")
End Sub

Use Cases ​

ScenarioMethod to Use
Floating WindowTopMost keeps window on top
Popup NotificationSwitchToThis switches to notification window
Modal DialogActiveForm ensures dialog keeps focus
Fullscreen ApplicationTopMost + ActiveForm combined

VB6 and LOGO copyright of Microsoft Corporation