Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Add result using EnumWindow/GetWindowText

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Steele - 06 Dec 2004 21:41 GMT
I've written a callback function for use with EnumWindow that is intended to
return the URL of all open IE windows. The code seems to do almost exactly
what I want, but fails at the final step when it tries to retrieve the text
of the address bar using the Win32 API GetWindowText. It returns an empty
string instead of the URL. Has anyone tried this? The code is pretty
straightforward, but I don't see what wrong:

private bool ieCheck(int hWnd, int lParam)
{
    StringBuilder text = new StringBuilder(256);
    if (GetClassName(hWnd, text, 256) == 0)
     return true;
    if (text.ToString() != "IEFrame")
     return true;
    int ieHandle = FindWindowEx(hWnd, 0, "WorkerW", null);
    if ((int)ieHandle > 0)
    {
         ieHandle = FindWindowEx(ieHandle, 0, "ReBarWindow32", null);
         if ((int)ieHandle > 0)
         {
             ieHandle = FindWindowEx(ieHandle, 0, "ComboBoxEx32", null);
              if ((int)ieHandle > 0)
              {
                   GetWindowText(hWnd, text, 256);
                     output.Add(text.ToString());
              }
         }
    }
    return true;
}
Serg - 07 Dec 2004 04:45 GMT
Try Spy++ tool which comes with your development environment. The control
that actually has your URL caption has a window class name of 'Edit', and is
a child of the 'ComboBoxEx32' of your 'ReBarWindow32'. Give this a try.

> I've written a callback function for use with EnumWindow that is intended to
> return the URL of all open IE windows. The code seems to do almost exactly
[quoted text clipped - 26 lines]
>      return true;
> }
Serg - 07 Dec 2004 05:25 GMT
Ok here's what's wrong. Replace GetWindowText in the innermost if with, and
you've got your url. Appearently SendMessage works better with out of process
boundaries.

SendMessage((IntPtr) ieHandle, 0x000D, new IntPtr(256), text);

//and here is my SendMessage from pinvoke.net
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,        
[Out] StringBuilder lParam);

HTH

> I've written a callback function for use with EnumWindow that is intended to
> return the URL of all open IE windows. The code seems to do almost exactly
[quoted text clipped - 26 lines]
>      return true;
> }
Paul Steele - 07 Dec 2004 11:46 GMT
> Ok here's what's wrong. Replace GetWindowText in the innermost if with,
> and
[quoted text clipped - 8 lines]
> static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
> [Out] StringBuilder lParam);

Thanks for confirming what I found out through additional googling and
testing!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.