Page 1 of 1

Obtaining the title of a web page

Posted: Fri Jun 11, 2004 9:40 pm
by Dreamland Fantasy
Hi there,

Could someone please tell me how to go about getting the title of a web page which is being displayed in a WebGadget?

Posted: Fri Jun 11, 2004 10:00 pm
by PolyVector
No time to test... but it should go something like this...

Code: Select all

Procedure.s ByteStr(pointer.l) 
  strlen.w = WideCharToMultiByte_(#CP_ACP, 0, pointer, -1, 0, 0 , 0, 0) 
  string.s = Space(strlen) 
  If strlen <> 0 
    newlen.w = WideCharToMultiByte_(#CP_ACP, 0, pointer, -1, @string, strlen , 0, 0) 
  EndIf 
  ProcedureReturn string 
EndProcedure 
  
Procedure.s GetLocationName$(WebGadgetNumber.l)
  Protected WebObject.IWebBrowser2,Ptr.l
  WebObject = GetWindowLong_(GadgetID(WebGadgetNumber), #GWL_USERDATA)
  WebObject\get_LocationName(@Ptr.l)
  ProcedureReturn ByteStr(Ptr)
EndProcedure

Posted: Sat Jun 12, 2004 1:06 am
by freak
Your procedure works. However, since you are dealing with a BSTR string
here, you should call SysFreeString_() to free it when it is no longer needed.

So the ByteStr() procedure could look like this:

Code: Select all

Procedure.s ByteStr(pointer.l)
  strlen.w = WideCharToMultiByte_(#CP_ACP, 0, pointer, -1, 0, 0 , 0, 0)
  string.s = Space(strlen)
  If strlen <> 0
    newlen.w = WideCharToMultiByte_(#CP_ACP, 0, pointer, -1, @string, strlen , 0, 0)
  EndIf
  SysFreeString_(pointer)  ; <<---- free the string.
  ProcedureReturn string
EndProcedure 
Timo

Posted: Sat Jun 12, 2004 1:55 am
by PolyVector
Thanks freak, I missed that :)

Posted: Sat Jun 12, 2004 1:52 pm
by Dreamland Fantasy
Excellent! :D This is exactly what I am looking for!

Thank you!

Kind regards,

Francis.