Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to bring a new window of default browser (or Chrome) to front in a not maximized window (Google Translate) for the user to type in it immediately and sees translation and then the user closes it and continues his work.

The code below works but opens only a new tab not a whole new window.

I also want to set the window near the mouse position and in moderate size relative to the monitor.

What I have tried:

var prs = new ProcessStartInfo("chrome.exe");
            prs.Arguments = "http://translate.google.com";
           Process p= Process.Start(prs);
           Program.setFocusToProcess(p);


public static void setFocusToThisProcessName(string name)
        {
            Process[] Processes = Process.GetProcessesByName(name);

            //if (Processes.Length == 0)
            //{
            //    MessageBox.Show("The program: '" + name + "' isn't running and can't be focused on.", "TranslateProgram");
            //    return;
            //}



            foreach (Process process in Processes)
            {
                setFocusToProcess(process);
            }
        }


        static void setFocusToProcess(Process process)
        {
            if (process.MainWindowHandle == (IntPtr)0x00000000)
            {
                return;
            }

            const int SW_RESTORE = 9;



            //if(IsIconic(process.MainWindowHandle) != 0)
            //{
                ShowWindow(process.MainWindowHandle, SW_RESTORE);
            //}

            SetForegroundWindow(process.MainWindowHandle);

            BringWindowToTop(process.MainWindowHandle);

            SetFocus(new HandleRef(null, process.MainWindowHandle));
        }




I found that this opens a new window:
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
process.StartInfo.Arguments = "google.com" + " --new-window";
process.Start();
Posted
Updated 19-Dec-18 11:16am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900