Obtaining the title of a web page

Windows specific forum
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Obtaining the title of a web page

Post 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?
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Thanks freak, I missed that :)
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Post by Dreamland Fantasy »

Excellent! :D This is exactly what I am looking for!

Thank you!

Kind regards,

Francis.
Post Reply