Posts: 1,032
Threads: 246
Joined: Jul 2022
02-07-2023, 02:21 PM
(This post was last modified: 02-07-2023, 02:22 PM by Davider.)
Hi,
I need to display the text in the edit box in the newly opened modal window for editing. When the modal window is closed, the modified text is returned to the edit box
As shown in the picture below
https://download.ru/g/1KwVw1VE/QKLqwTlNE...1676038830
Thanks in advance for any advice and help
david
Macro Macro6
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 100 ""
;4 Button 0x54032000 0x0 28 116 48 14 "Sci_Editor"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
e3=
;hello world
;thank you for your help
if(!ShowDialog(dd &sub.DlgProc &controls)) 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 4 ;;Sci_Editor
,_s.getwintext(id(3 hDlg))
,sub.Sci_Editor(hDlg _s)
ret 1
#sub Sci_Editor
function# [hwndOwner] [~txt]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
ret ShowDialog(dd &sub.DlgProc_Sci 0 hwndOwner)
#sub DlgProc_Sci
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
Posts: 1,032
Threads: 246
Joined: Jul 2022
02-07-2023, 11:38 PM
(This post was last modified: 02-08-2023, 12:33 AM by Davider.)
Using global variables tt ( str+ tt=txt) can be successful
But option v or r cannot pass the value of the variable txt (#sub DlgProc_Sci v)
Macro Macro6
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 100 ""
;4 Button 0x54032000 0x0 28 116 48 14 "Sci_Editor"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
e3=
;hello world
;thank you for your help
if(!ShowDialog(dd &sub.DlgProc &controls)) 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 4 ;;Sci_Editor
,_s.getwintext(id(3 hDlg))
,sub.Sci_Editor(hDlg _s)
,_s.setwintext(id(3 hDlg))
ret 1
#sub Sci_Editor
function# [hwndOwner] [~&txt]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
;str+ tt=txt ;;ok
int+ sci
str contrls="3"
str s3
ShowDialog(dd &sub.DlgProc_Sci &contrls hwndOwner)
txt=s3
#sub DlgProc_Sci v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.SetText(txt)
,;sub.SetText(tt) ;;ok
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)
#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)
#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))
#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
Posts: 1,032
Threads: 246
Joined: Jul 2022
I want to modify the selected text, but an error message( cannot paste) appears when return
,case 4 ;;Sci_Editor
,act id(3 hDlg)
,_s.getsel
,out _s
,if empty(_s)
,,_i=1
,,_s.getwintext(id(3 hDlg))
,if sub.Sci_Editor(hDlg _s)
,,out _s
,,if _i
,,,_s.setwintext(id(3 hDlg))
,,else
,,,act id(3 hDlg)
,,,_s.setsel(id(3 hDlg)) ;;err: cannot paste
Macro Macro6
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 100 ""
;4 Button 0x54032000 0x0 28 116 48 14 "Sci_Editor"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
e3=
;hello world
;thank you for your help
if(!ShowDialog(dd &sub.DlgProc &controls)) 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 4 ;;Sci_Editor
,act id(3 hDlg)
,_s.getsel
,out _s
,if empty(_s)
,,_i=1
,,_s.getwintext(id(3 hDlg))
,if sub.Sci_Editor(hDlg _s)
,,out _s
,,if _i
,,,_s.setwintext(id(3 hDlg))
,,else
,,,act id(3 hDlg)
,,,_s.setsel(id(3 hDlg)) ;;err: cannot paste
ret 1
#sub Sci_Editor
function# [hwndOwner] [~&txt]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str+ tt=txt ;;ok
int+ sci
str contrls="3"
str s3
if(!ShowDialog(dd &sub.DlgProc_Sci &contrls hwndOwner)) ret
txt=s3
ret 1
#sub DlgProc_Sci v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,;sub.SetText(txt) ;;no
,sub.SetText(tt) ;;ok
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)
#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
Posts: 1,336
Threads: 61
Joined: Jul 2006
02-08-2023, 05:10 AM
(This post was last modified: 02-08-2023, 05:22 AM by Kevin.)
if you want to share variables with subfunctions you need to declare them in the main function. Then can use v attribute .
here is an alternative way.
int sci
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 100 ""
;4 Button 0x54032000 0x0 28 116 48 14 "Sci_Editor"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3"
str e3
e3="hello world[]thank you for your help"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_APP+10 ;;receive text from child dialog
,str& txt=+lParam
,txt.setwintext(id(3 hDlg))
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4 ;;Sci_Editor
,sub.Sci_Editor(hDlg)
ret 1
#sub Sci_Editor
function# [hwndOwner]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
ShowDialog(dd &sub.DlgProc_Sci 0 hwndOwner)
#sub DlgProc_Sci v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,str text
,text.getwintext(id(3 GetParent(hDlg)))
,sub.SetText(text)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,sub.GetText(text)
,SendMessage GetParent(hDlg) WM_APP+10 hDlg &text
,case IDCANCEL
ret 1
#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)
#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)
#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))
#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
as far as your paste error it's from this.
_s.setsel(id(3 hDlg)) ;;err: cannot paste
should be,
Posts: 1,032
Threads: 246
Joined: Jul 2022
Thanks for your help, I still don't understand some of the code
I need the SCI editor code as a single function, and I have multiple edit box controls.
Modify the text in the currently active edit box, How do I pass parameters?
Macro Multi_editbox
int sci
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 286 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 80 ""
;4 Button 0x54032000 0x0 16 264 74 14 "Sci_Editor(Alt+A)"
;5 Edit 0x54231044 0x204 8 96 208 72 ""
;6 Edit 0x54231044 0x204 8 176 208 80 ""
;1 Button 0x54030001 0x4 112 264 48 14 "OK"
;2 Button 0x54030000 0x4 168 264 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 5 6"
str e3 e5 e6
e3=
;hello world 1
;thank you for your help 1
e5=
;hello world 2
;thank you for your help 2
e6=
;hello world 3
;thank you for your help 3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DT_SetAccelerators(hDlg "401 Aa")
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_APP+10 ;;receive text from child dialog
,str& txt=+lParam
,txt.setwintext(id(3 hDlg))
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [4 401];;Sci_Editor
,Sci_Editor(hDlg)
ret 1
Function Sci_Editor
function# [hwndOwner]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
ShowDialog(dd &sub.DlgProc_Sci 0 hwndOwner)
#sub DlgProc_Sci v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,str text
,text.getwintext(id(3 GetParent(hDlg)))
,sub.SetText(text)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,sub.GetText(text)
,SendMessage GetParent(hDlg) WM_APP+10 hDlg &text
,case IDCANCEL
ret 1
#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)
#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)
#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))
#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
Posts: 1,032
Threads: 246
Joined: Jul 2022
02-08-2023, 08:06 AM
(This post was last modified: 02-08-2023, 08:13 AM by Davider.)
This is the method I use, Use the hotkey Alt+A only
Macro Macro6
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 286 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 80 ""
;4 Button 0x54032000 0x0 16 264 74 14 "Sci_Editor(Alt+A)"
;5 Edit 0x54231044 0x204 8 96 208 72 ""
;6 Edit 0x54231044 0x204 8 176 208 80 ""
;1 Button 0x54030001 0x4 112 264 48 14 "OK"
;2 Button 0x54030000 0x4 168 264 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 5 6"
str e3 e5 e6
e3=
;hello world 1
;thank you for your help 1
e5=
;hello world 2
;thank you for your help 2
e6=
;hello world 3
;thank you for your help 3
int sci
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DT_SetAccelerators(hDlg "401 Aa")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [401] ;;Alt+A
,int hc=GetFocus
,act hc
,_s.getsel
,out _s
,if empty(_s)
,,_i=1
,,_s.getwintext(hc)
,if Sci_Editor(hDlg _s)
,,out _s
,,if _i
,,,_s.setwintext(hc)
,,else
,,,act hc
,,,_s.setsel(0 hc)
,case 5
,act id(3 hDlg)
,_s.getsel
,out _s
,if empty(_s)
,,_i=1
,,_s.getwintext(id(3 hDlg))
,if Sci_Editor(hDlg _s)
,,out _s
,,if _i
,,,_s.setwintext(id(3 hDlg))
,,else
,,,act id(3 hDlg)
,,,_s.setsel(0 id(3 hDlg))
ret 1
Function Sci_Editor
function# [hwndOwner] [~&txt]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str+ tt=txt ;;ok
str contrls="3"
str s3
if(!ShowDialog(dd &sub.DlgProc_Sci &contrls hwndOwner)) ret
txt=s3
ret 1
#sub DlgProc_Sci v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.SetText(tt) ;;ok
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)
#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
Posts: 1,336
Threads: 61
Joined: Jul 2006
can simplify it some get rid of the global variable...
Macro Macro6
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 286 "Dialog" "4"
;3 Edit 0x54231044 0x200 8 8 208 80 ""
;5 Edit 0x54231044 0x204 8 96 208 72 ""
;6 Edit 0x54231044 0x204 8 176 208 80 ""
;4 Static 0x54000001 0x0 16 266 74 14 "Sci_Editor(Alt+A)"
;1 Button 0x54030001 0x4 112 264 48 14 "OK"
;2 Button 0x54030000 0x4 168 264 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "3 5 6"
str e3 e5 e6
e3=
;hello world 1
;thank you for your help 1
e5=
;hello world 2
;thank you for your help 2
e6=
;hello world 3
;thank you for your help 3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DT_SetAccelerators(hDlg "401 Aa")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [401] ;;Alt+A
,int hc=GetFocus
,act hc
,_s.getsel
,if empty(_s)
,,_i=1
,,_s.getwintext(hc)
,if Sci_Editor(hDlg _s)
,,if _i
,,,_s.setwintext(hc)
,,else
,,,act hc
,,,_s.setsel
ret 1
Function Sci_Editor
function# [hwndOwner] [~&txt]
int sci
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 346 206 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 0 0 346 184 ""
;1 Button 0x54030001 0x4 232 188 48 14 "OK"
;2 Button 0x54030000 0x4 288 188 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str contrls="3"
str s3
if(!ShowDialog(dd &sub.DlgProc_Sci &contrls hwndOwner)) ret
txt=s3
ret 1
#sub DlgProc_Sci v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.SetText(txt)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)
#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
Posts: 1,032
Threads: 246
Joined: Jul 2022
More perfect. Thanks again
Posts: 1,032
Threads: 246
Joined: Jul 2022
Macros6 generate exe file, running exe will prompt the following error
Error (RT) in Sci_Editor: failed. Cannot show dialog. The most common reason is an invalid value in dialog definition: an unknown control class or an invalid control style
PS: use Tools -> COM Libraries , I cannot add SCI control class declaration
Posts: 12,075
Threads: 141
Joined: Dec 2002
Copy qmsci.dll from QM folder to exe folder.
And insert this near the start
#if EXE
LoadLibraryW(@_s.expandpath("$qm$\qmsci.dll"))
#endif
Posts: 1,032
Threads: 246
Joined: Jul 2022
worked well, thank you so much
|