Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Child window cannot display webpage
#1
I want to open the Yahoo website in the shortcut menu. After 20 seconds, the window will close automatically, but the webpage cannot be displayed. I hope everyone can provide some suggestions. Thanks in advance.  Smile

Macro Child window
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 900 432 "Dialog"
;4 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "4"
str ax4SHD
ax4SHD="http://www.quickmacros.com/help/QM_Help/IDH_OVERVIEW.html"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SetTimer hDlg 1 100 0
,SHDocVw.WebBrowser we4
,we4._getcontrol(id(4 hDlg))
,we4._setevents("sub.we4")
,;we4.Navigate("http://www.quickmacros.com/help/QM_Help/IDH_OVERVIEW.html")
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(4 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages

sel message
,case WM_RBUTTONDOWN
,str s=
,;1 yahoo
,;-
,;2 Bing

,
,MenuPopup x.AddItems(s)
,int i=x.Show
,sel i
,,case 1
,,sub.Dialog2(hwnd "www.yahoo.com")
,,20
,,clo
,,case 2
,,sub.Dialog2(hwnd "www.bing.com")
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)
,
,;case ...

ret R

#sub we4_NewWindow3
function IDispatch&ppDisp @&Cancel dwFlags BSTR'bstrUrlContext BSTR'bstrUrl SHDocVw.IWebBrowser2'we3

int hDlg2=sub.Dialog2
SHDocVw.WebBrowser d2_we3._getcontrol(id(3 hDlg2))
ppDisp=d2_we3



#sub Dialog2
function# [hwndOwner] [~url]

str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 900 432 "Dialog2"
;3 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!empty(url))
,ax3SHD=url
ret ShowDialog(dd &sub.DlgProc2 &controls hwndOwner 1) ;;modeless dialog


#sub DlgProc2
function# hDlg message wParam lParam
int- t_hdlg

sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3._setevents("sub.we3")
,t_hdlg=hDlg
,DT_SetAutoSizeControls hDlg "3s"
,SetTimer hDlg 1 100 0
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_CLOSE
,DT_Ok(hDlg)
ret
;messages2
sel wParam
,case IDOK
,ifk(Y)
,,key Y           ;; Enter
,,ret 0
,case IDCANCEL
,ret 0

ret 1

#sub we3_WindowClosing
function @IsChildWindow @&Cancel ;;SHDocVw.IWebBrowser2'we3

Cancel=1
int- t_hdlg
clo t_hdlg
#2
The second dialog hangs because of the 20.
Remove
20
clo
and replace with a timer that closes the dialog.
#3
I don't know the timer of the dialog. I checked some information about 【SetTimer】 but I don't know how to use it.  Huh
#4
Code in #sub DlgProc2.
Added lines are marked with ;;<----



Macro Macro2
Code:
Copy      Help
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3._setevents("sub.we3")
,t_hdlg=hDlg
,DT_SetAutoSizeControls hDlg "3s"
,SetTimer hDlg 1 100 0
,SetTimer hDlg 2 20000 0 ;;<----
,
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,,case 2 ;;<----
,,clo hDlg ;;<----
#5
Thank you very much, I really admire your programming level.  Smile

Now there is a problem,

 all the child windows will close after 20 seconds,  but I want to set the wait time for each open window separately.

How to change the code  Huh

Macro wait
Code:
Copy      Help
,sel i
,,case 1
,,sub.Dialog2(hwnd "www.yahoo.com")   ;;Wait 20 seconds close the window
,,case 2
,,sub.Dialog2(hwnd "www.bing.com")   ;;Wait 30 seconds close the window
#6
Added parameter closeAfterSeconds to sub Dialog2.


Code:
Copy      Help
#sub Dialog2
function# [hwndOwner] [~url] [closeAfterSeconds]

str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 900 432 "Dialog2"
;3 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!empty(url))
,ax3SHD=url
ret ShowDialog(dd &sub.DlgProc2 &controls hwndOwner 1 0 0 closeAfterSeconds) ;;modeless dialog


#sub DlgProc2
function# hDlg message wParam lParam
int- t_hdlg

sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3._setevents("sub.we3")
,t_hdlg=hDlg
,DT_SetAutoSizeControls hDlg "3s"
,SetTimer hDlg 1 100 0
,int closeAfterSeconds=DT_GetParam(hDlg); if(closeAfterSeconds>0) SetTimer hDlg 2 closeAfterSeconds*1000 0
,
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,,case 2
,,clo hDlg
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_CLOSE
,DT_Ok(hDlg)
ret
;messages2
sel wParam
,case IDOK
,ifk(Y)
,,key Y           ;; Enter
,,ret 0
,case IDCANCEL
,ret 0

ret 1
#7
you beat me to it Gintaras
also need to change this

Code:
Copy      Help
,sel i
,,case 1
,,sub.Dialog2(hwnd "www.yahoo.com")
,,case 2
,,sub.Dialog2(hwnd "www.bing.com")
to
Code:
Copy      Help
,sel i
,,case 1
,,sub.Dialog2(hwnd "www.yahoo.com" 20)  ;;<----change number to however many seconds you want
,,case 2
,,sub.Dialog2(hwnd "www.bing.com" 60)  ;;<----change number to however many seconds you want

full code

Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 900 432 "Dialog"
;4 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "4"
str ax4SHD
ax4SHD="http://www.quickmacros.com/help/QM_Help/IDH_OVERVIEW.html"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SetTimer hDlg 1 100 0
,SHDocVw.WebBrowser we4
,we4._getcontrol(id(4 hDlg))
,we4._setevents("sub.we4")
,;we4.Navigate("http://www.quickmacros.com/help/QM_Help/IDH_OVERVIEW.html")
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(4 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages
sel message
,case WM_RBUTTONDOWN
,str s=
,;1 yahoo
,;-
,;2 Bing

,MenuPopup x.AddItems(s)
,int i=x.Show
,sel i
,,case 1
,,sub.Dialog2(hwnd "www.yahoo.com" 20)  ;;<----change number to however many seconds you want
,,case 2
,,sub.Dialog2(hwnd "www.bing.com" 60)  ;;<----change number to however many seconds you want
,ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)
,;case ...
ret R

#sub we4_NewWindow3
function IDispatch&ppDisp @&Cancel dwFlags BSTR'bstrUrlContext BSTR'bstrUrl SHDocVw.IWebBrowser2'we3

int hDlg2=sub.Dialog2
SHDocVw.WebBrowser d2_we3._getcontrol(id(3 hDlg2))
ppDisp=d2_we3

#sub Dialog2
function# [hwndOwner] [~url] [closeAfterSeconds]

str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 900 432 "Dialog2"
;3 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!empty(url))
,ax3SHD=url
ret ShowDialog(dd &sub.DlgProc2 &controls hwndOwner 1 0 0 closeAfterSeconds) ;;modeless dialog

#sub DlgProc2
function# hDlg message wParam lParam

int- t_hdlg
sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3._setevents("sub.we3")
,t_hdlg=hDlg
,DT_SetAutoSizeControls hDlg "3s"
,SetTimer hDlg 1 100 0
,int closeAfterSeconds=DT_GetParam(hDlg); if(closeAfterSeconds>0) SetTimer hDlg 2 closeAfterSeconds*1000 0
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,,case 2
,,clo hDlg
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_CLOSE
,DT_Ok(hDlg)
ret
;messages2
sel wParam
,case IDOK
,ifk(Y)
,,key Y           ;; Enter
,,ret 0
,case IDCANCEL
,ret 0
ret 1

#sub we3_WindowClosing
function @IsChildWindow @&Cancel ;;SHDocVw.IWebBrowser2'we3
Cancel=1
int- t_hdlg
clo t_hdlg
#8
@kevinn

You have helped me too much, thank you very much  Heart


Forum Jump:


Users browsing this thread: 1 Guest(s)