Public Const WM_GETICON = &H7F
Public Const WM_SETICON = &H80
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function IsIcconic Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
'Constants used for the return of the MultiInst function
Public Const OPEN_APPLICATION = 0
Public Const SINGLE_INSTANCE_OPEN = 1
Private Sub AccpacOE1100UICtrl_OnUIAppOpened()
Dim hWnd As Long
Dim hIcon As Long
Dim MultiInstResult As Integer
Dim iWindow As Integer
'On Error Resume Next
With Me.AccpacOE1100UICtrl
Set Me.Icon = .UIIcon
hIcon = SendMessage(Me.hWnd, WM_GETICON, ICON_BIG, ByVal 0)
SendMessage nMainhWnd, WM_SETICON, ICON_BIG, ByVal hIcon
sCompanyID = .UIDBLinks(1).Session.CompanyID
'Call procedure to determine if an instance of the application is already loaded
MultiInstResult = MultiInst(sCompanyID & " - O/E Order Entry")
If MultiInstResult = SINGLE_INSTANCE_OPEN Then
'An instance already exists cancel the current application load
End
End If
end sub
Public Function MultiInst(sWindow As String) As Integer
'This function determines if a single instance of the
'application is already running.
Dim hwndFound As Long 'The window handle
Dim strWindowName 'The Caption on the window
'Set the caption of the application form
strWindowName = sWindow
'Get the handle of the application if it is open
hwndFound = FindWindow(vbNullString, strWindowName)
If hwndFound Then
'Set the function return
MultiInst = SINGLE_INSTANCE_OPEN
'If application minimized, restore, show it on top
If IsIcconic(hwndFound) Then
ShowWindow hwndFound, SW_RESTORE
'Show the window infront of all other windows
SetForegroundWindow hwndFound
Else
'Bring the application top most on the screen
SetForegroundWindow hwndFound
End If
ElseIf hwndFound = 0 Then
'Set the function return so it will continue loading
MultiInst = OPEN_APPLICATION
End If
End Function