Solved

VB4 16-bit AppActivate error

Posted on 1998-01-30
1
287 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
[X]
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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

734 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