Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Setting the focus for an Application in VB.net

Options
  • 16-10-2008 6:52pm
    #1
    Closed Accounts Posts: 2,268 ✭✭✭


    I have an applicatuion which calls an external process. I would like this process to be open as soon as it is called. i.e. with no user interaction.

    This is because I would like to send Keys to it to interact.
    I know how crude this is but this is a thrid party application that my boss has promised will open is a specific way.
    Dim procSungard As System.Diagnostics.Process = _
               New System.Diagnostics.Process()
               procSungard.StartInfo.FileName = _
               System.Environment.GetFolderPath_
              (Environment.SpecialFolder.ProgramFiles)&_
              "sungard/sungard.exe"
              procSungard.StartInfo.WindowStyle = _
              System.Diagnostics.ProcessWindowStyle.Normal
    
    
               If iCode = 1 Then
    
                procSungard.Start()
    
                System.Threading.Thread.Sleep(100)
                System.Windows.Forms.SendKeys.Send("{Tab}")
                End If
    

    So I declare the process, get its expected location and set a window style.
    Is there any way to give it focus on load?

    MM


Comments

  • Registered Users Posts: 2,150 ✭✭✭dazberry


    You'll probably need to use the likes of SetForegroundWindow and SetActiveWindow API functions directly. Something like (in C# - VB.NET should be pretty similar...)
            [DllImport("user32.dll")]       
            static extern bool SetForegroundWindow(IntPtr hWnd);
            [DllImport("user32.dll")]
            static extern int SetActiveWindow(IntPtr hWnd);
    
            ...
    
            Process process = Process.Start("c:\\winnt\\notepad.exe");
            SetActiveWindow(process.MainWindowHandle);
            SetForegroundWindow(process.MainWindowHandle);                       
    

    D.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Second post in this thread should help you out

    http://bytes.com/forum/thread113739.html


  • Closed Accounts Posts: 2,268 ✭✭✭mountainyman


    Ginger you are the king (or queen if you prefer) of CLR.

    MM


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    I generally prefer king :)


  • Closed Accounts Posts: 2,268 ✭✭✭mountainyman


    Dazberry apologies forgot to say thanks
    You are the Jedi of CLR.


  • Advertisement
Advertisement