Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB4 16-bit AppActivate error

Posted on 1998-01-30
1
284 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 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