Click here to Skip to main content
15,885,653 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I open a Google Translate page and bring it to front, but it doesn't always get focus on the source textbox for the user to type immediately. It gets focus always when I run it in VS debugging but not as and independent exe file.

Always after pressing the button on my mouse that runs this exe file after a long time of not pressing the button, the "source" textbox gets selected, but if I press not after a long time from the last press, the textbox "source" doesn't get selected.

What I have tried:

Process[] Processes = Process.GetProcessesByName("dragon");

            foreach (Process p in Processes)
            {
                ShowWindow(p.MainWindowHandle, SW_RESTORE);
            }



            Processes = Processes.Where(p => p.MainWindowHandle != IntPtr.Zero).ToArray();

            if (Processes.Length == 0)
            {
                ProcessStartInfo prs = new ProcessStartInfo("dragon.exe");
                prs.Arguments = "http://translate.google.com" + " --new-window";
                prs.WindowStyle = ProcessWindowStyle.Normal;
                Process p = Process.Start(prs);
                //p.WaitForInputIdle(3000);
            }


            Processes = Process.GetProcessesByName("dragon");

            foreach (Process p in Processes)
            {
                ShowWindow(p.MainWindowHandle, SW_MINIMIZE);
            }

            foreach (Process p in Processes)
            {
                ShowWindow(p.MainWindowHandle, SW_RESTORE);
                SetWindowPos(p.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
                BringWindowToTop(p.MainWindowHandle);
                SetForegroundWindow(p.MainWindowHandle);
            }

            foreach (Process p in Processes)
            {
                SetWindowPos(p.MainWindowHandle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
                SetWindowPos(p.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
            }

            foreach (Process p in Processes)
            {
                ShowWindow(p.MainWindowHandle, SW_RESTORE);
                BringWindowToTop(p.MainWindowHandle);
                SetFocus(new HandleRef(null, p.MainWindowHandle));
            }

            foreach (Process p in Processes)
            {
                SetForegroundWindow(p.MainWindowHandle);
            }
Posted
Updated 23-Dec-18 8:11am
v4
Comments
Dave Kreskowiak 22-Dec-18 10:23am    
Remember what I said just a few days ago about you "doing this the hard way"? This is why. You have little to no control over the user interface, cannot interact with it without major effort, and your code will become useless garbage the second Google changes the UI on that page.
john1990_1 22-Dec-18 10:56am    
I understand, thanks a lot for caring, but I made once an English teaching program but I didn't finish it because such a program needs to have a corporation do it not only one hobbyist, in it I embedded Google Translate Well and it translates online each English word to 3 languages chosen by the user and displays them in labels, the program you linked me to may be the one that I took code from it, but I want interactive Google Translate's page with history of searched texts (this feature is new), with choosing the languages comfortably, with detecting the language and showing which language to translate from, I have a program already that has a Bing Translate page and that had Google Translate page in the past but Google now prevents the browser control of VS from accessing Google Translate's website, and Bing Translate is horrible and detects text's language horribly wrong.

Please check my program linked below (without built in Google Translate page but can open it in the default browser with a button).

The UI of the program you sent me is terribly unfriendly and uncomfortable.
Dave Kreskowiak 22-Dec-18 11:12am    
I didn't post any links to any program anywhere and I'm not downloading code from an untrusted source, from an untrusted person.
john1990_1 22-Dec-18 11:19am    
The code is simple, and you can view it before running it, you can even open it in VS and not even press debug, it can't possibly harm you, I'm not sure about that, can it? well anyway it's not important that you view it, would you please help me about the code in the code textbox of this web page, and why it successfully selects the "source" textbox in Google Translate web page only after not pressing it for a long time, and if I press it not after a long time from the last press it doesn't select the "source" textbox? (I press a mouse button that is configured to run the exe file)

1 solution

Use the API properly:

Cloud Translation API documentation  |  Cloud Translation API  |  Google Cloud[^]

Integrate it with a Windows form that accepts the text.
 
Share this answer
 
Comments
john1990_1 23-Dec-18 14:16pm    
No thank you, I would rather use my exe that opens or brings to front Comodo Dragon browser with Google Translate page in it (while using Dragon browser only for this website), I've seen an example of an API, a Google translate page is much richer and more efficient and more friendly and comfortable. see the link to the source code I'm talking about in my website in the bottom of the page:
https://sites.google.com/site/workofmylife1234/
I don't want to spend a lot of time on programming anymore...

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