Activating a Previous Instance of an Application

Activating a Previous Instance of an Application

To prevent users from launching multiple instances of your application,check the PrevInstance property of VB’s App object; if the propertyis True, the program is already running. To activate the previousinstance, call Windows’ FindWindow, ShowWindow, and SetFocus APIs:

 Global Const SW_RESTORE=9Declare Function FindWindow Lib "User" _         (ByVal lpClassName As Any, ByVal _        lbWindowName As Any) As IntegerDeclare Function ShowWindow Lib "User" _         (ByVal hWnd As Integer, ByVal _        nCmdShow As Integer) As IntegerDeclare Function SetFocusAPI Lib _        "User" Alias "SetFocus" (ByVal _        hWnd As Integer) As IntegerSub Main ()        Dim hWnd As Integer        Dim iResult As Integer        ' App object's Title property may be         ' set at runtime, as illustrated         ' here, or at compile time in VB's         ' Make .EXE' dialog.        App.Title = "Test Application"        If App.PrevInstance Then                ' ThunderForm is the class name                 ' for VB forms (Thunder was the                 ' original code name for Visual                 ' Basic within 'Microsoft)                ' Find the existing instance                hWnd = FindWindow("Thunder_                        Form", App.Title)                ' FindWindow function returns a                 ' non-zero value if it finds a                 matching window                 If hWnd <> 0 Then                        ' Restore window if minimized                        iResult = ShowWindow(hWnd,                                SW_RESTORE)' Set focus to the specified window                        iResult = SetFocusAPI(hWnd)                        ' Close this instance                        End                End If        End If        ' If no previous instance, show        ' main form and proceed normally.        frmMain.ShowEnd Sub
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved