Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog loop
#1
Hi, I am trying to execute a loop when pressing a button in a dialog, but when executing the dialog becomes unresponsive until the loop ends. I don't know if it should work like this or if I am doing something wrong. Here is an example:
Code:
Copy      Help
Macro [b]Macro2[/b] [help1][/help1]
[code]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 262 120 "Dialog" "4"
;3 Button 0x54032000 0x0 7 4 248 110 "Loop"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B00 "*" "" "" ""

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 3
,int i
,for i 0 10
,,1
,,out i
,case IDOK
,case IDCANCEL
ret 1
[/code]
#2
The reason for the unresponsive dialog is the 1 second wait in your loop. The example you showed would be best put in a timer.(case WM_TIMER). Search forum for SetTimer for examples on how to use a timer in a dialog. Sorry not at pc can't give example. Other options would be to put that code in a subfuntion and call using mac.So it runs un another thread and doesn't effect dialog process. Last option would be to place opt waitmsg 1 before the loop. It works but is not recommended way
#3
So, using a subfuntion in the example above worked fine but when I tried to pass to my project didn't work.Here a example of the loop that I'm trying to run:Macro Macro2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 280 166 "Dialog" "4"
;3 Button 0x54032000 0x0 231 2 48 14 "Loop"
;4 QM_Grid 0x56031041 0x200 2 2 227 162 "0x10,0,0,0x2,0x0[]A,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B00 "*" "" "" ""

str controls = "4"
str qmg4x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
int i
str a
str csv

DlgGrid g.Init(hDlg 4)

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,ICsv z._create
,for i 0 13
,,1
,,a=i
,,z.Cell(i 0)=a
,,z.ToString(csv)
,,z.ToQmGrid(g 0)
,case IDOK
,case IDCANCEL
ret 1
[/code]
#4
there is no need for the 1 second delay in your loop that i can see .Why is it there?
Remove it and everything works.
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 280 166 "Dialog" "4"
;3 Button 0x54032000 0x0 231 2 48 14 "Loop"
;4 QM_Grid 0x56031041 0x200 2 2 227 162 "0x10,0,0,0x2,0x0[]A,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B00 "*" "" "" ""

str controls = "4"
str qmg4x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

int i; str a csv
DlgGrid g.Init(hDlg 4)

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,ICsv z._create
,for i 0 13
,,a=i
,,z.Cell(i 0)=a
,,z.ToString(csv)
,,z.ToQmGrid(g 0)
,case IDOK
,case IDCANCEL
ret 1
#5
Actually, that 1 second was just to simulate. I am using a Wait for handle to run and waiting for a CLI to exit, and in the time that is waiting the dialog become unresponsive. And basically I was trying to make the loop stop when pressing a button at the dialog. Using a subfuntion worked a bit because I was able to stop the loop using EndThread, but like above I was not able to pass the loop to the subfuction. Sorry if I couldn't explain it right. And thanks for the help.
Code:
Copy      Help
Macro [b]Macro2[/b] [help1][/help1]
[code]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 329 217 "Dialog" "4"
;3 Button 0x54032000 0x0 277 6 48 14 "Start"
;4 Button 0x54032000 0x0 277 23 48 14 "Stop"
;5 QM_Grid 0x56031041 0x200 2 3 272 207 "0x10,0,0,0x0,0x0[]A,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B00 "*" "" "" ""

str controls = "5"
str qmg5x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
ARRAY(str) files
int i
str name csv

DlgGrid g.Init(hDlg 5)
sel message
,case WM_INITDIALOG
,ICsv+ z._create
,z.FromString(csv)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,OpenSaveDialog(0 0 "Video Files[]*.ts;*.mkv;*.mp4;*.mov" "" 0 "" 0 files)
,for i 0 files.len
,,name=files[0+i]
,,__Handle hProcess=run("cmd.exe" F"/c ffmpeg -i ''{name}'' -c:v copy -aspect 16:9 -c:a copy ''{name}-copy.mp4''" "" "" 0x10000)
,,wait 0 H hProcess
,,z.Cell(i 0)=name
,,z.ToString(csv)
,,z.ToQmGrid(g 0)
,case 4
,
,case IDOK
,case IDCANCEL
ret 1
[/code]
#6
try this
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 329 217 "Dialog" "4"
;3 Button 0x54031003 0x0 277 6 48 14 "Start"
;5 QM_Grid 0x56031041 0x200 2 3 272 207 "0x10,0,0,0x0,0x0[]A,,,"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 5"
str c3Sta qmg5x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

DlgGrid g.Init(hDlg 5)
sel message
,case WM_INITDIALOG
,int- tHandle
,ICsv z._create
,str csv
,z.FromString(csv)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3 ;; start-stop button
,if(but(lParam))
,,out "Started"
,,tHandle=mac("sub.fill_loop" "" g csv)
,else
,,out "Stopped"
,,EndThread "" tHandle
,SetDlgItemText hDlg wParam iif(but(lParam) "Stop" "Start")    
,case IDOK
,case IDCANCEL
ret 1

#sub fill_loop
function gHwnd str'csv
ARRAY(str) files
int i; str name
ICsv z1._create
OpenSaveDialog(0 0 "Video Files[]*.ts;*.mkv;*.mp4;*.mov" "" 0 "" 0 files)
for i 0 files.len
,name=files[0+i]
,__Handle hProcess=run("cmd.exe" F"/c ffmpeg -i ''{name}'' -c:v copy -aspect 16:9 -c:a copy ''{name}-copy.mp4''" "" "" 0x10000)
,wait 0 H hProcess
,z1.Cell(i 0)=name
,z1.ToString(csv)
,z1.ToQmGrid(gHwnd 0)
#7
This worked great thanks again.


Forum Jump:


Users browsing this thread: 1 Guest(s)