I'm new to c# and programming. I'm trying to get the current URL being displaying in internet explorer.
So far I've managed to get an ArrayList of IntPtr's to all the currently open internet explorer windows. I'm not sure where to go from there. Can anyone help?
Thanks alot!
Loading
Sateesh ArvetiPosted Sep 2, 2008, 3:39 AM
so u r having all the IntPtrs of the opened IE windows.From here,u have to get handle for the URL control(textbox) and get the text of it.try to use this code and see once:
#region WIN32 API
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int msg, int wParam, StringBuilder sb);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string _ClassName, string _WindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr _Parent, int _ChildAfter, string _ClassName, string _WindowName);
public const int WM_GETTEXTLENGTH = 0x000E;
public const int WM_GETTEXT = 0x000D;
#endregion
IntPtr worker = FindWindowEx("pass Window Handle here", 0, "WorkerW", null);
IntPtr toolbar = FindWindowEx(worker, 0, "rebarwindow32", null);
IntPtr comboboxex = FindWindowEx(toolbar, 0, "comboboxex32", null);
IntPtr combo = FindWindowEx(comboboxex, 0, "ComboBox", null);
IntPtr edit = FindWindowEx(combo, 0, "Edit", null);
StringBuilder sb = new StringBuilder(length + 1);
SendMessage(edit, WM_GETTEXT, length + 1, sb);
if (sb.ToString().ToLower().IndexOf("google.com") != -1)
{
if (sb.ToString().IndexOf("?") != -1)
{
string url = sb.ToString();
}
}
sivaPosted May 12, 2009, 2:28 AM
using
System;using
System.Collections.Generic;using
System.Text;using
SHDocVw;namespace
ConsoleApplication1{
class Program{
static void Main(string[] args){
foreach (InternetExplorer ie in new ShellWindowsClass()){
Console.WriteLine(ie.LocationURL);}
Console.ReadLine();}
}
}
Please add a reference of shDocVw in system32
chris sunterPosted Sep 15, 2008, 10:25 AM
I have the following code to return the URL of an IE instance, however it always returns a blank URL can anyone see why?
string progName = "iexplore.exe";
ProcessStartInfo process = new
ProcessStartInfo(progName);
process.Arguments = "http://www.google.com";
// start process
_InternetExplorerGoogleProcess = new Process();
_InternetExplorerGoogleProcess = Process.Start(process);
IntPtr hWnd = (IntPtr)_InternetExplorerGoogleProcess.MainWindowHandle;
int WM_GETTEXT = 0x000D;
int length = 0;
IntPtr worker = FindWindowEx(hWnd,0, "WorkerW", null);
IntPtr toolbar = FindWindowEx(worker,0, "rebarwindow32", null);
IntPtr comboboxex = FindWindowEx(toolbar,0, "comboboxex32", null);
IntPtr combo = FindWindowEx(comboboxex,0, "ComboBox", null);
IntPtr edit = FindWindowEx(combo,0, "Edit", null);
StringBuilder sb = new StringBuilder(length + 1);
SendMessage(edit, WM_GETTEXT, length + 1, sb);
if (sb.ToString().IndexOf("?") != -1)
{
string url = sb.ToString();
MessageBox.Show("MESSAGE here 1 = " + url);
}
else
{
string url = sb.ToString();
MessageBox.Show("MESSAGE here 2 = " + url);
}
Thanks in Advance,
Raj KumarPosted Sep 1, 2008, 11:26 PM
Use Request.RawUrl
string str = Request.RawUrl;