Results 1 to 7 of 7

Thread: Maximize application

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84

    Question

    Hi:

    I know that with app.previnstance I can detect if my application it's runnig but how can I maximize the application if it's minimize and running and I try to run again?

    Thanks in advance
    Regards.
    Angel Maldonado López.
    VB Programmer

  2. #2
    Guest
    Try this:

    Code:
    Option Explicit
    
    Public Const GW_HWNDPREV = 3
    Declare Function OpenIcon Lib "User32" (ByVal hWnd As Long) As Long
    Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal _
    nCmdShow As Long) As Long
    Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal _
    lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function getwindow Lib "User32" Alias "GetWindow" (ByVal hWnd As Long, ByVal _
    wCmd As Long) As Long
    Declare Function SetForegroundWindow Lib "User32" (ByVal hWnd As Long) As _
    Long
    Public Const SW_MAXIMIZE = 3
    
    Sub ActivatePrevInstance()
    
       Dim OldTitle As String
       Dim PrevHndl As Long
       Dim result As Long
       Dim maxWin As Long
       
       'Save the title of the application.
       OldTitle = App.Title
    
       'Rename the title of this application so FindWindow
       'will not find this application instance.
       App.Title = "unwanted instance"
    
       'Attempt to get window handle using VB4 class name.
       PrevHndl = FindWindow("ThunderRTMain", OldTitle)
    
       'Check for no success.
       If PrevHndl = 0 Then
    
          'Attempt to get window handle using VB5 class name.
          PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
       End If
    
       'Check if found
       If PrevHndl = 0 Then
            'Attempt to get window handle using VB6 class name
            PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
       End If
    
       'Check if found
       If PrevHndl = 0 Then
          'No previous instance found.
          Exit Sub
       End If
    
       'Get handle to previous window.
       PrevHndl = getwindow(PrevHndl, GW_HWNDPREV)
    
       'Restore the program.
       result = OpenIcon(PrevHndl)
    
       'Activate the application.
       result = SetForegroundWindow(PrevHndl)
       
       'Maximize Window
       maxWin = ShowWindow(PrevHndl, SW_MAXIMIZE)
       
       'End the application.
       End
    End Sub
    
    Private Sub Form_Load()
       If App.PrevInstance Then
          ActivatePrevInstance
       End If
    End Sub

  3. #3
    Guest
    Be careful on this one. When testing it in the IDE, the ClassName is ThunderForm.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84

    Thumbs up

    Hi Matt:

    It works perfectly, thanks a lot

    Regards.
    Angel Maldonado López.
    VB Programmer

  5. #5
    Guest
    AM LOPEZ, curious: what version of VB are you using?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84

    Talking

    I'm using VB 6.0
    Angel Maldonado López.
    VB Programmer

  7. #7
    Guest
    Oh yeah, I see how it works for all VB versions.

    Code:
       'Attempt to get window handle using VB4 class name.
       PrevHndl = FindWindow("ThunderRTMain", OldTitle)
    
       'Check for no success.
       If PrevHndl = 0 Then
    
          'Attempt to get window handle using VB5 class name.
          PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
       End If
    
       'Check if found
       If PrevHndl = 0 Then
            'Attempt to get window handle using VB6 class name
            PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
       End If
    Did not see that, I only saw Visual Basic 4.0. Well, as long as it works, than that's good .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width