Posts: 125
Threads: 20
Joined: Jan 2021
hello everyone,
I need to use regular expressions to match all double byte characters, use the following code, and output only one result
I expect The results :
文字一
文字二
文字三
文字四
QM not fully support regular expressions? Any suggestions are welcome. Thanks in advance
Macro Macro15
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str pattern="(?<!//)[\x80-\xff]+"
int i; ARRAY(str) a
if(findrx(_s pattern 0 0 a)<0) out "does not match"; ret
for i 0 a.len
,out a[i]
Posts: 12,061
Threads: 140
Joined: Dec 2002
Use flag 4. Then the array has 2 dimensions.
Macro Macro3096
if(findrx(_s pattern 0 4 a)<0) out "does not match"; ret
for i 0 a.len
,out a[0 i]
Posts: 125
Threads: 20
Joined: Jan 2021
01-03-2021, 12:29 AM
(This post was last modified: 01-03-2021, 12:32 AM by macman.)
oh, Thanks Gintaras.Thank you for your help
I have another question: How to determine whether an array element exists?
I want to fill 10 EditBox in the dialog box with matched elements, but the number of matched elements may be less than 10,
I want to add a branch statement, for example:
if(a[0 0]) e3 = a[0 0] ; else e3 = ""
I expect The results :
If the element exists, it will be displayed in the EditBox. If it does not exist, the EditBox will be empty 【""】
for example, the following code
Macro Macro14
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x204 8 88 96 12 ""
;8 Edit 0x54030080 0x204 120 8 96 12 ""
;9 Edit 0x54030080 0x204 120 28 96 13 ""
;10 Edit 0x54030080 0x204 120 48 96 12 ""
;11 Edit 0x54030080 0x204 120 68 96 13 ""
;12 Edit 0x54030080 0x204 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
ARRAY(str) a
str pattern="[\x80-\xff]+"
if(findrx(_s pattern 0 4 a)<0) out "does not match"; ret
e3 = a[0 0]
e4 = a[0 1]
e5 = a[0 2]
e6 = a[0 3]
e7 = a[0 4]
;e8 = a[0 5]
;e9 = a[0 6]
;e10 = a[0 7]
;e11 = a[0 8]
;e12 = a[0 9]
if(!ShowDialog(dd 0 &controls)) ret
Posts: 1,335
Threads: 61
Joined: Jul 2006
this will do what you need.
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x204 8 88 96 12 ""
;8 Edit 0x54030080 0x204 120 8 96 12 ""
;9 Edit 0x54030080 0x204 120 28 96 13 ""
;10 Edit 0x54030080 0x204 120 48 96 12 ""
;11 Edit 0x54030080 0x204 120 68 96 13 ""
;12 Edit 0x54030080 0x204 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
ARRAY(str) a
str pattern="[\x80-\xff]+"
if(findrx(_s pattern 0 4 a)<0) out "does not match"; ret
for int'i 0 a.len
,sel i
,,case 0
,,e3 = a[0 i]
,,case 1
,,e4 = a[0 i]
,,case 2
,,e5 = a[0 i]
,,case 3
,,e6 = a[0 i]
,,case 4
,,e7 = a[0 i]
,,case 5
,,e8 = a[0 i]
,,case 6
,,e9 = a[0 i]
,,case 7
,,e10 = a[0 i]
,,case 8
,,e11 = a[0 i]
,,case 9
,,e12 = a[0 i]
if(!ShowDialog(dd 0 &controls)) ret
Posts: 125
Threads: 20
Joined: Jan 2021
@kevin
Thank you for your help, Code works final,
Now, I add the search and replace function at the end of the code. It seems to be a little difficult to use the SLE statement
I want to replace the original string with the string entered into the editbox
Macro Macro16
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x204 8 88 96 12 ""
;8 Edit 0x54030080 0x204 120 8 96 12 ""
;9 Edit 0x54030080 0x204 120 28 96 13 ""
;10 Edit 0x54030080 0x204 120 48 96 12 ""
;11 Edit 0x54030080 0x204 120 68 96 13 ""
;12 Edit 0x54030080 0x204 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
ARRAY(str) a
str pattern="[\x80-\xff]+"
if(findrx(_s pattern 0 4 a)<0) out "does not match"; ret
for int'i 0 a.len
,sel i
,,case 0
,,e3 = a[0 i]
,,case 1
,,e4 = a[0 i]
,,case 2
,,e5 = a[0 i]
,,case 3
,,e6 = a[0 i]
,,case 4
,,e7 = a[0 i]
,,case 5
,,e8 = a[0 i]
,,case 6
,,e9 = a[0 i]
,,case 7
,,e10 = a[0 i]
,,case 8
,,e11 = a[0 i]
,,case 9
,,e12 = a[0 i]
if(!ShowDialog(dd 0 &controls)) ret
_s.findreplace(a[0 0] F"{e3}")
_s.findreplace(a[0 1] F"{e4}")
_s.findreplace(a[0 2] F"{e5}")
_s.findreplace(a[0 3] F"{e6}")
_s.findreplace(a[0 4] F"{e7}")
_s.findreplace(a[0 5] F"{e8}")
_s.findreplace(a[0 6] F"{e9}")
_s.findreplace(a[0 7] F"{e10}")
_s.findreplace(a[0 8] F"{e11}")
_s.findreplace(a[0 9] F"{e12}")
out _s
Posts: 1,335
Threads: 61
Joined: Jul 2006
01-03-2021, 03:31 AM
(This post was last modified: 01-03-2021, 03:32 AM by Kevin.)
since the number of elements in the array can vary. you cant just access an element that doesn't exist. It will cause an error. That was the main reason for using sel. you can do the same thing when the dialog closes
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x204 8 88 96 12 ""
;8 Edit 0x54030080 0x204 120 8 96 12 ""
;9 Edit 0x54030080 0x204 120 28 96 13 ""
;10 Edit 0x54030080 0x204 120 48 96 12 ""
;11 Edit 0x54030080 0x204 120 68 96 13 ""
;12 Edit 0x54030080 0x204 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
ARRAY(str) a
str pattern="[\x80-\xff]+"
if(findrx(_s pattern 0 4 a)<0) out "does not match"; ret
for int'i 0 a.len
,sel i
,,case 0
,,e3 = a[0 i]
,,case 1
,,e4 = a[0 i]
,,case 2
,,e5 = a[0 i]
,,case 3
,,e6 = a[0 i]
,,case 4
,,e7 = a[0 i]
,,case 5
,,e8 = a[0 i]
,,case 6
,,e9 = a[0 i]
,,case 7
,,e10 = a[0 i]
,,case 8
,,e11 = a[0 i]
,,case 9
,,e12 = a[0 i]
if(!ShowDialog(dd 0 &controls)) ret
i=0
for i 0 a.len
,sel i
,,case 0
,,_s.findreplace(a[0 i] F"{e3}")
,,case 1
,,_s.findreplace(a[0 i] F"{e4}")
,,case 2
,,_s.findreplace(a[0 i] F"{e5}")
,,case 3
,,_s.findreplace(a[0 i] F"{e6}")
,,case 4
,,_s.findreplace(a[0 i] F"{e7}")
,,case 5
,,_s.findreplace(a[0 i] F"{e8}")
,,case 6
,,_s.findreplace(a[0 i] F"{e9}")
,,case 7
,,_s.findreplace(a[0 i] F"{e10}")
,,case 8
,,_s.findreplace(a[0 i] F"{e11}")
,,case 9
,,_s.findreplace(a[0 i] F"{e12}")
out _s
Posts: 125
Threads: 20
Joined: Jan 2021
01-03-2021, 04:04 AM
(This post was last modified: 01-03-2021, 04:18 AM by macman.)
How to prevent repeated replacement?
In some cases, the result of the replacement is incorrect
When some strings repeat, this replacement method is not reliable. Is there a better solution?
Posts: 125
Threads: 20
Joined: Jan 2021
01-03-2021, 09:48 AM
(This post was last modified: 01-03-2021, 10:03 AM by macman.)
@kevin
How to delete the line starting with // From multiple lines of text?
for example:
Macro Macro19
Trigger A6
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
;delete the line starting with //
out _s
Posts: 125
Threads: 20
Joined: Jan 2021
01-04-2021, 12:32 AM
(This post was last modified: 01-04-2021, 12:55 AM by macman.)
I can delete the comment line with the following code, but it will produce an empty line
Macro Macro20
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
_s.replacerx("//.*" "")
out _s
Perfect solution to the problem
_s.replacerx("//.*\n" "")
Posts: 1,335
Threads: 61
Joined: Jul 2006
01-04-2021, 06:27 AM
(This post was last modified: 01-04-2021, 06:47 AM by Kevin.)
Use this for your replacement code fixes(In some cases, the result of the replacement is incorrect)Your original code was starting the search every time at the beginning of the string. this will prevent that.
int ci
for i 0 a.len
,sel i
,,case 0
,,ci=_s.findreplace(a[0 i] F"{e3}")
,,case 1
,,ci=_s.findreplace(a[0 i] F"{e4}" 4 "" ci+e3.len)
,,case 2
,,ci=_s.findreplace(a[0 i] F"{e5}" 4 "" ci+e4.len)
,,case 3
,,ci=_s.findreplace(a[0 i] F"{e6}" 4 "" ci+e5.len)
,,case 4
,,ci=_s.findreplace(a[0 i] F"{e7}" 4 "" ci+e6.len)
,,case 5
,,ci=_s.findreplace(a[0 i] F"{e8}" 4 "" ci+e7.len)
,,case 6
,,ci=_s.findreplace(a[0 i] F"{e9}" 4 "" ci+e8.len)
,,case 7
,,ci=_s.findreplace(a[0 i] F"{e10}" 4 "" ci+e9.len)
,,case 8
,,ci=_s.findreplace(a[0 i] F"{e11}" 4 "" ci+e10.len)
,,case 9
,,ci=_s.findreplace(a[0 i] F"{e12}" 4 "" ci+e11.len)
Posts: 125
Threads: 20
Joined: Jan 2021
@kevin
Thank you very much. The code works very well
Posts: 125
Threads: 20
Joined: Jan 2021
@kevin
Because sometimes I need to output the original string, I add a button to implement it
But the following code doesn't work. What should I do? Thanks in advance
Macro Macro9
_s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;13 Button 0x54030001 0x4 64 116 48 14 "Original"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
str ss = _s ;;Original string
_s.replacerx("\s*//.*" "") ;;Processed string
#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 13
,out ss ;;out Original string
,case IDOK
,out _s ;;out Processed string
,case IDCANCEL
ret 1
Posts: 1,335
Threads: 61
Joined: Jul 2006
use a thread Variable
change _s to
str- s
str- s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run 文字一run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;文字三document.Save("test.docx");文字四
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;13 Button 0x54030001 0x4 64 116 48 14 "Original"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,str- s
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 13
,out s ;;out Original string
,case IDOK
,case IDCANCEL
ret 1
Posts: 125
Threads: 20
Joined: Jan 2021
Skillfully deflected thanks a lot
Posts: 125
Threads: 20
Joined: Jan 2021
@kevin
Why can't paste it
Macro Macro15
Trigger A5
str- s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;document.Save("文字三");
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;13 Button 0x54030001 0x4 64 116 48 14 "Original"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
_s = s
_s.replacerx("\s*//.*" "")
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
paste _s
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,str- s
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 13
,out s ;;success
,paste s ;;fail
,DT_Cancel(hDlg)
,case IDOK
,case IDCANCEL
ret 1
Posts: 1,335
Threads: 61
Joined: Jul 2006
where are you trying to paste it to?
Posts: 125
Threads: 20
Joined: Jan 2021
The insertion point in the document
Posts: 1,335
Threads: 61
Joined: Jul 2006
When you click the dialog button the focus is now on that button. The Insertion Point doesn't exist anymore. Need to activate the document before using paste.
Posts: 125
Threads: 20
Joined: Jan 2021
It's a bit strange. I'm in the insertion point status of the document, and I still can't paste it
Posts: 1,335
Threads: 61
Joined: Jul 2006
please show a video of the problem
Posts: 125
Threads: 20
Joined: Jan 2021
Posts: 1,335
Threads: 61
Joined: Jul 2006
Thank you .It is what I thought the issue was.
need to activate notepad window first.
change code to this
,case 13
,out s ;;success
,int w=win("" "Notepad")
,int c=id(15 w) ;;editable text 'Text Editor
,act c
,paste s
,DT_Cancel(hDlg)
Posts: 125
Threads: 20
Joined: Jan 2021
01-05-2021, 04:08 AM
(This post was last modified: 01-05-2021, 04:13 AM by macman.)
The input window is uncertain
why?
paste _s
It is valid in all windows with input points
Posts: 1,335
Threads: 61
Joined: Jul 2006
01-05-2021, 04:14 AM
(This post was last modified: 01-05-2021, 04:24 AM by Kevin.)
Paste Fails while the dialog is open because the dialog is the active window. But once the dialog closes , notepad is the active window again so paste works.
the variable makes no difference. It's because notepad is not the active window. Yes paste needs an active window. Need to get the handle of notepad and make sure it is the active window before using paste.
You could use other commands such as setwintext which can set text to a background window. also can use setsel
once you click the button on the dialog window even the dialog control loses focus and has no caret. Because the focus has been moved to the button.
Posts: 125
Threads: 20
Joined: Jan 2021
I removed the button【Original】 and now 【paste s】 works, but there's no way to cancel
Macro Macro15
Trigger A5
str- s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;document.Save("文字三");
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
_s = s
_s.replacerx("\s*//.*" "")
;if(!ShowDialog(dd &sub.DlgProc &controls)) ret
if(!ShowDialog(dd &sub.DlgProc &controls)) paste s; ret
paste _s
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,str- s
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Posts: 1,335
Threads: 61
Joined: Jul 2006
another way using setsel
,case 13
,out s ;;success
,int w=win("" "Notepad2")
,int c=id(64259 w) ;;Scintilla
,s.setsel(0 c)
,DT_Cancel(hDlg)
or
,case 13
,out s ;;success
,int w=win("" "Notepad2")
,act w
,paste s
,DT_Cancel(hDlg)
Posts: 125
Threads: 20
Joined: Jan 2021
01-05-2021, 05:35 AM
(This post was last modified: 01-05-2021, 05:36 AM by macman.)
I need to paste it in multiple software windows
Posts: 1,335
Threads: 61
Joined: Jul 2006
01-05-2021, 05:52 AM
(This post was last modified: 01-05-2021, 05:55 AM by Kevin.)
this should work for you. Gets handle of active window when ctrl+F5 is pressed
and stores it for use later when button is clicked.
So just need to make sure the correct window is active before pressing ctrl+F5.
Function DialogTester
Trigger AF5
int- windowHandle=win()
str- s=
;DocumentModel document = new DocumentModel();
;
;Section section = new Section(document);
;document.Sections.Add(section);
;
;Paragraph paragraph = new Paragraph(document);
;section.Blocks.Add(paragraph);
;
;Run run = new Run(document, "文字二");
;paragraph.Inlines.Add(run);
;
;document.Save("文字三");
;
;//文字
;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;13 Button 0x54030001 0x4 64 116 48 14 "Original"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
_s = s
_s.replacerx("\s*//.*" "")
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
paste _s
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,str- s
,int- windowHandle
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 13
,out s ;;success
,act windowHandle
,paste s
,DT_Cancel(hDlg)
,case IDOK
,case IDCANCEL
ret 1
Posts: 125
Threads: 20
Joined: Jan 2021
01-05-2021, 06:28 AM
(This post was last modified: 01-05-2021, 06:36 AM by macman.)
Good idea. Code works well
@kevin
Using #10 code, there are still replacement errors, which seems a little difficult
Macro Macro9
Trigger A5
_s=
;class Program
;{
;,static void Main()
;,{
;,,ComponentInfo.SetLicense("FREE-LIMITED-KEY");
;
;,,DocumentModel document = new DocumentModel();
;
;,,Section section = new Section(document);
;,,document.Sections.Add(section);
;
;,,Paragraph paragraph = new Paragraph(文件);
;,,section.Blocks.Add(paragraph);
;
;,,Run run = new Run(document, "文字");
;,,paragraph.Inlines.Add(run);
;
;,,document.Save("文件名.docx");
;,}
;}
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Edit 0x54030080 0x200 8 68 96 13 ""
;7 Edit 0x54030080 0x200 8 88 96 12 ""
;8 Edit 0x54030080 0x200 120 8 96 12 ""
;9 Edit 0x54030080 0x200 120 28 96 13 ""
;10 Edit 0x54030080 0x200 120 48 96 12 ""
;11 Edit 0x54030080 0x200 120 68 96 13 ""
;12 Edit 0x54030080 0x200 120 88 96 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 5 6 7 8 9 10 11 12"
str e3 e4 e5 e6 e7 e8 e9 e10 e11 e12
ARRAY(str) a
str pattern="[\x80-\xff]+" ;;Match all double byte characters
if(findrx(_s pattern 0 4 a)<0) out "does not match"; ret
for int'i 0 a.len
,sel i
,,case 0
,,e3 = a[0 i]
,,case 1
,,e4 = a[0 i]
,,case 2
,,e5 = a[0 i]
,,case 3
,,e6 = a[0 i]
,,case 4
,,e7 = a[0 i]
,,case 5
,,e8 = a[0 i]
,,case 6
,,e9 = a[0 i]
,,case 7
,,e10 = a[0 i]
,,case 8
,,e11 = a[0 i]
,,case 9
,,e12 = a[0 i]
if(!ShowDialog(dd 0 &controls)) ret
int ci
for i 0 a.len
,sel i
,,case 0
,,ci=_s.findreplace(a[0 i] F"{e3}")
,,case 1
,,ci=_s.findreplace(a[0 i] F"{e4}" 4 "" ci+e3.len)
,,case 2
,,ci=_s.findreplace(a[0 i] F"{e5}" 4 "" ci+e4.len)
,,case 3
,,ci=_s.findreplace(a[0 i] F"{e6}" 4 "" ci+e5.len)
,,case 4
,,ci=_s.findreplace(a[0 i] F"{e7}" 4 "" ci+e6.len)
,,case 5
,,ci=_s.findreplace(a[0 i] F"{e8}" 4 "" ci+e7.len)
,,case 6
,,ci=_s.findreplace(a[0 i] F"{e9}" 4 "" ci+e8.len)
,,case 7
,,ci=_s.findreplace(a[0 i] F"{e10}" 4 "" ci+e9.len)
,,case 8
,,ci=_s.findreplace(a[0 i] F"{e11}" 4 "" ci+e10.len)
,,case 9
,,ci=_s.findreplace(a[0 i] F"{e12}" 4 "" ci+e11.len)
paste _s
Posts: 1,335
Threads: 61
Joined: Jul 2006
easy fix change
,,case 0
,,ci=_s.findreplace(a[0 i] F"{e3}")
to
,,case 0
,,ci=_s.findreplace(a[0 i] F"{e3}" 4)
|