Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controlling macro from open dialog
#1
Hi, I used your example here and was able to create a dialog that could start and stop another macro
http://www.quickmacros.com/forum/showthr...p?tid=1954
IS it also possible to be able to send and retreive information from the dialog to another macro or function?
I think I need to use function as I want to compile it into an .exe and mac is not supported in this feature?
Here is the basic dialog that is working
Function Dialog3
Code:
Copy      Help
/Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 6 4 48 14 "Start"
;4 Button 0x54032000 0x0 6 22 48 14 "Stop"
;5 Edit 0x54030080 0x200 72 58 34 16 ""
;6 Static 0x54000000 0x0 6 58 60 16 "Number of times to loop"
;7 Edit 0x54030080 0x200 74 76 96 14 ""
;8 Static 0x54000000 0x0 6 76 60 14 "Success Message"
;2 Button 0x54030000 0x4 6 42 48 14 "Exit"
;END DIALOG
;DIALOG EDITOR: "" 0x2030408 "" "" "" ""

str controls = "5 7"
str e5 e7
if(!ShowDialog("Dialog3" &Dialog3 &controls)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,    mac "Loop"
,    
,case 4
,    shutdown -6 0 "Loop"
,
,case IDCANCEL
ret 1


And the macro it is controlling, if you click start it outputs the count and stop will stop the count.

Macro Loop1
Code:
Copy      Help
;;simple loop macro
int count
for count 1 10
,wait 1
,out count

What I would like to be able to do, is say have a text box on the dialog and the number entered there is sent to the function for the number of times to loop. And when done a success message is sent back to the dialog from the function, something like this, I am sure the syntax is not correct, but was not sure how to send the shutdown command to the function? When I run the macro and enter a number into the text box, nothing happens when I click start.

Function Dialog3
Code:
Copy      Help
/Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 6 4 48 14 "Start"
;4 Button 0x54032000 0x0 6 22 48 14 "Stop"
;5 Edit 0x54030080 0x200 72 58 34 16 ""
;6 Static 0x54000000 0x0 6 58 60 16 "Number of times to loop"
;7 Edit 0x54030080 0x200 74 76 96 14 ""
;8 Static 0x54000000 0x0 6 76 60 14 "Success Message"
;2 Button 0x54030000 0x4 6 42 48 14 "Exit"
;END DIALOG
;DIALOG EDITOR: "" 0x2030408 "" "" "" ""

str controls = "5 7"
str e5 e7
if(!ShowDialog("Dialog3" &Dialog3 &controls)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,    mac Loop(0 val(e5))
,    e7=success
,case 4
,    shutdown -6 0 Loop(0 0)
,
,case IDCANCEL
ret 1

Function Loop
Code:
Copy      Help
;;function that accepts argumnents from dialog and returns success message to dialog
/
function int'count int'e5 str'message
message="success!"
for count 1 e5
,wait 1
,out count
ret message

Thanks kindly Matt
#2
mac is supported in exe, but it supports only functions, not macros, which is almost the same anyway.
mac "Function_NotMacro"

I could help with the dialog, but I'm lazy to read your codes when without colors. To copy code with colors, use menu Edit -> Other Formats -> Forum.
#3
Gintaras Wrote:I could help with the dialog, but I'm lazy to read your codes when without colors. To copy code with colors, use menu Edit -> Other Formats -> Forum.

Oh yes I would very much appreciate some help with the dialog Gintaras, I have modified the initial post so that is now formatted correctly with colors.

Kind Regards
Matt
#4
Function Dialog310
Code:
Copy      Help
/Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 6 4 48 14 "Start"
;4 Button 0x5C032000 0x0 6 22 48 14 "Stop"
;5 Edit 0x54030080 0x200 72 58 34 16 ""
;6 Static 0x54000000 0x0 6 58 60 16 "Number of times to loop"
;7 Edit 0x54030080 0x200 74 76 96 14 ""
;8 Static 0x54000000 0x0 6 76 60 14 "Success Message"
;2 Button 0x54030000 0x4 6 42 48 14 "Exit"
;END DIALOG
;DIALOG EDITOR: "" 0x2030502 "" "" "" ""

str controls = "5 7"
str e5 e7
if(!ShowDialog("Dialog310" &Dialog310 &controls)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_APP
,SetDlgItemText hDlg 7 F"{lParam%%s}"
,EnableWindow id(3 hDlg) 1; EnableWindow id(4 hDlg) 0
ret
;messages2
sel wParam
,case 3
,SetDlgItemText hDlg 7 ""
,EnableWindow id(3 hDlg) 0; EnableWindow id(4 hDlg) 1
,mac "Loop" "" hDlg _s.getwintext(id(5 hDlg))
,
,case 4
,shutdown -6 0 "Loop"
,EnableWindow id(3 hDlg) 1; EnableWindow id(4 hDlg) 0
,
,case IDCANCEL
ret 1

Function Loop
Code:
Copy      Help
;;function that accepts argumnents from dialog and returns success message to dialog
/
function hDlg e5

int i
for i 0 e5
,wait 1
,out i

SendMessage hDlg WM_APP 0 "success!"
#5
That works great, thanks kindly Gintaras. Is it also possible to send a parameter back from the function to the dialog?
So once the loop is complete, send the word success back to the edit box?

Function Dialog3
Code:
Copy      Help
sel wParam
,case 3
,SetDlgItemText hDlg 7 ""
,EnableWindow id(3 hDlg) 0; EnableWindow id(4 hDlg) 1
,mac "Loop" "" hDlg _s.getwintext(id(5 hDlg))
,e7=message

Function Loop
Code:
Copy      Help
;;function that accepts argumnents from dialog and returns success message to dialog
/
function int'count int'e5 str'message
message="success!"
for count 1 e5
,wait 1
,out count
ret message


Thanks kindly
Matt
#6
sorry, forgot function Loop, now added in previous post
#7
Gintaras Wrote:sorry, forgot function Loop, now added in previous post

No need to apologise, that works brilliantly!

Thank you so much for your assistance, your support is fantastic Smile
#8
Please, can you tell me how I can scroll the text returned from the function, in the read only edit, rather than simply replacing it?

Function Dialog3
Code:
Copy      Help
/Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 6 4 48 14 "Start"
;4 Button 0x54032000 0x0 6 22 48 14 "Stop"
;5 Edit 0x54030080 0x200 72 58 34 16 ""
;6 Static 0x54000000 0x0 6 58 60 16 "Number of times to loop"
;7 Edit 0x54030080 0x200 112 22 96 14 ""
;8 Static 0x54000000 0x0 6 76 60 14 "Success Message"
;9 Edit 0x54200844 0x20000 72 76 96 48 ""
;2 Button 0x54030000 0x4 6 42 48 14 "Exit"
;END DIALOG
;DIALOG EDITOR: "" 0x2030408 "" "" "" ""

str controls = "5 7 9"
str e5 e7 e9
if(!ShowDialog("Dialog3" &Dialog3 &controls)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_APP
,SetDlgItemText hDlg 9 F"{lParam%%s}"
/EnableWindow id(3 hDlg) 1; EnableWindow id(4 hDlg) 0
ret
;messages2
sel wParam
,case 3
,SetDlgItemText hDlg 9 ""
,EnableWindow id(3 hDlg) 0; EnableWindow id(4 hDlg) 1
,mac "Loop" "" hDlg _s.getwintext(id(5 hDlg))
,/e7=message
,
,case 4
,shutdown -6 0 "Loop"
,EnableWindow id(3 hDlg) 1; EnableWindow id(4 hDlg) 0
,
,case IDCANCEL
ret 1

;BEGIN MENU
;>&File
,;&Open : 101 0 0 Co
,;-
,;>&Recent
,,;Empty : 102 0 3
,,;<
,;<
;>&Edit
,;&Undo : 106 0 1 Cz
,;Enable Undo : 110
,;Disable Undo : 111
,;Cu&t : 103 0 0 Cx
,;-
,;Select &All : 104 0 0 Ca
,;<
;&Help : 105 0
;END MENU

Function Loop
Code:
Copy      Help
;;function that accepts argumnents from dialog and returns success message to dialog

function hDlg e5

int i
for i 0 e5
,wait 1
,out i
,SendMessage hDlg WM_APP 1 "success!"

Thank you kindly
Matt
#9
Replace SetDlgItemText hDlg 9 F"{lParam%%s}" to
Code:
Copy      Help
,int c=id(9 hDlg)
,SendMessage c EM_SETSEL 1000000000 1000000000
,SendMessage c EM_REPLACESEL 0 F"{lParam%%s}[]"
#10
Thanks Gintaras, that works great!

Is it possible to return both int and str variables to the SAME edit box?

SetDlgItemText hDlg 9 F"{lParam%%s}"

Thanks
Matt
#11
SendMessage hDlg WM_APP 0 F"success! {intVariable} {strVariable}"
#12
Great, thank you. As usual your support is fantastic!

Matt
#13
Hi Gintaras, I made some changes to the dialog (removed an edit box) and somehow I broke SendMessage command. It was working Sad

The function no longer sends anything back to the dialog- not sure what I have done, looks like it should be working, would you mind taking a look?

Function Hot_Dialog
Code:
Copy      Help
/Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 287 130 "The Roulette Project"
;3 Button 0x54032000 0x0 6 4 48 14 "Start"
;4 Button 0x54032000 0x0 6 22 48 14 "Stop"
;9 Edit 0x54200844 0x20000 60 4 226 125 ""
;2 Button 0x54030000 0x4 6 42 48 14 "Exit"
;END DIALOG
;DIALOG EDITOR: "" 0x2030408 "" "" "" ""

str controls = "9"
str e9
if(!ShowDialog("Hot_Dialog" &Hot_Dialog &controls)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,/SetDlgItemText hDlg 6 ""
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_APP
,int c=id(9 hDlg)
,SendMessage c EM_SETSEL 1000000000 1000000000
,SendMessage c EM_REPLACESEL 0 F"{lParam%%s}[]"


ret
;messages2
sel wParam
,case 3
,SetDlgItemText hDlg 3 "Running"
,EnableWindow id(3 hDlg) 0; EnableWindow id(4 hDlg) 1
,mac "Hot";; " " hDlg _s.getwintext(id(6 hDlg))

,
,case 4
,SetDlgItemText hDlg 3 "Start"
,shutdown -6 0 "Hot"
,EnableWindow id(3 hDlg) 1; EnableWindow id(4 hDlg) 0
,
,case IDCANCEL
ret 1

Function Hot
Code:
Copy      Help
/out(F"Keep window open is now {KeepWindowOpen}")
,out_spinnumber.from(F"Spin number is {TotalSpins}")
,out_spinnumber.setfile("$my qm$\QmData\nums.txt" -1 -1 1)
,SendMessage hDlg WM_APP 1 out_spinnumber
,/out out_spinnumber

Thanks so much
Matt
#14
mac "Hot" does not send hDlg etc.
#15
Ah thanks Gintaras. I did not realise I needed hDlg when calling the macros for the conversation to occur both ways.

Cheers
Matt


Forum Jump:


Users browsing this thread: 1 Guest(s)