Getting URL of Internet Explorer page?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Anyone know how to get the URL of the current Internet Explorer page?
I can see, via ShoWin, that the URL address bar is of "Edit" class,
so if I could somehow use the GetWindowText API on it then all would
be fine... but I don't know how to get its handle. So what I need is
to be taught how to get all the child window/classes of an Internet
Explorer window... can somebody please teach me? :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Hello PB,

Does the ObjectClass app I posted on ressource site not help ? (Snippet section). If it does not but just because some information miss I can extend it to meet your needs.

Rgrds

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Does the ObjectClass app I posted on ressource site not help ?

No, it doesn't, because it just gets the details from the window under
the mouse (just like ShoWin, actually). I need to get the info without
using the mouse, which means getting the handle of the IE window and
then searching its children for the URL address bar. And I'm not sure
how to do that... I've experimented with FindWindowEx a bit but haven't
succeeded...


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

...,

Using the following snippet you will get Main windows information.

Structure FindWindowData
hFW.l
sFW.s
EndStructure
NewList FindWindow.FindWindowData()

Procedure.l EnumWindowsProc(hFind,lParam)
WindowName.s=Space(255)
If GetWindowText_(hFind,@WindowName,255)
AddElement(FindWindow())
FindWindow()\hFW=hFind
FindWindow()\sFW=WindowName
EndIf
ProcedureReturn 1
EndProcedure

OpenConsole()
If EnumWindows_(@EnumWindowsProc(),0)
ResetList(FindWindow())
While NextElement(FindWindow())
Debug FindWindow()\sFW + " " + Str(FindWindow()\hFW)
Wend
EndIf
Input()
CloseConsole()
End

The problem is ATM that I cannot get children parameters. If you launch both ObjectClass program and this snippet you will notice that you can get opened IE parameters with FindWindow but the ObjectClass program gives more because you can find children objects.

ATM I could not find the right way to list a hierarchical listing of ALL objects starting from parents ...

If you have any idea in the meanwhile I am interested. Otherwise I will go back on this in the near future.

...

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Take a look at EnumChildWindows_(hWndParent,EnumCallback,0)
to get all ChildWindows.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

This code gets the URL, the max lenght is set to 500 chars.

Code: Select all

hedit.l=0

Procedure EnumFunc(hchild,lparam)
  Shared hedit
  class$=Space(30)
  GetClassName_(hchild,@class$,30)
  If class$="Edit"
    hedit=hchild
    ProcedureReturn 0
  EndIf
  ProcedureReturn 1
EndProcedure

;IE handle
hie.l=FindWindow_("IEFrame",#null)
If hie=0 : MessageRequester("Error","IE Window not found.",0) : End : EndIf

;find Edit handle
EnumChildWindows_(hie,@EnumFunc(),0)
If hedit=0 : MessageRequester("Error","Edit control not found.",0) : End : EndIf

;get text
editcont$=Space(500)
sendmessage_(hedit,#WM_GETTEXT,500,@editcont$)

MessageRequester("Edit",editcont$,0)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

...,

I tried to solve your question in a larger way ...

Hope this snippet will help now and later.

I have just posted the same code on the ressource site.

Let me know your opinion about and any test result you will have.

;================================================================
;
; EnumWindows TreeView
; F.Weil 20020828
;
; Two linked lists are used for both parent windows and children objects
;
; Each list is updated using a callback Enum procedure
;
; The Tree gadget is build when opening the program's main window
; then you have just to click the items / nodes and surf.
;
; This program has a resizing feature linking the tree gadget size to the main window.
;
; I choosed to put all handle, text and class name information in a single label in the
; tree gadget for each item, so that no more action is necessary except looking labels.
;
; I also tried a List icon gadget version of this program but this tree gadget version is
; really simple and convenient for any further feature to add later.
;
; Feel free to modify update this code sample for any use in the PureBasic community.
;

Structure FindWindowData
hFW.l ; variable to store a handle
sFW.s ; variable to store a Window name
cFW.s ; variable to store a window class name
EndStructure

NewList FindWindow.FindWindowData()
NewList FindChild.FindWindowData()

Procedure.l EnumChildProc(hChild, lParam)
ChildName.s = Space(255)
ChildClass.s = Space(255)
If GetWindowText_(hChild, ChildName, 255)
Else
SendMessage_(hChild, #WM_GETTEXT, 500, ChildName)
EndIf
If GetClassName_(hChild, ChildClass, 255)
AddElement(FindChild())
FindChild()\hFW = hChild
FindChild()\sFW = ChildName
FindChild()\cFW = ChildClass
EndIf
ProcedureReturn 1
EndProcedure

Procedure.l EnumWindowsProc(hFind, lParam)
WindowName.s = Space(255)
WindowClass.s = Space(255)
If GetWindowText_(hFind, WindowName, 255)
Result = GetClassName_(hFind, WindowClass, 255)
AddElement(FindWindow())
FindWindow()\hFW = hFind
FindWindow()\sFW = WindowName
FindWindow()\cFW = WindowClass
EndIf
ProcedureReturn 1
EndProcedure

;
; Main starts here
;

WEvent.l
WindowXSize.l
WindowYSize.l
Quit.l

Quit = #FALSE
WindowXSize = 320
WindowYSize = 240

If OpenWindow(0, 200, 200, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar, "MyWindow")
CreateGadgetList(WindowID())
TreeGadget(100, 0, 0, WindowXSize, WindowYSize, #PB_Tree_AlwaysShowSelection)
If EnumWindows_(@EnumWindowsProc(), 0)
ResetList(FindWindow())
While NextElement(FindWindow())
AddGadgetItem(100, -1, FindWindow()\sFW + " - " + FindWindow()\cFW + " - " + Str(FindWindow()\hFW))
ClearList(FindChild())
If EnumChildWindows_(FindWindow()\hFW, @EnumChildProc(), 0)
OpenTreeGadgetNode()
ResetList(FindChild())
While NextElement(FindChild())
AddGadgetItem(100, -1, FindChild()\sFW + " - " + FindChild()\cFW + " - " + Str(FindChild()\hFW))
Wend
CloseTreeGadgetNode()
EndIf
Wend
EndIf

Repeat
WEvent = WaitWindowEvent()
Select WEvent
Case #PB_EventCloseWindow
Quit = #TRUE
Default
EndSelect

If WindowXSize WindowWidth() Or WindowYSize WindowHeight()
WindowXSize = WindowWidth()
WindowYSize = WindowHeight()
ResizeGadget(100, 0, 0, WindowXSize, WindowYSize)
EndIf

Until Quit

EndIf

End
;================================================================

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> This code gets the URL, the max lenght is set to 500 chars.

Thanks Justin, that's precisely what I needed. :)

(BTW: To everyone else, thanks for your assistance also -- I shall
study what you've all provided and hopefully learn from it all).


PB - Registered PureBasic Coder
Post Reply