Page 1 of 1

(Solved)how to open url webpage by clicking an image??

Posted: Tue Jun 04, 2019 6:35 pm
by LESTROSO
how to open url webpage by clicking an image?? i'm using macos x 10.13.6 and windows 10 ....

hi, i'm trying to launch a web page clicking on a credit image from my purebasic program...but without success ...can you help me please??

Best regards,Lestroso :oops:

Re: how to open url webpage by clicking an image??

Posted: Tue Jun 04, 2019 6:43 pm
by RSBasic

Code: Select all

EnableExplicit

CreateImage(1, 100, 100, 24, RGB(255, 0, 0))

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ImageGadget(1, 10, 10, 100, 100, ImageID(1), 0)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            RunProgram("https://www.google.de")
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Or:

Code: Select all

EnableExplicit

CreateImage(1, 100, 100, 24, RGB(255, 0, 0))

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(1, 10, 10, 100, 100, 0)
  If StartDrawing(CanvasOutput(1))
    DrawImage(ImageID(1), 0, 0)
    StopDrawing()
  EndIf
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Select EventType()
              Case #PB_EventType_LeftClick
                RunProgram("https://www.google.de")
            EndSelect
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf

Re: how to open url webpage by clicking an image??

Posted: Tue Jun 04, 2019 8:04 pm
by Shardik
LESTROSO wrote:i'm using macos x 10.13.6 and windows 10 ....
RSBasic's examples only work on Windows. On MacOS you have to use

Code: Select all

RunProgram("Open", "https://www.google.de", "")
In this example in the German forum I demonstrated how to display a website in the default browser on Linux, MacOS and Windows.

Re: how to open url webpage by clicking an image??

Posted: Wed Jun 05, 2019 3:18 pm
by LESTROSO
I thank you very much!! it's all ok!! you have solved my problem....Best Regards, Lestroso :) :) :)

Re: how to open url webpage by clicking an image??

Posted: Thu Jun 06, 2019 9:44 pm
by LESTROSO
Dear friends...... i try to code this problem but i cant have success with it....My Simple problem is to click an image jpg and open the browser to google... i try this software..can you help me??? please ??? Lestroso :oops: :oops:

Code: Select all

Global FasaImage
Procedure testaimmagini()
 
  Select EventGadget()
          
       Case #Fasaimage
                If EventType() = #PB_EventType_Change
                  Select GetGadgetState(#Fasaimage) 
                                              
                    Case 1
                      Debug #fasaimage
            RunProgram("Open", "https://www.google.com", "") ; this for macintosh
            ;version windows RunProgram("https://www.google.de", "")

                 EndSelect

               EndIf
           EndSelect
           
EndProcedure


Re: how to open url webpage by clicking an image??

Posted: Thu Jun 06, 2019 9:56 pm
by wombats
It is best if you post a runnable program so that we can better see what you are trying to do. It's not clear what you're trying to do there - what type of gadget is #Fasaimage? Why do you check the EventGadget() in a procedure - is it bound to a gadget's event?

Re: how to open url webpage by clicking an image??

Posted: Fri Jun 07, 2019 2:56 am
by TI-994A
LESTROSO wrote:...to click an image jpg and open the browser to google...
This should do it:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(0, 0, 0, 200, 200, "ImageGadget", wFlags)
  yourImage = CreateImage(#PB_Any, 180, 180, 32, #Red)  
  imageGadget = ImageGadget(#PB_Any,  10, 10, 10, 10, ImageID(yourImage))
  Repeat    
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        appQuit = 1  
      Case #PB_Event_Gadget
        Select EventGadget()
          Case imageGadget
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS              
              RunProgram("Open", "https://www.google.com", "")
            CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
              RunProgram("https://www.google.de")
            CompilerEndIf            
        EndSelect       
    EndSelect
  Until appQuit
EndIf

Re: how to open url webpage by clicking an image??

Posted: Fri Jun 07, 2019 6:36 pm
by LESTROSO
Dear TI-994A,...your software example...clear my problem...i tryed your software and it works fine! I thank you very much...best regards, Lestroso :D :D :D