Resize WebGadget to WebPage size
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Resize WebGadget to WebPage size
Anyone know how to do that programmatically?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Resize WebGadget to WebPage size
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^^)
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^^)
Re: Resize WebGadget to WebPage size
Hi
Code: Select all
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
-
MachineCode
- Addict

- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Resize WebGadget to WebPage size
@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!
PureBasic: Born in 1998 and still going strong to this very day!
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Resize WebGadget to WebPage size
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)
So, I thought "maybe the Window has to be re-sized too", but nope, that makes no difference:
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):
Edit Edit: Ha, my code above does not even work with "http://www.purebasic.com" 
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)
So, I thought "maybe the Window has to be re-sized too", but nope, that makes no difference:
Code: Select all
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 = 1Code: Select all
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 = 1IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Resize WebGadget to WebPage size
So, if the Window is re-arranged so that the resize button is always on screen:
...hitting resize once gets a wrong result, hitting it again gets a different wrong result
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?
Code: Select all
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 = 1Can'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.
If it sounds simple, you have not grasped the complexity.
Re: Resize WebGadget to WebPage size
A good or modern WebSide have no fixed Size 
The WebSide should always use the size of your WebGadget and not the other way
The WebSide should always use the size of your WebGadget and not the other way
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Resize WebGadget to WebPage size
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 WebSide should always use the size of your WebGadget and not the other way
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.
If it sounds simple, you have not grasped the complexity.
Re: Resize WebGadget to WebPage size
In that case you can use the next code By Freak Modified By RASHADThe 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
I posted that code earlier but no harm to post it again
Use SaveAs .mht
Code: Select all
; 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
Re: Resize WebGadget to WebPage size
Egypt my love
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Resize WebGadget to WebPage size
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.
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.
If it sounds simple, you have not grasped the complexity.
Re: Resize WebGadget to WebPage size
Hi IdeasVacuum
If you are not satisfied with MHT go blame M$ (If you can
)
If you are not satisfied with MHT go blame M$ (If you can
Egypt my love
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Resize WebGadget to WebPage size
..... 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.
If it sounds simple, you have not grasped the complexity.
-
Seymour Clufley
- Addict

- Posts: 1266
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: Resize WebGadget to WebPage size
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."
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Resize WebGadget to WebPage size
...That's nothing short of brilliant Seymour, very nice work. 
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.

