Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
execute QM commands from buttons on a web page
#1
Web design software can be very convenient layout. Can I execute QM macro commands on the buttons of web pages?

I hope the developer can provide some sample code, thanks in advance.


Macro Macro1
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 448 214 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 448 214 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
ax3SHD="$desktop$\index.html"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub sub1
mes "this is QM mes"

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Attached Files Image(s)
   

.zip   index.zip (Size: 882 bytes / Downloads: 292)
#2
download this file for an example
http://www.quickmacros.com/forum/attachment.php?aid=132

it uses older way of setting browser events but it will show you how the process works
#3
Thank you for your reminder, this code is too long, the dialog code is not the same as the new version of QM now, is there a simpler method?

If I can quickly execute QM code on a web page, the QM program interface will be very simple to make.
#4
Give me a few minutes i will show updated code but still  wont be alot shorter

Function HtmlElementsDialog
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 448 214 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 448 214 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
ax3SHD="$desktop$\index.html";; change to location of your html files
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,MSHTML.HTMLDocument doc=sub.DT_GetHtmlDocument(hDlg 3)
,MSHTML.HTMLInputElement- button1=+doc.getElementById("Button1")
,button1._setevents("sub.button1")
,MSHTML.HTMLInputElement- button2=+doc.getElementById("Button2")
,button2._setevents("sub.button2")    
,;Note: HTMLInputElement can be used for any type of input elements. For some element types also can be used specific interfaces, eg HTMLInputTextElement.
,;Note: Use thread variables for html elements for which is called _setevents.
,;Note: After navigating to other page, if these thread variables still must be used, they must be reinitialized, and _setevents called again. If not used, they should be cleared (=0).    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub DT_GetHtmlDocument
function'MSHTML.HTMLDocument hDlg ctrlid [flags] ;;flags: 1 - return 0 if not loaded

;Returns MSHTML.HTMLDocument interface pointer of a web browser control which is on a custom dialog.
;Call this function from dialog procedure.
;Returns 0 if the control currently is not displaying a html document.

;hDlg - parent dialog
;ctrlid - web browser control id
;SHDocVw.WebBrowser we3
SHDocVw.WebBrowser we
we._getcontrol(id(ctrlid hDlg))
if(flags&1) if(we.Busy or we.ReadyState!=SHDocVw.READYSTATE_COMPLETE) ret
ret we.Document

#sub button1_onclick
function MSHTML.DispHTMLInputElement'btn
out "button 1 clicked"
mes "sub1 button has been clicked"

#sub button2_onclick
function MSHTML.DispHTMLInputElement'btn1
out "button 2 clicked"
mes "this is QM mes"


i had to revise your html as well got rid of useless unneeded  parts and had to put css in html file or sometimes qm would have trouble finding the elements because it wasn't loaded yet.


.zip   indexrevised.zip (Size: 537 bytes / Downloads: 277)

i reposted the code and attachment posted wrong attachment and changed directory for the file in dialog code. place the html file on the desktop not in a folder
#5
I added a text area in index.html with some QM code, can I run it?    Idea

If I can implement the functions, I put index.html in my website space, my friend, as long as QM is installed, he can run the QM code I wrote, which is very good.   Big Grin


Attached Files Image(s)
   

.zip   index+.zip (Size: 989 bytes / Downloads: 280)
#6
Follow  the code for the buttons will be similar  will need  to create  a new html input variable and set event for the new button
#7
I tried it many times and I have two problems.

1. How to get the QM code in TextArea1

2. How to run the above code in sub3

Can you help me any more, thanks

Macro Macro2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 448 214 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 448 214 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
ax3SHD="$desktop$\index+.html";; change to location of your html files
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,MSHTML.HTMLDocument doc=sub.DT_GetHtmlDocument(hDlg 3)
,MSHTML.HTMLInputElement- button1=+doc.getElementById("Button1")
,button1._setevents("sub.button1")
,MSHTML.HTMLInputElement- button2=+doc.getElementById("Button2")
,button2._setevents("sub.button2")
,MSHTML.HTMLInputElement- button3=+doc.getElementById("Button2")
,button2._setevents("sub.button3")
,???
,;Note: HTMLInputElement can be used for any type of input elements. For some element types also can be used specific interfaces, eg HTMLInputTextElement.
,;Note: Use thread variables for html elements for which is called _setevents.
,;Note: After navigating to other page, if these thread variables still must be used, they must be reinitialized, and _setevents called again. If not used, they should be cleared (=0).
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub DT_GetHtmlDocument
function'MSHTML.HTMLDocument hDlg ctrlid [flags] ;;flags: 1 - return 0 if not loaded

;Returns MSHTML.HTMLDocument interface pointer of a web browser control which is on a custom dialog.
;Call this function from dialog procedure.
;Returns 0 if the control currently is not displaying a html document.

;hDlg - parent dialog
;ctrlid - web browser control id
;SHDocVw.WebBrowser we3
SHDocVw.WebBrowser we
we._getcontrol(id(ctrlid hDlg))
if(flags&1) if(we.Busy or we.ReadyState!=SHDocVw.READYSTATE_COMPLETE) ret
ret we.Document

#sub button1_onclick
function MSHTML.DispHTMLInputElement'btn
out "button 1 clicked"
mes "sub1 button has been clicked"
run "notepad.exe"

#sub button2_onclick
function MSHTML.DispHTMLInputElement'btn1
out "button 2 clicked"
mes "this is QM mes"
run "notepad.exe"

#sub button3_onclick
function MSHTML.DispHTMLInputElement'btn2

????
#8
Now that i look at this idea better  its not great  idea. Big potential security  vulnerability  there .someone could  change run notepad line  to something  else  could  easily  do damage to the pc it runs  on.  Would need  to put in place code to protect against this potential vulnerability.

also you have mistakes in your code
these lines are incorrect
,MSHTML.HTMLInputElement- button3=+doc.getElementById("Button2");;<--------------------- wrong button id

wrong variable name------->>>> ,button2._setevents("sub.button3")

if  i am reading this correctly you were thinking of being able to run programs from the text area text that was typed? not just notepad?

this shows how to get the text area text i added in some comments so maybe you will understand better

Function HtmlElementsDialog2 
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 448 214 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 448 214 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
ax3SHD="$desktop$\index+.html";; change to location of your html files
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,;Gets document
,MSHTML.HTMLDocument doc=sub.DT_GetHtmlDocument(hDlg 3)

,;get input button1 element and set events for it
,MSHTML.HTMLInputElement- button1=+doc.getElementById("Button1")
,button1._setevents("sub.button1")

,;get input button2 element and set events for it
,MSHTML.HTMLInputElement- button2=+doc.getElementById("Button2")
,button2._setevents("sub.button2")    

,;get input button3 element and set events for it
,MSHTML.HTMLInputElement- button3=+doc.getElementById("Button3")
,button3._setevents("sub.button3")    
,;Note: HTMLInputElement can be used for any type of input elements. For some element types also can be used specific interfaces, eg HTMLInputTextElement.
,;Note: Use thread variables for html elements for which is called _setevents.
,;Note: After navigating to other page, if these thread variables still must be used, they must be reinitialized, and _setevents called again. If not used, they should be cleared (=0).    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub DT_GetHtmlDocument
function'MSHTML.HTMLDocument hDlg ctrlid [flags] ;;flags: 1 - return 0 if not loaded

;Returns MSHTML.HTMLDocument interface pointer of a web browser control which is on a custom dialog.
;Call this function from dialog procedure.
;Returns 0 if the control currently is not displaying a html document.

;hDlg - parent dialog
;ctrlid - web browser control id
;SHDocVw.WebBrowser we3
SHDocVw.WebBrowser we
we._getcontrol(id(ctrlid hDlg))
if(flags&1) if(we.Busy or we.ReadyState!=SHDocVw.READYSTATE_COMPLETE) ret
ret we.Document

#sub button1_onclick
function MSHTML.DispHTMLInputElement'btn1
out "button 1 clicked"
mes "sub1 button has been clicked"

#sub button2_onclick
function MSHTML.DispHTMLInputElement'btn2
out "button 2 clicked"
mes "this is QM mes"

#sub button3_onclick
function MSHTML.DispHTMLInputElement'btn3
out "button 3 clicked"
;on button3 click get html document
MSHTML.HTMLDocument doc=btn3.document

,;get text area element and text
str s    
MSHTML.HTMLInputElement textarea=+doc.getElementById("TextArea1")
s=textarea.innerText;;; gets text in text area
out s
#9
I want run programs from the text area text , How to achieve? Smile


thanks for your reminder, My thoughts do have security issues, I won't expose index.html  Tongue
#10
You should keep in mind  that all html forms need to be preventive  to protect servers or in this case the pc . You don't want users being able  to run any program or file on that particular pc.Since you want to allow programs  to be run I would suggest limiting the programs that could be run .To do this you're going  to need  a list of programs that can be run then compare  the input text against that list and allow or disallow. This is Just a strong recommendation.  The next part  is you need to figure out how to read  and process  multi line strings.  As the text is multilined .search the forum and read  help about  multiline  strings.
#11
Also you have to consider how are you going to process the data. 
What if they change the wording? 
Would be simpler to create a combo box and let them choose from a list . Trying to parse unknown data is not easy.
#12
here is a working example using a combo box instead of a text area i edited your html file as well.

Function HtmlElementsDialog3 
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 448 214 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 448 214 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
ax3SHD="$desktop$\index+revised.html";; change to location of your html files
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
int- t_hdlg
sel message
,case WM_INITDIALOG
,t_hdlg=hDlg
,;Gets document
,MSHTML.HTMLDocument doc=sub.DT_GetHtmlDocument(hDlg 3)

,;get input button1 element and set events for it
,MSHTML.HTMLInputElement- button1=+doc.getElementById("Button1")
,button1._setevents("sub.button1")

,;get input button2 element and set events for it
,MSHTML.HTMLInputElement- button2=+doc.getElementById("Button2")
,button2._setevents("sub.button2")    

,;get input button3 element and set events for it
,MSHTML.HTMLInputElement- button3=+doc.getElementById("Button3")
,button3._setevents("sub.button3")    
,
,;get input button4 element and set events for it
,MSHTML.HTMLInputElement- button4=+doc.getElementById("Button4")
,button4._setevents("sub.button4")    
,
,;Note: HTMLInputElement can be used for any type of input elements. For some element types also can be used specific interfaces, eg HTMLInputTextElement.
,;Note: Use thread variables for html elements for which is called _setevents.
,;Note: After navigating to other page, if these thread variables still must be used, they must be reinitialized, and _setevents called again. If not used, they should be cleared (=0).    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub DT_GetHtmlDocument
function'MSHTML.HTMLDocument hDlg ctrlid [flags] ;;flags: 1 - return 0 if not loaded

;Returns MSHTML.HTMLDocument interface pointer of a web browser control which is on a custom dialog.
;Call this function from dialog procedure.
;Returns 0 if the control currently is not displaying a html document.

;hDlg - parent dialog
;ctrlid - web browser control id
;SHDocVw.WebBrowser we3
SHDocVw.WebBrowser we
we._getcontrol(id(ctrlid hDlg))
if(flags&1) if(we.Busy or we.ReadyState!=SHDocVw.READYSTATE_COMPLETE) ret
ret we.Document

#sub button1_onclick
function MSHTML.DispHTMLInputElement'btn1
out "button 1 clicked"
mes "sub1 button has been clicked"

#sub button2_onclick
function MSHTML.DispHTMLInputElement'btn2
out "button 2 clicked"
mes "this is QM mes"

#sub button3_onclick
function MSHTML.DispHTMLInputElement'btn3
;on button3 click get html document
MSHTML.HTMLDocument doc=btn3.document

,;get select box element and selected item
int- t_hdlg
Htm e=htm("SELECT" "programlist" "" t_hdlg "0" 0 0x101 3)
str selItemText result1 result2
int selItem=e.CbItem(selItemText);;finds the selected item
result2=e.el.getAttribute("value" 0);; stores program name to run
result1.from("Next Will Open " selItemText);; makes a string for mes
mes result1;;; show run message
run result2;;; run selected program

#sub button4_onclick
function MSHTML.DispHTMLInputElement'btn4
;get document
MSHTML.HTMLDocument doc=btn4.document
;;get text from input
MSHTML.HTMLInputElement text=+doc.getElementById("message1")
str s1=text.getAttribute("value" 0)
if(s1.len)
,mes s1;; show text in a message
else
,mes "Opps!! You didnt type a message"

here is the revised html file to go with this

.zip   index+revised.zip (Size: 1.03 KB / Downloads: 282)
#13
works for me but again i will try and stress this is not a good idea.
#14
Well, I also feel that there is a real risk of running.
#15
there are  few problems with the text area idea
1. typos if you make typo it will fail and close dialog
2. if qm command is type wrong will fail and close dialog
3. handling unknown data is not easy to many variables to try and contend with


check out my posted solution  its very user friendly and eliminates errors.
if you give us a better idea of your ideas on what you would like to implement in this form can help further


Forum Jump:


Users browsing this thread: 1 Guest(s)