Sparkies old webgadget interface still works...

Share your advanced PureBasic knowledge/code with the community.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Sparkies old webgadget interface still works...

Post by utopiomania »

Code updated for 5.20+

Sparkies old trick still works with IE7, with and without unicode, if you write the html
to a unicode file (writeString(0, s, #PB_UNICODE) instead of loading it with an "about:.. string.

Just thought I should let you know in case you like to experiment with web-like interfaces like I do..:wink:

Code: Select all

;-initialize
;-
Enumeration
  #WIN1
  #WEB1
EndEnumeration

Global path.s = GetPathPart(ProgramFilename()) + "page.html"
Declare openMainWindow()
Declare.s page1(path.s)

;-program entry
openMainWindow()

;expose the IWebBrowser2 object
webObject.IWebBrowser2 = GetWindowLong_(GadgetID(1),#GWL_USERDATA)

;-program event handler
Repeat
  event = WaitWindowEvent()
  If isBusy ;loading
    webObject\get_ReadyState(@isReady)
    If isReady
      url.s = GetGadgetText(1)
      If FindString(url, "link", 1)
        ;link clicked, cancel navigation
        SetGadgetState(1,#PB_Web_Back)
        ;process the link event
        MessageRequester("Processing", url)
      EndIf
    EndIf
  EndIf
  webObject\get_busy(@isBusy)
Until event = #PB_Event_CloseWindow

;-program exit
;-
DeleteFile(path)
End

Procedure openMainWindow()
  flags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
  If OpenWindow(0, 0, 0, 600, 400, "", flags)
    WebGadget(1, 0, 0, 600, 400, page1(path))
  EndIf
EndProcedure

Procedure.s page1(path.s) 
  s.s = "<html><body><a href = 'link'>Click this link ÆØÅ</a></body></html>"
  ;write the string to a file
  If FileSize(path) = -1
    ;the file doesn't exist yet, create it
    CreateFile(0, path)
    WriteString(0, s, #PB_Unicode)
    CloseFile(0)
  EndIf
  ProcedureReturn "file://" + path
EndProcedure
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You mean I wrote some code and it didn't break :shock: When and where did I do that :?: :? :?: :lol:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply