Page 1 sur 1

Y a t-il un spécialiste des interfaces dans la salle?

Publié : sam. 29/oct./2005 12:42
par Chris
Ce bout de code me retourne des caractères incompréhensibles, j'arrive pas à trouver pourquoi! :?

Code : Tout sélectionner

#Win = 0
#Web = 0
If OpenWindow(#Win,0,0,600,300,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"WebGadget") And CreateGadgetList(WindowID(0))
  WebGadget(#Web,10,10,580,280,"http://www.purebasic.com")
  
  ; ==================================================================
  Browser.IWebBrowser2 = GetWindowLong_(GadgetID(#Web), #GWL_USERDATA)
  If Browser = 0
    MessageRequester("Erreur","Impossible d'initialiser le navigateur", #MB_OK|#MB_ICONERROR)
    End
  Else
    Repeat 
      While WindowEvent(): Wend 
      Delay(1) 
      Browser\get_Busy(@IsBusy.l) 
    Until IsBusy = 0 
  EndIf
  
  Adress.s = Space(#MAX_PATH)
  If Browser\get_LocationURL(@Adress) = #ERROR_SUCCESS
    MessageRequester("", PeekS(@Adress)) ; Caractères incompréhensibles
  EndIf
  ; ==================================================================
  
  ; Note: if you want to use a local file, change last parameter to "file://" + path + filename
  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Voilà ce que dit la doc MicroSoft:
IWebBrowser2::LocationURL Property

--------------------------------------------------------------------------------

Retrieves the URL of the resource that Microsoft® Internet Explorer is currently displaying.

Syntax

HRESULT IWebBrowser2::get_LocationURL(BSTR *pbstrLocationURL);
Parameters

pbstrLocationURL
Pointer to a variable of type BSTR that receives the URL. The caller frees this buffer with the SysFreeString function.
Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

If the resource is a folder or file on the network or local computer, the name is the full path of the folder or file in the Universal Naming Convention (UNC) format.
Je pensais que ça me retournerait l'adresse "http://www.purebasic.com", mais non.

Un petit coup de main serait le bienvenu! :roll:

PS : J'ai essayé aussi avec "MessageRequester("", Adress)", même punition

Publié : sam. 29/oct./2005 13:29
par KarLKoX

Code : Tout sélectionner

#Win = 0
#Web = 0

Procedure.s BSTR_To_STR(BSTR.l)
Protected tmp.s

  If BSTR = 0 : ProcedureReturn "" : EndIf
  
  lenb = SysStringLen_(BSTR) + 1
  tmp  = Space(lenb)
  If WideCharToMultiByte_(#CP_ACP, 0, BSTR, lenb, @tmp, lenb, #Null, #False) = 0
    ProcedureReturn ""
  EndIf
  SysFreeString_(BSTR)
  
  ProcedureReturn tmp
  
EndProcedure

If OpenWindow(#Win,0,0,600,300,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"WebGadget") And CreateGadgetList(WindowID(0))
  WebGadget(#Web,10,10,580,280,"http://www.purebasic.com")
 
  ; ==================================================================
  Browser.IWebBrowser2 = GetWindowLong_(GadgetID(#Web), #GWL_USERDATA)
  If Browser = 0
    MessageRequester("Erreur","Impossible d'initialiser le navigateur", #MB_OK|#MB_ICONERROR)
    End
  Else
    Repeat
      While WindowEvent(): Wend
      Delay(1)
      Browser\get_Busy(@IsBusy.l)
    Until IsBusy = 0
  EndIf
 
  *Adress.b = AllocateMemory(#MAX_PATH)
  If Browser\get_LocationURL(@*Adress) = #ERROR_SUCCESS
    MessageRequester("", BSTR_To_STR(*Adress) ) ; Caractères incompréhensibles
  EndIf
  ; ==================================================================
 
  ; Note: if you want to use a local file, change last parameter to "file://" + path + filename
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf 

Publié : sam. 29/oct./2005 13:35
par Chris
Euhhhh.......
Ca marche pas :oops:

Ca se lance, et au bout d'un moment, ça plante avec le message d'erreur de Windows :(

Je suis sous XP, et toi?

[Edit]
Le debugger me retourne "Invalid Acess Memory" sur 'ProcedureReturn tmp'

Publié : sam. 29/oct./2005 13:44
par Chris
J'ai trouvé!

Tu avais juste fait une erreur

Code : Tout sélectionner

If WideCharToMultiByte_(#CP_ACP, 0, BSTR, lenb, @a, lenb, #Null, #False) = 0
au lieu de

Code : Tout sélectionner

If WideCharToMultiByte_(#CP_ACP, 0, BSTR, lenb, @tmp, lenb, #Null, #False) = 0
Merci, ça marche :wink:

Publié : sam. 29/oct./2005 13:54
par KarLKoX
J'avais édité entre temps parce que 'a' c'étais pas trop explicite :D

Publié : sam. 29/oct./2005 13:56
par Chris
J'avais pas vu que tu avais édité :lol:
Merci! :)