VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Another Prev Instance Activator

by Thomas Greenwood (2 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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)
Code 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

Download Another Prev Instance Activator

Download Another Prev Instance Activator (3 KB)

Another Prev Instance Activator Comments

No comments have been posted about Another Prev Instance Activator. Why not be the first to post a comment about Another Prev Instance Activator.

Post your comment

Subject:
Message:
0/1000 characters