Solved

VB4 16-bit AppActivate error

Posted on 1998-01-30
1
279 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now