Posts: 2
Threads: 1
Joined: Apr 2021
Hello
Totally new to QM.
How do I attach a command to a button on a dialogue to run a file/program.Thanks you for your help. It is much appreciated.
Kind regards
Alex
Posts: 1,337
Threads: 61
Joined: Jul 2006
04-18-2021, 03:31 AM
(This post was last modified: 04-18-2021, 10:33 AM by Kevin.)
open qm dialog editor
on the dialog editor window select the control(button in this case) you want to execute code from
then click the events buttons.(the lightning icon)
it will open another window
select BN_CLICKED
click ok on that window
it will insert code for that event into the dialog procedure
Then just need to add run code
example with run program and open file two buttons
Function
DialogRunOrOpenFile
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 33 48 48 14 "Run" "click to run or open file"
;4 Button 0x54032000 0x0 144 48 48 14 "Open"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C00 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#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
,case 3 ;;Run
,run "$windows$\notepad.exe";; run notepad
,case 4 ;;Open
,run "$qm$\License.txt"
ret 1
Posts: 2
Threads: 1
Joined: Apr 2021
Hello Kevin
Many thanks for your reply.
When I click on the events, I get a message
"Cannot find Dialogue Procedure
It must be in the same macro/function where is the dialogue definition
More info in QM output
What am I doing wrong?Thanks you for your help. It is much appreciated.
Kind regards
Alex
Posts: 8
Threads: 0
Joined: Mar 2018
Add this line to the beginning of the function above.
\Dialog_Editor
Posts: 1,337
Threads: 61
Joined: Jul 2006
Your dialog needs to be a smart dialog.
the error message shows you how to fix it. The dialog must have a Dialogue Procedure. In qm output it gives you a sample code to fix the issue..
Sample ShowDialog code and dialog procedure:
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#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
close dialog editor
find this line in
if(!ShowDialog(dd 0 0)) ret
replace with sample code
then reopen dialog editor and follow instructions given above.
or can re make the dialog as a smart dialog.