Page 1 of 1

Posted: Tue Feb 04, 2003 4:36 am
by BackupUser
Restored from previous forum. Originally posted by pusztry.

How will I know if the page is finished loading in the webgadget?
Second, How can I tell the webgadget to go to the IE home page?
Third, are there ANY events thrown by the webgadget?
I am looking for a way to build a little browser but I can't find some of the key features from the instruction manual. Do I need any dll's that aren't included on a normal install of windows?

Thanks in advanced,


- Ryan
RJP Computing

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra

Posted: Tue Feb 04, 2003 8:45 am
by BackupUser
Restored from previous forum. Originally posted by fred.

You need th ATL.dll if you want to use the WebGadget (located in the compilers\ directory)

Fred - AlphaSND

Posted: Tue Feb 04, 2003 9:34 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.

Hello Ryan.

1. If your page is wider than the web gadget, a slider bar will pop up on the right of the gadget. You can watch that resizing itself as the page loads so you will see when it has finished.

2. You can tell the web gadget to go the the home page the same way that you loaded the other pages into it. SetGadgetText(#YourGadget, "http://www.ie.com")

3. The manual says that even the web gadget returns an id to EventGadgetID()

Since it also says that you can use the below to do some action on the gadget, maybe you can check the EventGadgetId for the gadget to see if it returned an ID when any of those actions were done to it, thus checking what and when it happened.

From the manual:

- SetGadgetState(): Do some action on the gadget. The following constants are valid:

#PB_Web_Back : One step back in the navigation.
#PB_Web_Forward: One step forward in the navigation.
#PB_Web_Stop : Stop the current page loading
#PB_Web_Refresh: Refresh the current page



Fangles woz ear orright den?

Posted: Tue Feb 04, 2003 4:18 pm
by BackupUser
Restored from previous forum. Originally posted by pusztry.

Here is a snippet from my program and I never get the webgadget to fire any events.

Code: Select all

WebGadget(#Gadget_Main_Form_Web,0,23,799,533,"[url]http://www.google.com[/url]")...
Select EventGadgetID()
          Case #Gadget_Main_Form_Back_Button
            SetGadgetState(#Gadget_Main_Form_Web, #PB_Web_Back)
          Case #Gadget_Main_Form_Forward_Button
            SetGadgetState(#Gadget_Main_Form_Web, #PB_Web_Forward)
          Case #Gadget_Main_Form_Stop_Button
            SetGadgetState(#Gadget_Main_Form_Web, #PB_Web_Stop)
          Case #Gadget_Main_Form_Refresh_Button
            SetGadgetState(#Gadget_Main_Form_Web, #PB_Web_Refresh)
          Case #Gadget_Main_Form_Web
          Debug "Web Event"
            SetGadgetText(#Gadget_Main_Form_Address_ComboBox, GetGadgetText(#Gadget_Main_Form_Web))

- Ryan
RJP Computing

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra

Posted: Tue Feb 04, 2003 9:13 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

I've played with the WebGadget.pb example which comes with PB, here are the results:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MiniBrowser
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; This program requiers the Microsoft freely distribuable 
; ATL.dll shared library.
;

; Modified by El_Choni

Procedure Error(message.s, fatal.b)
  ErrorBuffer$ = Space(256)
  FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), 0, ErrorBuffer$, Len(ErrorBuffer$), 0)
  MessageRequester("Error", message+Chr(10)+Chr(10)+ErrorBuffer$, 0)
  If fatal
    End
  EndIf
EndProcedure

Global hComboBox, WindowID, OldComboEditProc, WindowWidth, hStatus, sz.SIZE

#BackButton = 1
#NextButton = 2
#StopButton = 3
#EditableComboBox = 4
#GoButton = 5
#WebGadget = 10

Dim ButtonText$(3)
ButtonText$(0) = "Back"
ButtonText$(1) = "Next"
ButtonText$(2) = "Stop"

#gap = 5:#gap2 = #gap*2:#gap3 = #gap*3:#gap4 = #gap*4

Procedure GetTextWidthHeight(hWnd, text$)
  hDC = GetDC_(hWnd)
  OldObject = SelectObject_(hDC, GetStockObject_(#DEFAULT_GUI_FONT))
  GetTextExtentPoint32_(hDC, text$, Len(text$), sz)
  SelectObject_(hDC, OldObject)
  ReleaseDC_(hWnd, hDC)
EndProcedure

Procedure ResizeWebWindow(newWindowWidth, newWindowHeight)
  GetTextWidthHeight(WindowID, "Wj")
  deltaX = newWindowWidth-WindowWidth
  WindowWidth = newWindowWidth
  GetWindowRect_(hStatus, rc.RECT)
  ResizeGadget(#WebGadget, -1, -1, WindowWidth, newWindowHeight-(#gap4+sz\cy)-(rc\bottom-rc\top))
  ResizeGadget(#EditableComboBox, -1, -1, GadgetWidth(#EditableComboBox)+deltaX, -1)
  ResizeGadget(#GoButton, WindowWidth-(GadgetWidth(#GoButton)+#gap), -1, -1, -1)
  ResizeGadget(6, -1, -1, WindowWidth, -1)
EndProcedure

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_SIZE
      If wParam#SIZE_MINIMIZED
        UpdateStatusBar(0)
        ResizeWebWindow(lParam&$ffff, lParam>>16)
        result = 1
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

Procedure$ FixURL(line$)
  If FindString(line$, "://", 0)
    URL$ = line$
  Else
    URL$ = "http://"+line$
  EndIf
  ProcedureReturn URL$
EndProcedure

#CB_ERR = -1
Procedure ComboEditProc(hWnd, uMsg, wParam, lParam)
  result = 0
  Select uMsg
    Case #WM_CHAR
      CallWindowProc_(OldComboEditProc, hWnd, uMsg, wParam, lParam)
      GadgetText$ = GetGadgetText(#EditableComboBox)
      MatchingItemIndex = SendMessage_(hComboBox, #CB_FINDSTRING, 0, GadgetText$)
      If MatchingItemIndex#CB_ERR
        SetGadgetState(#EditableComboBox, MatchingItemIndex)
        SendMessage_(hWnd, #EM_SETSEL, Len(GadgetText$), Len(GetGadgetText(#EditableComboBox)))
      EndIf
      result = 0
    Case #WM_KEYDOWN
      If wParam=#VK_RETURN
        GadgetText$ = GetGadgetText(#EditableComboBox)
        SetGadgetText(#WebGadget, FixURL(GadgetText$))
        If SendMessage_(hComboBox, #CB_FINDSTRINGEXACT, 0, GadgetText$)=#CB_ERR
          AddGadgetItem(#EditableComboBox, -1, GadgetText$)
          GetTextWidthHeight(hComboBox, GadgetText$)
          LockWindowUpdate_(hComboBox)
          ResizeGadget(#EditableComboBox, -1, -1, -1, CountGadgetItems(#EditableComboBox)*(sz\cy))
          LockWindowUpdate_(0)
        EndIf
      EndIf
      result = CallWindowProc_(OldComboEditProc, hWnd, uMsg, wParam, lParam)
    Default
      result = CallWindowProc_(OldComboEditProc, hWnd, uMsg, wParam, lParam)
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 100, 100, 500, 300, #PB_Window_Invisible|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget, "PureBasic MiniBrowser v1.0")
  WindowID = WindowID()
  WindowWidth = WindowWidth()
  hStatus = CreateStatusBar(0, WindowID)
  If hStatus
    StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)
  Else
    Error("Can't create status bar.", 0)
  EndIf
  If CreateGadgetList(WindowID)
    For i=#BackButton To #StopButton
      GetTextWidthHeight(WindowID, ButtonText$(i-#BackButton))
      If sz\cx=>PreviousWidth
        ButtonWidth = sz\cx+#gap2
        PreviousWidth = ButtonWidth
      EndIf
    Next i
    For i=#BackButton To #StopButton
      ButtonX = #gap+((i-#BackButton)*(ButtonWidth+#gap))
      ButtonGadget(i, ButtonX, #gap, ButtonWidth, sz\cy+#gap2, ButtonText$(i-#BackButton))
    Next i
    HomePage$ = "[url]http://www.purebasic.com[/url]"
    hComboBox = ComboBoxGadget(#EditableComboBox, #gap+(#StopButton*(ButtonWidth+#gap)), #gap, 0, 200, #PB_ComboBox_Editable)
    AddGadgetItem(#EditableComboBox, 0, HomePage$)
    SetGadgetState(#EditableComboBox, 0)
    hComboEdit = GetWindow_(hComboBox, #GW_CHILD)
    OldComboEditProc = SetWindowLong_(hComboEdit, #GWL_WNDPROC, @ComboEditProc())
    GetTextWidthHeight(WindowID, "Go")
    ComboBoxWidth = WindowWidth-#gap-(((ButtonWidth+#gap)*#StopButton)+sz\cx+#gap4)
    ButtonGadget(#GoButton, GadgetX(#EditableComboBox)+ComboBoxWidth+#gap, #gap, sz\cx+#gap2, sz\cy+#gap2, "Go")
    ResizeGadget(#EditableComboBox, -1, -1, ComboBoxWidth, -1)
    If WebGadget(#WebGadget, 0, #gap4+sz\cy, 0, 0, HomePage$)=0:    Error("ATL.dll not found.", 0):End:EndIf
    Frame3DGadget(6, 0, #gap4+sz\cy, WindowWidth, 2, "", 2) ; Nice little separator
    ResizeWebWindow(WindowWidth, WindowHeight())
    HideWindow(0, 0)
    SetWindowCallback(@WndProc())
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          Select EventGadgetID()
            Case #BackButton
              SetGadgetState(#WebGadget, #PB_Web_Back)
            Case #NextButton
              SetGadgetState(#WebGadget, #PB_Web_Forward)
            Case #StopButton
              SetGadgetState(#WebGadget, #PB_Web_Stop)
            Case #EditableComboBox
              If EventType()=1
                SetGadgetText(#WebGadget, FixURL(GetGadgetText(#EditableComboBox)))
              EndIf
            Case #GoButton
              SetGadgetText(#WebGadget, FixURL(GetGadgetText(#EditableComboBox)))
          EndSelect
      EndSelect
    Until Event=#PB_Event_CloseWindow
  Else
    Error("Can't create GadgetList.", 1)
  EndIf
Else
  Error("Can't create main window.", 1)
EndIf
End
I hope this helps, bye,

El_Choni

Posted: Wed Feb 05, 2003 5:08 pm
by BackupUser
Restored from previous forum. Originally posted by Midebor.

Hi,

I've modified the PB minibrowser to use a command line parameter as
Home URL. You can put different instances on your desktop and define
opening URL by adding http://domain.com/ as command line parameter in the properties of your desktop icon.
This makes the program more universaly usable ...

;
; ------------------------------------------------------------
;
; PureBasic - MiniBrowser
;
; (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; This program requiers the Microsoft freely distribuable
; ATL.dll shared library.
; Modified by Midebor using commandline parameter as Home URL
; Compile with "%FILE%" as argument
;
URL$=ProgramParameter()

Procedure ResizeWebWindow()
ResizeGadget(10, -1, -1, WindowWidth(), WindowHeight()-52)
ResizeGadget(4, -1, -1, WindowWidth()-185, -1)
ResizeGadget(5, WindowWidth()-25, -1, -1, -1)
ResizeGadget(6, -1, -1, WindowWidth(), -1)
EndProcedure


Procedure SizeCallback(WindowID, Message, wParam, lParam)

ReturnValue = #PB_ProcessPureBasicEvents

If Message = #WM_SIZE
UpdateStatusBar(0)
ResizeWebWindow()
ReturnValue = 1
EndIf

ProcedureReturn ReturnValue
EndProcedure


If OpenWindow(0, 100, 100, 500, 300, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "PureBasic MiniBrowser v1.0")

CreateStatusBar(0, WindowID())
StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)

CreateGadgetList(WindowID())
ButtonGadget(1, 0, 0, 50, 25, "Back")
ButtonGadget(2, 50, 0, 50, 25, "Next")
ButtonGadget(3, 100, 0, 50, 25, "Stop")

StringGadget(4, 155, 5, 0, 20, URL$)

ButtonGadget(5, 0, 0, 25, 25, "Go")

Frame3DGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator

If WebGadget(10, 0, 31, 0, 0, URL$) = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf

AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)

ResizeWebWindow()

SetWindowCallback(@SizeCallback())

Repeat
Event = WaitWindowEvent()

Select Event
Case #PB_Event_Gadget

Select EventGadgetID()
Case 1
SetGadgetState(10, #PB_Web_Back)

Case 2
SetGadgetState(10, #PB_Web_Forward)

Case 3
SetGadgetState(10, #PB_Web_Stop)

Case 5
SetGadgetText(10, GetGadgetText(4))

EndSelect

Case #PB_Event_Menu ; We only have one shortcut
SetGadgetText(10, GetGadgetText(4))

EndSelect

Until Event = #PB_Event_CloseWindow

EndIf


Regards,
Michel