Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of SendMessage
#1
Hi All,
I'm trying to learn the use of SendMessage.
So I have a complex Dialog with a Multiline Edit Control and lots of buttons.
The edit control text is populated with C:\temp\test.txt when initialized.
Also when text is added to the control it will get wintext and setfile back to C:\temp\test.txt.
If I manually edit the file C:\temp\test.txt in Notepad and Save, I want to be able to Set the wintext
from the file to the control and leave the blinking cursor at end of text in the control,
without activating the dialog or control.
How would this be possible?

I did see some examples here like Eg: QM editor background color but mainly just for color.
Not sure if I'm on the right track with:
 
Code:
Copy      Help
,int selStart selEnd
,int line=SendMessage(lParam EM_LINEFROMCHAR -1 0)
,SendMessage(lParam EM_SETSEL &selStart &selEnd)
,SendMessage(lParam EM_LINESCROLL 0 line)

Any advice much appreciated, Thanks!
#2
Sorry Scott, didn't see your post till now 

try this didn't have time to fully test
 will need two functions a dialog and a file trigger function
Function Test_txt_sample_dialog
Code:
Copy      Help
str gf.getfile("C:\temp\test.txt")
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 158 "Test Dialog" "4"
;3 Edit 0x54231144 0x200 0 4 228 118 ""
;4 Button 0x54032000 0x0 52 137 48 14 "Reload"
;1 Button 0x54030001 0x4 116 137 48 14 "OK"
;2 Button 0x54030000 0x4 168 137 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3"
str e3=gf
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc v
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 ;;Reload
,str rf.getfile("C:\temp\test.txt")
,if gf<> rf
,,rf.setwintext(id(3 hDlg))
,,SetFocus(GetDlgItem(hDlg, 3));
,,gf=rf
,case EN_SETFOCUS<<16|3
,,SendMessage(lParam WM_VSCROLL SB_BOTTOM 0);;scroll to bottom
,,int sp ep
,,SendMessage(lParam EM_GETSEL &sp &ep)
,,if sp=ep
,,,SendMessage(lParam EM_SETSEL 0 -1);; select  all
,,,SendMessage(lParam EM_SETSEL -1 -1);; deselect all and place caret at end
,,else
,,,SendMessage(lParam EM_SETSEL -1 -1);; deselect all and place caret at end
ret 1

Function Test_txt_FileTrigger
Trigger $f 0x48 "C:\temp" "test.txt"     Help - how to add the trigger to the macro
Code:
Copy      Help
;\
function event $name [$newname]
;event: 1 added, 2 removed, 4 renamed, 8 modified
;out F"{event} {name}"
int w=win("Test Dialog" "#32770")
if w
,str gf.getfile("C:\temp\test.txt")
,gf.setwintext(id(3 w))
,SendMessage(id(3 w) WM_VSCROLL SB_BOTTOM 0);;scroll to bottom
#3
Hi Kevin,
Thanks for the response, I will definitely try to implement these into my dialog.
Yeah I've been fairly busy myself. I will try over the next few days and I'll post back either way.
Thanks again for the help! It is very much appreciated.
Scott

Kevin,
I did test the sample though and it perfectly updates the dialog's text. 

I was thinking if the file is updated, the it updates the dialog, which works perfect, but also
when the dialog is updated, it does setfile back to the txt file upon each keystroke
which I kind of have it doing already. But I was having the trouble with the SendMessage part
for the dialog.  So I think this will work for this project.

My dialog is duplicated on two PC's on my LAN, this is so that both dialogs have the same 
text, realtime.

Thanks Kevin you've been a big help. I'm glad we've got a great group on this forum!
Scott


Forum Jump:


Users browsing this thread: 2 Guest(s)