Posts: 726
Threads: 99
Joined: Mar 2018
04-15-2019, 10:46 PM
(This post was last modified: 04-15-2019, 10:53 PM by win .)
Hello,
I want to execute the selected item in turn, for example, I chose, item 1 3 5, When I press the ok button,
will execute the sub-function 1 3 5, the dialog is minimized, not closed
In addition, I want to know how to get the text of the selected item. The current output is all numbers, like this 10101
Thanks in advance
Macro
Execute the selected item
str L=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""
str controls = "5"
str lb5
lb5= L
if ( ! ShowDialog ( dd & sub.DlgProc & controls)) ret
out
out lb5
#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
#sub m1
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m1" "" m)
#sub m2
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m2" "" m)
#sub m3
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m3" "" m)
#sub m4
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m4" "" m)
#sub m5
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m5" "" m)
Posts: 726
Threads: 99
Joined: Mar 2018
04-17-2019, 01:19 AM
(This post was last modified: 04-17-2019, 01:55 AM by win .)
I changed the smart dialog box to a simple dialog box, which can achieve the effect I want, but it is very troublesome, is there a simpler method? I want to use smart dialogs, any suggestions for perfecting this feature code are welcome.
Macro
Macro2
;start
str L=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""
str controls = "5"
str lb5
lb5= L
if ( ! ShowDialog ( dd 0 & controls)) ret
out
out lb5
if lb5= 10000
, sub.m1
if lb5= 11000
, sub.m1
, sub.m2
,
if lb5= 11100
, sub.m1
, sub.m2
, sub.m3
,
goto start
;#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
, ;min hDlg
, ;ret 0
, ;case IDCANCEL
;ret 1
#sub m1
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m1" "" m)
#sub m2
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m2" "" m)
#sub m3
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m3" "" m)
#sub m4
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m4" "" m)
#sub m5
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m5" "" m)
The above method is not reliable. If I re-add the list item, the operation of executing the code should be re-modified.
Posts: 726
Threads: 99
Joined: Mar 2018
Can someone give some advice?
The number of items in the list is not fixed, and new items need to be added later.
How to deal with is the best way
Posts: 1,335
Threads: 61
Joined: Jul 2006
04-18-2019, 11:53 PM
(This post was last modified: 04-27-2019, 03:27 PM by Kevin .)
Function
Function_LB_multiSelect_Dialog
ARRAY ( str ) - lb_selected
str L=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;3 Button 0x54032000 0x0 9 116 56 14 "Run Selected"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
str controls = "5"
str lb5
lb5= L
if ( ! ShowDialog ( dd & sub.DlgProc & controls)) ret
out
lb5= lb_selected
out lb5
#sub DlgProc v
function # hDlg message wParam lParam
int hlb
sel message
, case WM_INITDIALOG
, case WM_DESTROY
, case WM_COMMAND goto messages2
ret
;messages2
hlb= id ( 5 hDlg)
sel wParam
, case IDOK
, LB_GetSelectedItems ( hlb 0 lb_selected)
, case IDCANCEL
, case 3 ;;Run Selected
, LB_GetSelectedItems ( hlb 0 lb_selected)
, _s= lb_selected
, str ss
, foreach ss _s
,, ss.trim
,, opt waitmsg 1
,, sel ss
,,, case "sub.m1"
,,, sub.m1
,,, case "sub.m2"
,,, sub.m2
,,, case "sub.m3"
,,, sub.m3
,,, case "sub.m4"
,,, sub.m4
,,, case "sub.m5"
,,, sub.m5
ret 1
#sub m1
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m1" "" m)
#sub m2
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m2" "" m)
#sub m3
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m3" "" m)
#sub m4
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m4" "" m)
#sub m5
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m5" "" m)
need this function as well
Function
LB_GetSelectedItems
;/
function # hwnd [ARRAY ( int ) & ai] [ARRAY ( str ) & as]
;Gets selected items in a multisel listbox control.
;Returns number of selected items.
;hwnd - control handle.
;ai - array variable that receives indices of selected items. Optional, can be 0.
;as - array variable that receives text of selected items. Optional, can be 0.
;REMARKS
;The control must belong to current process. Use eg in dialog procedures.
if ( & ai) ai= 0
if ( & as) as= 0
int i n
n= SendMessage ( hwnd LB_GETSELCOUNT 0 0 ); if ( n< 1 ) ret
if & ai or & as
, ARRAY ( int ) _ai; if ( !& ai) & ai= _ai
, ai.create ( n)
, n= SendMessage ( hwnd LB_GETSELITEMS n & ai[0 ]); if ( n< 0 ) n= 0
, if ( n! ai.len ) ai.redim ( n)
, if & as
,, as.create ( n)
,, for ( i 0 n) LB_GetItemText ( hwnd ai[i] as[i])
ret n
Posts: 726
Threads: 99
Joined: Mar 2018
04-19-2019, 12:08 AM
(This post was last modified: 04-19-2019, 12:19 AM by win .)
Prompt without this function
why
My QM software does not have these functions.
and this
http://www.quickmacros.com/forum/showthr...9#pid33199
Attached Files
Image(s)
Posts: 1,335
Threads: 61
Joined: Jul 2006
04-19-2019, 12:36 AM
(This post was last modified: 04-19-2019, 12:39 AM by Kevin .)
sorry i forgot to post it .It is also posted in the forum somewhere and is also in the archive updated post above with the needed function
Posts: 726
Threads: 99
Joined: Mar 2018
Still prompted error
Attached Files
Image(s)
Posts: 1,335
Threads: 61
Joined: Jul 2006
restart qm and see if it errors again
Posts: 726
Threads: 99
Joined: Mar 2018
Posts: 1,335
Threads: 61
Joined: Jul 2006
you must not be using full posted code
Posts: 726
Threads: 99
Joined: Mar 2018
Do you mean that the code I copied is incomplete?
I am sure that the code is complete and I tried it many times.
Posts: 726
Threads: 99
Joined: Mar 2018
I installed win10 virtual machine and QM on my computer.
Test the above code, there are still errors
Posts: 1,335
Threads: 61
Joined: Jul 2006
got me on why it will not work is unicode mode enabled in qm?
try this version
Function
dialogMultisellistbox
ARRAY ( str ) - lb_selected
str l=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;3 Button 0x54032000 0x0 9 116 56 14 "Run Selected"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
str controls = "5"
str lb5
lb5= l
if ( ! ShowDialog ( dd & sub.DlgProc & controls)) ret
out
lb5= lb_selected
out lb5
#sub DlgProc v
function # hDlg message wParam lParam
int hlb
sel message
, case WM_INITDIALOG
, case WM_DESTROY
, case WM_COMMAND goto messages2
ret
;messages2
hlb= id ( 5 hDlg)
sel wParam
, case IDOK
, sub.LB_GetSelectedItems2 ( hlb lb_selected)
, case IDCANCEL
, case 3 ;;Run Selected
, sub.LB_GetSelectedItems2 ( hlb lb_selected)
, _s= lb_selected
, str ss
, foreach ss _s
,, ss.trim
,, opt waitmsg 1
,, sel ss
,,, case "sub.m1"
,,, sub.m1
,,, case "sub.m2"
,,, sub.m2
,,, case "sub.m3"
,,, sub.m3
,,, case "sub.m4"
,,, sub.m4
,,, case "sub.m5"
,,, sub.m5
ret 1
#sub m1
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m1" "" m)
#sub m2
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m2" "" m)
#sub m3
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m3" "" m)
#sub m4
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m4" "" m)
#sub m5
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m5" "" m)
#sub LB_GetSelectedItems2
function hlb ARRAY ( str ) & a
;Gets text of selected items in a multiple-selection listbox.
int i n= SendMessage ( hlb LB_GETSELCOUNT 0 0 )
if ( n=- 1 ) ;;single-sel control
, a.redim ( 1 )
, if ( LB_SelectedItem ( hlb a[0 ]) < 0 ) a.redim
else
, a.redim ( n)
, if ( n)
,, ARRAY ( int ) selitems.create ( n)
,, SendMessage ( hlb LB_GETSELITEMS n & selitems[0 ])
,, for ( i 0 n) LB_GetItemText hlb selitems[i] a[i]
Posts: 1,335
Threads: 61
Joined: Jul 2006
04-20-2019, 02:02 AM
(This post was last modified: 04-20-2019, 02:03 AM by Kevin .)
no the function in the second version is slightly different
try the 1st function again and comment out this line first
if(&as) as=0
Posts: 726
Threads: 99
Joined: Mar 2018
04-20-2019, 02:44 AM
(This post was last modified: 04-20-2019, 02:46 AM by win .)
Still not working
I found the following separate code,
Function LB_GetSelectedItemsIndexArray
[size=large];/ http://www.quickmacros.com/forum/showthread.php?tid=408&pid=17235#pid17235
function hlb ARRAY ( int ) & selitems
;Gets integer array of selected items 0-based index in a multiple-selection listbox.
int i n= SendMessage ( hlb LB_GETSELCOUNT 0 0 )
if ( n)
, selitems.create ( n)
, SendMessage ( hlb LB_GETSELITEMS n & selitems[0 ]) [/size]
Attached Files
Image(s)
Posts: 726
Threads: 99
Joined: Mar 2018
How to stop the task when I press the ctrl+d hotkey
Macro Macro3
ARRAY ( str ) - lb_selected
str l=
;&sub.m1
;sub.m2
;&sub.m3
;sub.m4
;&sub.m5
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;3 Button 0x54032000 0x0 9 116 56 14 "Run Selected"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
str controls = "5"
str lb5
lb5= l
if ( ! ShowDialog ( dd & sub.DlgProc & controls)) ret
out
lb5= lb_selected
out lb5
#sub DlgProc v
function # hDlg message wParam lParam
int hlb
sel message
, case WM_INITDIALOG
, DT_SetAccelerators ( hDlg "400 Cd" )
, case WM_DESTROY
, case WM_COMMAND goto messages2
ret
;messages2
hlb= id ( 5 hDlg)
sel wParam
, case IDOK
, sub.LB_GetSelectedItems2 ( hlb lb_selected)
,
, case IDCANCEL
,
, case 400 ;;stop
, res hDlg
, ;stop code:
,
, case 3 ;;Run Selected
, min hDlg
, sub.LB_GetSelectedItems2 ( hlb lb_selected)
, _s= lb_selected
, str ss
, foreach ss _s
,, ss.trim
,, opt waitmsg 1
,, sel ss
,,, case "sub.m1"
,,, sub.m1
,,, case "sub.m2"
,,, sub.m2
,,, case "sub.m3"
,,, sub.m3
,,, case "sub.m4"
,,, sub.m4
,,, case "sub.m5"
,,, sub.m5
, res hDlg
ret 1
#sub m1
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m1" "" m)
#sub m2
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m2" "" m)
#sub m3
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m3" "" m)
#sub m4
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m4" "" m)
#sub m5
MES m.timeout= 5 ; m.style= "OCa" ; m.default= 'C'
mes ( "this is m5" "" m)
#sub LB_GetSelectedItems2
function hlb ARRAY ( str ) & a
;Gets text of selected items in a multiple-selection listbox.
int i n= SendMessage ( hlb LB_GETSELCOUNT 0 0 )
if ( n=- 1 ) ;;single-sel control
, a.redim ( 1 )
, if ( LB_SelectedItem ( hlb a[0 ]) < 0 ) a.redim
else
, a.redim ( n)
, if ( n)
,, ARRAY ( int ) selitems.create ( n)
,, SendMessage ( hlb LB_GETSELITEMS n & selitems[0 ])
,, for ( i 0 n) LB_GetItemText hlb selitems[i] a[i]
Posts: 726
Threads: 99
Joined: Mar 2018
Now I have a problem,
In the process of executing sequentially, any sub-function has a problem, the dialog box will be closed
is there a simple exception handling method?
Also, sometimes I need to use a hotkey to terminate execution