VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Another Prev Instance Activator

Thomas Greenwood  (2 Submissions)   Windows API Call/Explanation   Visual Basic 5.0   Intermediate   Wed 3rd February 2021

This code will activate a previous instance of your program if detected. It uses subclassing of the main window.

Inputs
N/A

Assumes
May crash the ide, so save your work before execution (did not crash mine however, but subclassing can be unstable)

Returns
N/A

Side Effects
Had to use end to close the next instance (not the prev instance). Using Unload Obj in Form_Load produced an error, it can be used if On Error Resume Next or a Error Handler is produced.

API Declarations
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' ^ Used to change window proc
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' ^ Used to call default window proc for window
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
' ^ Send Message to window (Proc)
Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
' ^ Used, funnily enough...to flash the window :D
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
' ^ Used to find the window if we have a prev instance
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
' ^ Check to see if we have a valid window.

Rate Another Prev Instance Activator (4(4 Vote))

Download Another Prev Instance Activator

Another Prev Instance Activator Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters