Results 1 to 3 of 3

Thread: [RESOLVED] How to get focus back to my app

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    42

    Resolved [RESOLVED] How to get focus back to my app

    Hi, here is my problem :

    I have 2 vb programs, App1 and App2.

    App1 launches App2 with

    Code:
    Shell "App2.exe", vbNormalFocus
    I would like App1 to get back the focus when user minimizes App2.

    For the moment, when App2 is minimized by the user, he has to click App1. When I try the command AppActivate, App1 (MDI form) flashes but does not get the focus.

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2020
    Posts
    42

    Re: How to get focus back to my app

    Thank you, it seems to be the best solution. I was trying to pilot everything from App1 (waiting App2 to lose focus in order to get it back) but your solution is better.

    For those interested, here is what I've done.

    App1 :
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        
        Shell """" & App.Path & "\App2.exe"" " & Me.hWnd, vbNormalFocus
        
    End Sub
    App2:
    Code:
    Option Explicit
    
    Private App1hWnd As Long
    
    Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
    
    Private Sub Form_Load()
    
        App1hWnd = CLng(Command$)
        
    End Sub
    
    Private Sub Form_Resize()
        
        If Me.WindowState = vbMinimized Then
            
            If App1hWnd <> 0 Then SetForegroundWindow App1hWnd
            
            Exit Sub
            
        End If
        
    End Sub
    Attached Files Attached Files

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