Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Setting the focus for an Application in VB.net

  • 16-10-2008 06: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, Registered Users 2 Posts: 2,157 ✭✭✭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, Registered Users 2 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, Registered Users 2 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