It is currently Wed May 22, 2013 8:56 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 3:45 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
Anyone know how to do that programmatically?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 3:57 am 
Offline
User
User
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 61
Not without parsing HTML or CSS.
CSS files can be included, so you'd have to follow the paths an search for the right values.

It's probably easier to check the "internal" size of the webgadget (scroll position). But I don't know how to do that.
Probably some Win-Api (hopefully^^)

_________________
PB 4.6b3 - Win7 32


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 1:50 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1468
Hi

Code:
OpenWindow(0, 0, 0, 1024,840, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
WebGadget(0, 10, 10, 300, 65, "http://www.purebasic.com")
ButtonGadget(1,10,810,60,25,"Resize")

Repeat
  Select WaitWindowEvent()
     
      Case #PB_Event_CloseWindow
          Quit = 1
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
               SetGadgetAttribute(0, #PB_Web_ScrollX, 2000)
               SetGadgetAttribute(0, #PB_Web_ScrollY, 2000)
               ResizeGadget(0,10,10,GetGadgetAttribute(0, #PB_Web_ScrollY)+60,GetGadgetAttribute(0, #PB_Web_ScrollY)+60)
          EndSelect
  EndSelect
Until Quit = 1


_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 3:19 pm 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1459
@RASHAD, your example fails miserably with www.google.com (sorry to say).

_________________
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 4:11 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
Hi Rashad

Well, funny thing is that the code only wants to work with "http://www.purebasic.com". I have tried several websites (mostly home pages) now and they all re-size to a small 45x45 square (including this forum) :shock:

So, I thought "maybe the Window has to be re-sized too", but nope, that makes no difference:

Code:
Enumeration
#Win
#Web
#Btn
EndEnumeration

  OpenWindow(#Win,  0,   0, 1024, 840, "Resize WebGadget", #PB_Window_SystemMenu)
   WebGadget(#Web, 10,  10,  300, 300, "http://www.qinbiying.co.uk")
ButtonGadget(#Btn, 10, 810,   60,  25, "Resize")

Repeat

  Select WaitWindowEvent()
     
      Case #PB_Event_CloseWindow
          Quit = 1
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case #Btn
               SetGadgetAttribute(#Web, #PB_Web_ScrollX, 2000)
               SetGadgetAttribute(#Web, #PB_Web_ScrollY, 2000)

               iNewW.i = GetGadgetAttribute(#Web, #PB_Web_ScrollX) + 60
               iNewH.i = GetGadgetAttribute(#Web, #PB_Web_ScrollY) + 60

               ResizeWindow(#Win,0,0,iNewW + 10,iNewH + 10)
               ResizeGadget(#Web,10,10,iNewW,iNewH)
          EndSelect
  EndSelect

Until Quit = 1


Edit: I was wondering if GetGadgetAttribute with #PB_Web_ScrollX/Y was the culprit, but seems it could be SetGadgetAttribute, which I thought should set the WebGadget scroll bars to a specific position, but hard to tell if that works or not (not knowing the range):

Code:
Enumeration
#Win
#Web
#Btn
EndEnumeration

Procedure OpenWin()
;------------------
  OpenWindow(#Win,  0,   0, 1024, 840, "Resize WebGadget", #PB_Window_SystemMenu)
   WebGadget(#Web, 10,  10,  500, 300, "http://www.qinbiying.co.uk")
SetGadgetAttribute(#Web, #PB_Web_ScrollX, 200)
SetGadgetAttribute(#Web, #PB_Web_ScrollY, 200)
ButtonGadget(#Btn, 10, 810,   60,  25, "Resize")

EndProcedure

OpenWin()

Repeat

  Select WaitWindowEvent()
     
      Case #PB_Event_CloseWindow
          Quit = 1
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case #Btn
               SetGadgetAttribute(#Web, #PB_Web_ScrollX, 2000)
               SetGadgetAttribute(#Web, #PB_Web_ScrollY, 2000)

               iNewW.i = GetGadgetAttribute(#Web, #PB_Web_ScrollX) + 60
               iNewH.i = GetGadgetAttribute(#Web, #PB_Web_ScrollY) + 60

               ResizeWindow(#Win,0,0,iNewW + 10,iNewH + 10)
               ResizeGadget(#Web,10,10,iNewW,iNewH)
          EndSelect
  EndSelect

Until Quit = 1


Edit Edit: Ha, my code above does not even work with "http://www.purebasic.com" :mrgreen:

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 4:38 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
So, if the Window is re-arranged so that the resize button is always on screen:

Code:
Enumeration
#Win
#Web
#Btn
EndEnumeration

Procedure OpenWin()
;------------------
  OpenWindow(#Win,  0,   0,  520, 350, "Resize WebGadget", #PB_Window_SystemMenu)
   WebGadget(#Web, 10,  40,  500, 300, "http://www.purebasic.com")
ButtonGadget(#Btn, 10,  10,   60,  25, "Resize")

EndProcedure

OpenWin()

Repeat

  Select WaitWindowEvent()
     
      Case #PB_Event_CloseWindow
          Quit = 1
     
      Case #PB_Event_Gadget
          Select EventGadget()
           Case #Btn
               SetGadgetAttribute(#Web, #PB_Web_ScrollX, 2000)
               SetGadgetAttribute(#Web, #PB_Web_ScrollY, 2000)

               iNewW.i = GetGadgetAttribute(#Web, #PB_Web_ScrollX)
               iNewH.i = GetGadgetAttribute(#Web, #PB_Web_ScrollY)

               ResizeWindow(#Win,0,0,iNewW + 20,iNewH + 50)
               ResizeGadget(#Web,10,40,iNewW,iNewH)
          EndSelect
  EndSelect

Until Quit = 1


...hitting resize once gets a wrong result, hitting it again gets a different wrong result :shock:

Can't work out an API approach from the MSDN info, but also it might be that the WebGadget is a special PB control anyway?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 4:48 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
A good or modern WebSide have no fixed Size :mrgreen:
The WebSide should always use the size of your WebGadget and not the other way :wink:

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 5:08 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
Quote:
The WebSide should always use the size of your WebGadget and not the other way

Never happens though, unless the site has a mobile version. Some dynamic sites can get too big height-wise, requiring too much scrolling don't you think? I'm all for limiting web page dimensions to reasonable size and most are.

The reason I want the Gadget to resize is to be able to efficiently grab a snapshot image of the web page. The web gadget for this purpose would be hidden.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 6:36 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1468
Quote:
The reason I want the Gadget to resize is to be able to efficiently grab a snapshot image of the web page. The web gadget for this purpose would be hidden


In that case you can use the next code By Freak Modified By RASHAD
I posted that code earlier but no harm to post it again
Use SaveAs .mht

Code:
; Constants for the ExecWB() method of IWebBrowser2

  Enumeration 1
    #OLECMDID_OPEN         
    #OLECMDID_NEW         
    #OLECMDID_SAVE         
    #OLECMDID_SAVEAS         
    #OLECMDID_SAVECOPYAS   
    #OLECMDID_PRINT         
    #OLECMDID_PRINTPREVIEW   
    #OLECMDID_PAGESETUP     
    #OLECMDID_SPELL         
    #OLECMDID_PROPERTIES     
    #OLECMDID_CUT           
    #OLECMDID_COPY           
    #OLECMDID_PASTE           
    #OLECMDID_PASTESPECIAL   
    #OLECMDID_UNDO           
    #OLECMDID_REDO             
    #OLECMDID_SELECTALL       
    #OLECMDID_CLEARSELECTION 
    #OLECMDID_ZOOM             
    #OLECMDID_GETZOOMRANGE     
    #OLECMDID_UPDATECOMMANDS   
    #OLECMDID_REFRESH           
    #OLECMDID_STOP             
    #OLECMDID_HIDETOOLBARS   
    #OLECMDID_SETPROGRESSMAX   
    #OLECMDID_SETPROGRESSPOS   
    #OLECMDID_SETPROGRESSTEXT   
    #OLECMDID_SETTITLE           
    #OLECMDID_SETDOWNLOADSTATE 
    #OLECMDID_STOPDOWNLOAD   
    #OLECMDID_ONTOOLBARACTIVATED
    #OLECMDID_FIND             
    #OLECMDID_DELETE           
    #OLECMDID_HTTPEQUIV       
    #OLECMDID_HTTPEQUIV_DONE   
    #OLECMDID_ENABLE_INTERACTION
    #OLECMDID_ONUNLOAD         
    #OLECMDID_PROPERTYBAG2     
    #OLECMDID_PREREFRESH       
    #OLECMDID_SHOWSCRIPTERROR
    #OLECMDID_SHOWMESSAGE     
    #OLECMDID_SHOWFIND       
    #OLECMDID_SHOWPAGESETUP   
    #OLECMDID_SHOWPRINT       
    #OLECMDID_CLOSE         
    #OLECMDID_ALLOWUILESSSAVEAS
    #OLECMDID_DONTDOWNLOADCSS
    #OLECMDID_UPDATEPAGESTATUS
    #OLECMDID_PRINT2
    #OLECMDID_PRINTPREVIEW2
    #OLECMDID_SETPRINTTEMPLATE
    #OLECMDID_GETPRINTTEMPLATE
  EndEnumeration

Enumeration 0
  #OLECMDEXECOPT_DODEFAULT     
  #OLECMDEXECOPT_PROMPTUSER       
  #OLECMDEXECOPT_DONTPROMPTUSER   
  #OLECMDEXECOPT_SHOWHELP       
EndEnumeration

; Variant stuff

Enumeration
  #VT_EMPTY           = 0
  #VT_NULL            = 1
  #VT_I2              = 2
  #VT_I4              = 3
  #VT_R4              = 4
  #VT_R8              = 5
  #VT_CY              = 6
  #VT_DATE            = 7
  #VT_BSTR            = 8
  #VT_DISPATCH        = 9
  #VT_ERROR           = 10
  #VT_BOOL            = 11
  #VT_VARIANT         = 12
  #VT_UNKNOWN         = 13
  #VT_DECIMAL         = 14
  #VT_I1              = 16
  #VT_UI1             = 17
  #VT_UI2             = 18
  #VT_UI4             = 19
  #VT_I8              = 20
  #VT_UI8             = 21
  #VT_INT             = 22
  #VT_UINT            = 23
  #VT_VOID            = 24
  #VT_HRESULT         = 25
  #VT_PTR             = 26
  #VT_SAFEARRAY       = 27
  #VT_CARRAY          = 28
  #VT_USERDEFINED     = 29
  #VT_LPSTR           = 30
  #VT_LPWSTR          = 31
  #VT_RECORD          = 36
  #VT_FILETIME        = 64
  #VT_BLOB            = 65
  #VT_STREAM          = 66
  #VT_STORAGE         = 67
  #VT_STREAMED_OBJECT = 68
  #VT_STORED_OBJECT   = 69
  #VT_BLOB_OBJECT     = 70
  #VT_CF              = 71
  #VT_CLSID           = 72
  #VT_BSTR_BLOB       = $0fff
  #VT_VECTOR          = $1000
  #VT_ARRAY           = $2000
  #VT_BYREF           = $4000
  #VT_RESERVED        = $8000
  #VT_ILLEGAL         = $ffff
  #VT_ILLEGALMASKED   = $0fff
  #VT_TYPEMASK        = $0fff
EndEnumeration

Structure BRECORD
  *pvRecord.l
  *pRecInfo.IRecordInfo
EndStructure


If OpenWindow(0, 0, 0, 600, 600, "WebBRowser", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)
   
    WebGadget(0, 10, 10, 580, 555, "http://www.google.com/")
    WebObject.IWebBrowser2 = GetWindowLongPtr_(GadgetID(0), #GWL_USERDATA)
   
    ButtonGadget(1, 10, 570, 100, 20, "Save as:")
    StringGadget(2, 115, 570, 300, 20, "C:\Test.html")
    ButtonGadget(3, 425, 570, 80, 20, "Copy")
    ButtonGadget(4, 510, 570, 80, 20, "Print")
   
Repeat
  Select WaitWindowEvent()
     
        Case #PB_Event_CloseWindow
          Quit = 1
       
        Case #PB_Event_Gadget
          Select EventGadget()
           Case 1           
              filename$ = GetGadgetText(2)
             
              ; convert to unicode
              filename_Unicode = AllocateMemory(Len(filename$)*2+2)
              MultiByteToWideChar_(#CP_ACP, 0, @filename$, -1, filename_Unicode, Len(filename$)*2+2)               
             
              ; create bstr
              filename_BSTR = SysAllocString_(filename_Unicode)
             
              ; fill variant
              VariantIn.VARIANT
              VariantIn\vt = #VT_BSTR
              VariantIn\bstrVal = filename_BSTR
                     
              If WebObject\ExecWB(#OLECMDID_SAVEAS, #OLECMDEXECOPT_PROMPTUSER, @VariantIn, 0) = #S_OK
                MessageRequester("","Saved successfully")
              Else
                MessageRequester("","could not save file")
              EndIf
             
              FreeMemory(filename_Unicode)
              SysFreeString_(filename_BSTR)
             
           Case 3
              WebObject\ExecWB(#OLECMDID_SELECTALL,#OLECMDEXECOPT_DONTPROMPTUSER,0,0)  ;Select All
              WebObject\ExecWB(#OLECMDID_COPY, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
              WebObject\ExecWB(#OLECMDID_CLEARSELECTION,#OLECMDEXECOPT_DONTPROMPTUSER,0,0)
              MessageRequester("", GetClipboardText(), 0)
             
           Case 4
              WebObject\ExecWB(#OLECMDID_CLOSE, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
              ;WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)   ;No PrintRequester
          EndSelect
         
        Case #PB_Event_SizeWindow
            GetClientRect_(WindowID(0),r.RECT)
            ResizeGadget(0,10,10,r\right-r\left-20,r\bottom-r\top-45)
            ResizeGadget(1,10,r\bottom-30,100,20)
            ResizeGadget(2,120,r\bottom-30,300,20)
            ResizeGadget(3,r\right-175,r\bottom-30,80,20)
            ResizeGadget(4,r\right-90,r\bottom-30,80,20)
               
  EndSelect
Until Quit = 1
 
EndIf



_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 8:56 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1468
Hi IdeasVacuum

[url]
viewtopic.php?f=12&t=49461
[/url]

_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 13, 2012 11:05 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
That is excellent Rashad, thank you. Saving as an MHT file is good (added advantage of being able to use it as an email).

MHT Suits my purpose, but for anyone reading this, the MHT format has not kept up with the rest of the web world so only the simple web pages are captured 100%.

Saving as HTML Complete on the other hand does completely preserve the page, but obviously not as a single file.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Wed Mar 14, 2012 3:42 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1468
Hi IdeasVacuum :mrgreen:
If you are not satisfied with MHT go blame M$ (If you can :P )

_________________
Egypt my love


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Wed Mar 14, 2012 4:16 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
..... they seem to have abandoned MHT. Great shame, years ago I used it to quickly make email news letters using that format (renamed to .eml). Mind you, MS Outlook/Express can use those files but Thunderbird does not like them.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Tue Mar 20, 2012 3:09 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 28, 2007 9:13 am
Posts: 923
Location: Edinburgh
MHT is dying a death because DataURI means that all resources can be included in the page as an HTML file. This code does it.

_________________
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."


Top
 Profile  
 
 Post subject: Re: Resize WebGadget to WebPage size
PostPosted: Thu Mar 22, 2012 4:24 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2854
Location: Wales, UK
...That's nothing short of brilliant Seymour, very nice work. 8)

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye