In this tips, I would like to discuss how to make an application run only once at a time. When user try to run your application, first try to see if it is already running. If it is already running bring it to top and return. There are some sleek SDK functions you can make use of to implement this. The following are the steps to create this feature:

  1. Create a "Custom Class UserObject"
    Custom Class PowerBuilder UserObject
  2. Set the AutoInstantiate to TRUE
  3. Declare the Win32 API modul at the UserObject on Declare -> Local External Functions
    Function Long GetLastError () Library 'kernel32.dll'
    Function ULong CreateMutex (ULong lpsa, Boolean fInitialOwner, String lpszMutexName) Library 'kernel32.dll' Alias for CreateMutexA
  4. Create a UserObject Function like this:
    Create UserObject Function - isRunning
    String ls_name
    If Handle(GetApplication()) > 0 Then
    ls_name = GetApplication().AppName + Char(0)
    CreateMutex(0, True, ls_name)
    If GetLastError() = 183 Then Return True
    End If
    Return False
  5. Save the UserObject as uo_mutex (for example)
Below is how to use the object. Put this code at the beginning of open event from your Application object:
uo_mutex lou_mutex
If lou_mutex.uf_isrunning() Then
MessageBox ('Warning', 'Application is already running', StopSign!)
HALT CLOSE
End If
//...
// Your next line code
//...