Solved

VB4 16-bit AppActivate error

Posted on 1998-01-30
1
282 Views
Last Modified: 2008-02-01
I've place the following code in the Sub Main() of my program

    If App.PrevInstance Then
        sTitle = App.Title
        App.Title = "armgarmgar"
        AppActivate sTitle
        End
    End If

After running a second instance of my program it gives me a runtime error  'Invalid procedure call' '5'

I'm  also running the program under Win95.  What am I doing wrong?
0
Comment
Question by:armg
1 Comment
 
LVL 6

Accepted Solution

by:
anthonyc earned 200 total points
ID: 1454497
The problem is you are confusing your app, since the title is the same as your current app.  Use this code to do what yu want.  In sub main put this

Please find the declare for the API functions in the api viewer
(findwindow, getwindowplacement, setfocusapi, setforegorund window)  The #if are precompiler conditions


sub main
  if app.previnstance then
      restorepreviousinstance
      end
  end if
end sub

Public Sub RestorePreviousInstance()
    Dim lngPrevWin       As Long
    Dim strPreviousTitle As String
   
    'VB3 & VB4 use class name "ThunderRTForm"
    'VB5 uses class name "ThunderRT5Form"
    'Including the class name for the compiled exe class
    'prevents the routine from finding and attempting
    'to activate the project form of the same name.
    'Set the current App.Title = "....Duplicate Instance" to avoid it being found
    strPreviousTitle = App.Title
    App.Title = "....Duplicate Instance"
   
#If Win32 Then
    lngPrevWin = FindWindow("ThunderRT5Form", strPreviousTitle)
#Else
    lngPrevWin = FindWindow("ThunderRTForm", strPreviousTitle)
#End If
   
    DoEvents
   
    'Check to see if the previous instance is open
    If lngPrevWin > 0 Then
        Dim intReturn As Long
        Dim udtCurWin As WINDOWPLACEMENT
       
        'get the current window state of the previous instance
        udtCurWin.Length = Len(udtCurWin)
        intReturn = GetWindowPlacement(lngPrevWin, udtCurWin)
               
        'if the udtCurWin.showCmd member indicates that
        'the window is currently minimized, it needs
        'to be restored, so ...
        If udtCurWin.showCmd = SW_SHOWMINIMIZED Then
            udtCurWin.Length = Len(udtCurWin)
            udtCurWin.Flags = 0&
            udtCurWin.showCmd = SW_SHOWNORMAL
            intReturn = SetWindowPlacement(lngPrevWin, udtCurWin)
        End If
       
        'bring the window to the front and make
        'the active window.  Without this, it
        'may remain behind other windows.
        'This command only works in Win32
#If Win32 Then
        intReturn = SetForegroundWindow(lngPrevWin)
#Else
        intReturn = SetFocusAPI(lngPrevWin)
#End If
       
        DoEvents
   End If
End Sub



0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question