Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

variable from gui edit passed to COM_Invoke?


  • Please log in to reply
9 replies to this topic
weblord
  • Members
  • 23 posts
  • Last active: May 10 2018 09:13 PM
  • Joined: 11 Dec 2009
#include COM.ahk
Gui, Add, Button, x6 y50 w120 h20 gButtonGoogle, Google
Gui, Add, Edit, x6 y20 w250 h20 vWord, autohotkey
Gui, Add, Text, x6 y0 w870 h20, Type in a word you're searching in Google.
;Gui, Add, Edit, x266 y30 w610 h490, PUT THE BROWSER HERE

Return

ButtonGoogle:
COM_AtlAxWinInit()
;pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),top,left,width,height, "Shell.Explorer") )  ;left these here just for reference of the parameters
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),269,20,610,490, "Shell.Explorer") )
url:="http://google.com/search?q=%Word%"
COM_Invoke(pwb, "Navigate", url)
Return



GuiClose:
ExitApp

i have something like the script on top.

I'm trying to pass the variable typed from the gui edit box to the COM_Invoke so when the gui button is clicked it will open the url inside the gui browser including the %Word% whatever it contains.

Another is there are other series of button when clicked will go to another search engine url along with the variable but it seems like i can't do it since it won't change the url inside the pwb to another url contained in the button.

if you want to show a shorter version pls. feel free to do so.

don't let the x, y, w, h confuse you, it's just there for me to know i can already position the COM inside GUI.

help me out.

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
MODIFIED, don't know how to start second time new browser
Variable submit works, newstart with clear

#include COM.ahk   ;--- put COM.ak to  C:\Programme\AutoHotkey\Lib and remove here -----
SetWorkingDir %A_ScriptDir%
Gui,2: Add, Button, x6 y50 w120 h20 gButtonGoogle, Google
Gui,2: Add, Button, x6 y90 w120 h20 gReload1,CLEAR
Gui,2: Add, Edit, x6 y20 w250 h20 vWord, autohotkey
Gui,2: Add, Text, x6 y0 w870 h20, Type in a word you're searching in Google.
;Gui,2: Add, Edit, x266 y20 w610 h490, PUT THE BROWSER HERE
Gui,2:show,x0 y0 h510 w900
Return

ButtonGoogle:
Gui,2:submit,nohide
AA=http://google.com/search?q=%Word%
COM_AtlAxWinInit()
;pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),top,left,width,height, "Shell.Explorer") )  ;left these here just for reference of the parameters
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),269,20,610,490, "Shell.Explorer") )
COM_Invoke(pwb, "Navigate", AA)
Return

Reload1:
reload
return

2GuiClose:
Gui,2: Destroy
;      COM_CoUninitialize()
;      COM_AtlAxWinTerm()
ExitApp
just another example
;--------- saved at Donnerstag, 10. April 2008 10:36:26 --------------
MODIFIED = 20080406
FILENAME = EMBED_TEST
;--------- lbbrowse3.dll
;---------------------------------------------------
#NoEnv
#SingleInstance force
setworkingdir, %a_scriptdir%
ifnotexist,lbbrowse3.dll
   goto,LBBROWSE3


transform,S,chr,32    ;space
transform,P,chr,37    ;procent


;--- video example --
;myvideo=http://www.youtube.com/watch?v=82ZuxWbO8QY

lbbHandle := DllCall("LoadLibrary", "str", "lbbrowse3.dll")
;-------- 4GUI ---------------------------------------------
WA=%A_screenwidth%
HA=%A_screenheight%
SW1 :=(WA*99.5)/100    ;width    guishow width
SH1 :=(HA*95)/100      ;height
YB1 :=(SH1*96)/100     ;y-button last line
YB2 :=(SH1*90)/100
;-- position from picture -----
X1 :=(WA*2.5)/100
Y1 :=(HA*2.5)/100
WD :=(WA*94 )/100
HG :=(HA*80 )/100

;------------------------------
Gui,4:Color,000000
AA="Sylvia la torre" "sa kabukiran"
Gui,4:add,button,x10    y%YB1% h20 w100 gYTT1    ,VISAYAN
Gui,4:add,button,x120   y%YB1% h20 w100 gYTT2    ,DANSK
Gui,4:Add,Edit,  x230   y%YB1% h20 w190 vWord1,%AA%
Gui,4:add,button,x430   y%YB1% h20 w100 gYTT3    ,GOOGLE
Gui,4:add,button,x550   y%YB1% h20 w100 gYTT4    ,CLEAR
Gui,4:Font,S16 cteal, Verdana
Gui,4:Add,Text,center x0  y%YB2%  w%SW1% vAL1,
Gui,4: Show, x0 y0 h%SH1% w%SW1%,%Filename%
WinGet, mainGuiHandle, ID, A
AS2=about:blank
DLLCall("lbbrowse3\CreateBrowser","uint",mainGuiHandle,"Int",X1,"Int",Y1,"Int",WD,"Int",HG,"Str",AS2)
DllCall("lbbrowse3\ShowStatusbar","int",0)
OnExit, Cleanup
gosub,YTT1                       ;test-1
Return
;--------------------------------------------

;-------- EXAMPLE-1 MAP  Philippines  -------------------------
YTT1:
M3   =%A_scriptdir%\EMBED_TEST.htm
ifexist,%M3%
   filedelete,%M3%

AA4=<iframe width="%WD%" height="%HG%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=carlota+philippines&sll=-20.492632,-54.600677&sspn=7.528597,10.283203&ie=UTF8&ll=11.043647,123.189697&spn=3.953887,5.141602&z=8&om=1&output=embed&s=AARTsJplSG2Od2sNI-gbn35QUXlu3D0lRQ"></iframe><small><a href="http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=carlota+philippines&sll=-20.492632,-54.600677&sspn=7.528597,10.283203&ie=UTF8&ll=11.043647,123.189697&spn=3.953887,5.141602&z=8&om=1&source=embed" style="color:#0000FF;text-align:left"></a></small>

e1=
(
<HTML>
<HEAD>
<TITLE>MAPS</TITLE>
</HEAD>
<style type="text/css">
  body {
       background-color: #000000;
       margin:  0px;
       padding: 0px;
       color: #fff;
       overflow-y: hidden;
       overflow-x: hidden;
       }
</style>
<BODY>
%AA4%
</object>
</BODY>
</HTML>
)
Fileappend,%E1%`r`n,%M3%

X2 :=(X1)
Y2 :=(Y1)
W2 :=(WD)
H2 :=(HG)
GuiControl,4:Text,AL1,
  DLLCall("lbbrowse3\MoveBrowser","Int",X2,"Int",Y2,"Int",W2,"Int",H2)
  DllCall("lbbrowse3\Navigate", "str",M3)
return

;------------------- TEST-2 DANSK RADIO EVERGREEN ------------------
YTT2:
AX1=http://netradio.dr.dk/content.asp?station=29&#
X2 :=(10)
Y2 :=(10)
W2 :=(680)
H2 :=(290)
GuiControl,4:Text,AL1,Danmark Radio Evergreen
  DLLCall("lbbrowse3\MoveBrowser","Int",X2,"Int",Y2,"Int",W2,"Int",H2)
  DllCall("lbbrowse3\Navigate", "str",AX1)
return
;---------------------------------------------------------------------

YTT3:
Gui,4:submit,nohide
word1=%word1%
stringreplace,B1,word1,%S%,+,all
stringreplace,B2,B1,`",%P%22,all
URL3=http://google.com/search?q=%B2%
X3 :=(X1)
Y3 :=(Y1)
W3 :=(WD)
H3 :=(HG)
GuiControl,4:Text,AL1,
  DLLCall("lbbrowse3\MoveBrowser","Int",X3,"Int",Y3,"Int",W3,"Int",H3)
  DllCall("lbbrowse3\Navigate", "str",URL3)
return





/*
YTT3:
AX1=%MyVideo%
stringreplace,AX1,AX1,/watch?v=,/v/,all
X2 :=(330)
Y2 :=(190)
W2 :=(720)
H2 :=(600)
DLLCall("lbbrowse3\MoveBrowser","Int",X2,"Int",Y2,"Int",W2,"Int",H2)
DllCall("lbbrowse3\Navigate", "str",AX1)
GuiControl,4:Text,AL1,Flickan i Havanna-Evert Taube-Sverige
return
*/



YTT4:
AX1=about:blank
DllCall("lbbrowse3\Navigate", "str",AX1)
return


;---------- CLOSE -----------------------------------------------
cleanup:
4GuiClose:
  Gui,4:Destroy
  DllCall("lbbrowse3\DestroyBrowser")
  DllCall("FreeLibrary", "UInt", lbbHandle)
ExitApp
;------------------------------------------------------------------------------------------------

;================= DOWNLOAD lbbrowse3.dll==========================================
LBBROWSE3:
{
   text31=
(
Download
-lbbrowse3.dll

from
http://www.alycesrestaurant.com/lbbrowse.htm

Want you download this program ?
)
msgbox, 262180, Start URL,%text31%
ifmsgbox,NO
   {
   exitapp
   return
   }
else
   {
   ;run,http://www.alycesrestaurant.com/lbbrowse.htm
   run,http://www.alycesrestaurant.com/zips/browsdll3.zip
   exitapp
   return
   }
}
;==================================================================


garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
hi weblord, just want say, first script above added/ modified

weblord
  • Members
  • 23 posts
  • Last active: May 10 2018 09:13 PM
  • Joined: 11 Dec 2009
thank you very much garry, you have done so much that im asking for. in second example, that is something for me to learn as well in these embedding questions on gui, pls. don't edit it.

i will try it now, see how it works on my end.

weblord
  • Members
  • 23 posts
  • Last active: May 10 2018 09:13 PM
  • Joined: 11 Dec 2009
first code works for me.
but this code
Reload1:
reload
return

also erases the keyword placed on the edit box which is inconvenient for user doing the research, is there a way to clear the url inside
COM_Invoke(pwb, "Navigate", AA)
and replace it with another url?

besides "Navigate" what are the other functions of COM_Invoke for web embeds? i can't find it on the wiki.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
It doesn't sound to me like Reload is the function you're really looking for there. What are you trying to accomplish with the Clear button?

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
sorry weblord , missing time and knowledge ....
the command reload starts script new

just another example, starts 2 url and can scroll
URL1=
first weather shanghai then type manila ... can go back/forward
URL2=
start youtube
should have a stop/clear button ....
MODIFIED=20091020
TAG=scrollto

; this is an example of using COM to get contents from a single framed web page
; this example Relies on the following
; COM.ahk by Sean
;  http://www.autohotkey.com/forum/viewtopic.php?p=146242#146242
; Download COM
;  https://ahknet.autohotkey.com/~Sean/Lib/COM.zip
; COM.ahk should be placed in c:\Program Files\AutoHotkey\lib\com.ahk
; #Include Com.ahk should be in same folder or > %A_programfiles%\AutoHotkey\lib\com.ahk
;----------- see also COM IE etc ........
;http://www.autohotkey.com/forum/viewtopic.php?t=15885.
;http://www.autohotkey.com/forum/topic19225.html


;--#Include Com.ahk should be in same folder or > %A_programfiles%\AutoHotkey\lib\com.ahk
#include com.ahk            ; < remove this if exist in %A_programfiles%\AutoHotkey\lib\com.ahk
;----------------------------------------------------------------------------------------
name1=Shanghai-Weather & Youtube-YeLaiXiang
URL1:="http://weather.yahoo.com/forecast/CHXX0116_c.html"
URL2:="http://www.youtube.com/watch?v=IHzIItZKmD8&fmt=18"
;URL3:="http://netradio.dr.dk/content.asp?station=29&#"              ;dansk radio

SetTitleMatchMode, 2
WinTitle := "%name1%"

WA=%A_screenwidth%
HA=%A_screenheight%

GW:=(WA*99)/100
GH:=(HA*93)/100

BP:=(HA*89)/100


COM_CoInitialize()
If Not   DllCall("GetModuleHandle", "str", "atl" Version)
   DllCall("LoadLibrary"    , "str", "atl" Version)
DllCall("atl" Version "\AtlAxWinInit")
Gui,2:  +LastFound   +Resize
Gui,2: Add, Button, y%BP% h20 gBackward,<
Gui,2: Add, Button, y%BP% h20 gForward ,>
Gui,2: Add, Button, y%BP% h20 gEX1,SHANGHAI
Gui,2: Add, Button, y%BP% h20 gEX2,YOUTUBE
;Gui,2: Add, Button, y%BP% h20 gEX3,DANMARK
X1:=20
Y1:=5
W1:=(WA*40)/100
H1:=(HA*85)/100
pwb1:=COM_AtlAxGetControl(COM_AtlAxCreateContainer(hwnd:=WinExist(),X1,Y1,W1,H1,"Shell.Explorer"))

X2:=(WA*43)/100
Y2:=5
W2:=(WA*55)/100
H2:=(HA*85)/100
pwb2:=COM_AtlAxGetControl(COM_AtlAxCreateContainer(hwnd:=WinExist(),X2,Y2,W2,H2,"Shell.Explorer"))


gui,2:show,x0 y0 w%GW% h%GH% ,%name1%
AX1:="about:blank"
NavigateGui(AX1)

AX1:="about:blank"
NavigateGui2(AX1)

;NavigateGui("c:\test.jpg")
gosub,ex1
Return
;----------------------------------



EX1:
gui,2:submit,nohide
;NavigateGui(URL1)
X1:=2
Y1:=5
W1:=440
H1:=440
SX1:=2
SY1:=272
WinMove,% "ahk_id " COM_AtlAxGetContainer(pwb1),,X1,Y1,W1,H1
NavigateGui(URL1)
scrollto(SX1,SY1)
return


EX2:
gui,2:submit,nohide
NavigateGui2(URL2)
;X1:=20
;Y1:=5
;W1:=(WA*92)/100
;H1:=(HA*87)/100

X1:=(X2)
Y1:=5
W1:=(W2)
H1:=(H2)

SX1:=155
SY1:=130
WinMove,% "ahk_id " COM_AtlAxGetContainer(pwb2),,X1,Y1,W1,H1
scrollto2(SX1,SY1)
return

/*
EX3:
gui,2:submit,nohide
NavigateGui(URL3)
X1:=20
Y1:=5
W1:=(WA*65)/100
H1:=(HA*52)/100
SX1:=0
SY1:=0
WinMove,% "ahk_id " COM_AtlAxGetContainer(pwb1),,X1,Y1,W1,H1
;scrollto(SX1,SY1)
return
*/


backward:
COM_Error(0)
COM_Invoke(pwb1,"GoBack")
;scrollto(2,275)
COM_Error(1)
Return

forward:
COM_Error(0)
COM_Invoke(pwb1,"GoForward")
;scrollto(200,50)
COM_Error(1)
Return



2GuiClose:
ExitApp

;--------------- FUNCTIONS NAVIGATE and SCROLL ------------------------


NavigateGui(url)
{
   global   pwb1
   navTrustedForActiveX   =   0x0400
   COM_Invoke(pwb1,   "Navigate",   url,   navTrustedForActiveX,   "_self")
   ;; ensure navigation is complete new page is loaded
   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {
      If (rdy:=COM_Invoke(pwb1,"readyState") = 4)
         Return
      Sleep,500               ;   sleep half second between cycles
   }
}

scrollTo(x,y)
{
   global pwb1
   IID_IHTMLWindow2      := "{332C4427-26CB-11D0-B483-00C04FD90119}"
   pwin:=COM_QueryService(pwb1,   IID_IHTMLWindow2,   IID_IHTMLWindow2)
   COM_Invoke(pwin,"scrollTo",x,y)
   COM_Release(pwin),   VarSetCapacity(pwin,   0)
   return
}
;=========================================================================================



NavigateGui2(url)
{
   global   pwb2
   navTrustedForActiveX   =   0x0400
   COM_Invoke(pwb2,   "Navigate",   url,   navTrustedForActiveX,   "_self")
   ;; ensure navigation is complete new page is loaded
   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {
      If (rdy:=COM_Invoke(pwb2,"readyState") = 4)
         Return
      Sleep,500               ;   sleep half second between cycles
   }
}


scrollTo2(x,y)
{
   global pwb2
   IID_IHTMLWindow2      := "{332C4427-26CB-11D0-B483-00C04FD90119}"
   pwin:=COM_QueryService(pwb2,   IID_IHTMLWindow2,   IID_IHTMLWindow2)
   COM_Invoke(pwin,"scrollTo",x,y)
   COM_Release(pwin),   VarSetCapacity(pwin,   0)
   return
}


weblord
  • Members
  • 23 posts
  • Last active: May 10 2018 09:13 PM
  • Joined: 11 Dec 2009
yes you're right thanks for the emphasis on that. i don't wish to reload the script while the user is using it.

i don't need the clear button as well to clear entries after a button is pressed, all i want is a series of buttons there as choices that a user can click on and it will "change" the url on the embed.

I don't know how to call that, i searched already there are no examples how to clear url after an COM has been called to call a url.

I also don't need a scrollto, thanks.

can someone help me out?

It doesn't sound to me like Reload is the function you're really looking for there. What are you trying to accomplish with the Clear button?


what i really need is something like the one below, but it should work mine's not. help me make it work.

#include COM.ahk   ;--- put COM.ak to  C:\Programme\AutoHotkey\Lib and remove here -----
SetWorkingDir %A_ScriptDir%
Gui,2: Add, Button, x6 y50 w120 h20 gButtonGoogle, Google
Gui,2: Add, Button, x6 y90 w120 h20 gButtonYahoo,Yahoo
Gui,2: Add, Edit, x6 y20 w250 h20 vWord, autohotkey
Gui,2: Add, Text, x6 y0 w870 h20, Type in a word you're searching in Google.
;Gui,2: Add, Edit, x266 y20 w610 h490, PUT THE BROWSER HERE
Gui,2:show,x0 y0 h510 w900
Return

ButtonGoogle:
Gui,2:submit,nohide
AA=http://google.com/search?q=%Word%
COM_AtlAxWinInit()
;pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),top,left,width,height, "Shell.Explorer") )  ;left these here just for reference of the parameters
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),269,20,610,490, "Shell.Explorer") )
COM_Invoke(pwb, "Navigate", AA)
Return

ButtonYahoo:
Gui,2:submit,nohide
AA=http://search.yahoo.com/search?p=%Word%
COM_AtlAxWinInit()
;pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),top,left,width,height, "Shell.Explorer") )  ;left these here just for reference of the parameters
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(),269,20,610,490, "Shell.Explorer") )
COM_Invoke(pwb, "Navigate", AA)
Return

2GuiClose:
Gui,2: Destroy
;      COM_CoUninitialize()
;      COM_AtlAxWinTerm()
ExitApp

when google's button is clicked it switches to google's page, when yahoo button is clicked it switches to yahoo, all based on what's typed on vWord variable on the edit box, no need for scrollto, no need for reload because the user will still need to copy/paste some results from the results embed to complete his/her study so he needs to switch back and forth from the 2 search engine in this example.

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
seems work now .... thank tank ... and all members from forum for help
#include COM.ahk   ;--- put COM.ak to  C:\Program files\AutoHotkey\Lib and remove here -----
SetWorkingDir %A_ScriptDir%
WA=%A_screenwidth%
HA=%A_screenheight%
GW:=(WA*99)/100
GH:=(HA*93)/100

COM_CoInitialize()
If Not   DllCall("GetModuleHandle", "str", "atl" Version)
   DllCall("LoadLibrary"    , "str", "atl" Version)
DllCall("atl" Version "\AtlAxWinInit")

Gui,2:  +LastFound   +Resize
Gui,2: Add, Edit,   x6   y10 w250 h20 vWord   , autohotkey
Gui,2: Add, Button, x300 y10 w100 h20 gGoogle , Google
Gui,2: Add, Button, x420 y10 w100 h20 gYahoo  ,Yahoo
;Gui,2: Add, Text,   x6 y0  h20, Search

X1:=20
Y1:=40
W1:=(WA*95)/100
H1:=(HA*85)/100
pwb1:=COM_AtlAxGetControl(COM_AtlAxCreateContainer(hwnd:=WinExist(),X1,Y1,W1,H1,"Shell.Explorer"))
gui,2:show,x0 y0 w%GW% h%GH% ,%name1%
AX1:="about:blank"
NavigateGui(AX1)
gosub,google
Return

2GuiClose:
ExitApp


Google:
gui,2:submit,nohide
URL1=http://google.com/search?q=%Word%
NavigateGui(URL1)
return


Yahoo:
gui,2:submit,nohide
URL2=http://search.yahoo.com/search?p=%Word%
NavigateGui(URL2)
return

NavigateGui(url)
{
   global   pwb1
   navTrustedForActiveX   =   0x0400
   COM_Invoke(pwb1,   "Navigate",   url,   navTrustedForActiveX,   "_self")
   ;; ensure navigation is complete new page is loaded
   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {
      If (rdy:=COM_Invoke(pwb1,"readyState") = 4)
         Return
      Sleep,500               ;   sleep half second between cycles
   }
}
return


weblord
  • Members
  • 23 posts
  • Last active: May 10 2018 09:13 PM
  • Joined: 11 Dec 2009
thank you very much, garry for writing a gosub function for me greatly appreciate it. the script worked perfectly.