Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the window handle of a particular webpage
My code is as follows:
C#
ProcessStartInfo psi = new ProcessStartInfo("iexplore.exe", "http://google.com");
Process p = Process.Start(psi);
int number = p.Id;
Console.WriteLine(number);//the process id
IntPtr windowHandle = p.Handle;
Console.WriteLine(windowHandle.ToInt32());// corresponding handler


I am getting a 4 digit handler. But not sure if it's correct or not. Because the process id which is returning, I can't find that process id when I am checking process ids by Task Manager.
And also I am using that window handle later to activate that page. But sometime it is not activating that page. Instead it activating some other window.
What changes I need to in my code or is there any other way by which I can get the handler of any webpage
Posted
Comments
ZurdoDev 4-Feb-15 7:46am    
I know IE will have one process for several windows. Why are you wanting to do this?
JaideepChandra 4-Feb-15 7:50am    
Using that handler of the particular page , I am trying to activate that page later in my project.
Nathan Minier 5-Feb-15 7:36am    
By and large, a web page does not have a handle since a web page isn't a process, the containing browser is. Specific browsers may be an exception to the rule, or if you open multiple browser instances, but there's the other problem: the browser process itself isn't aware of what it's pointing to, that's an application-level variable. I don't think you're going to be able to do what you want without a heck of a lot of infrastructure.

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