IonicWind Software

IWBasic => General Questions => Topic started by: Andy on March 31, 2020, 05:08:46 am

Title: EM_GETLINE message
Post by: Andy on March 31, 2020, 05:08:46 am
I'm trying to see if I replace:

CONTROLCMD(w1,1,@RTGETLINE,a-1,line$,255)

w1 is my window
1 is the rich edit control
a-1 is the line number I want
line$ is the string to store the line text.

with the EM_GETLINE message will make another difference on speed.

a link to it is here:
https://docs.microsoft.com/en-us/windows/win32/controls/em-getline

I'm having trouble translating it into a SENDMESSAGE command, can any one help with this please?

Thanks,
Andy.
Title: Re: EM_GETLINE message
Post by: Brian on March 31, 2020, 05:25:18 am
Andy, have a look here:

http://www.jasinskionline.com/windowsapi/ref/e/em_getline.html

Brian
Title: Re: EM_GETLINE message
Post by: Andy on March 31, 2020, 06:27:28 am
Thanks Brian,

That helps but still struggling with it.

Andy.
Title: Re: EM_GETLINE message
Post by: aurelCB on March 31, 2020, 08:54:52 am
Andy use something like this:

SendMessage (riched, EM_GETLINE, i, pt) ' get line from richedit control
riched is control handler
 i - is your line number
 pt is a pointer->Text from a  line i
Title: Re: EM_GETLINE message
Post by: fasecero on March 31, 2020, 04:47:15 pm
Like Aurel said, this is getting the second line for me just fine

Code Select
istring buffer[1000]
_SendMessage(GetDlgItem(w1.hwnd, RICHEDIT_1), EM_GETLINE, 1, &buffer)

if the above code keeps failing for some reason, according to MSDN

QuoteThe first word of the buffer specifies the maximum number of characters that can be copied to the buffer.

That would be something like this

Code Select
istring buffer[1000]
WORD s = 1000 ' 1000 =  256 * 3 + 232
buffer[0] = s >> 8 ' 3
buffer[1] = s & 0xFF ' 232
_SendMessage(GetDlgItem(w1.hwnd, RICHEDIT_1), EM_GETLINE, 1, &buffer)
Title: Re: EM_GETLINE message
Post by: aurelCB on March 31, 2020, 11:48:13 pm
I think that i use 
char Lbuff[1024]

but istring should be fine too.
Title: Re: EM_GETLINE message
Post by: Andy on April 01, 2020, 05:10:38 am
Thanks guys,

Not had a chance today as the electricity has been off today for over 5 hours.

Will have a go...

Thanks,

Andy.
 
Title: Re: EM_GETLINE message
Post by: Andy on April 01, 2020, 05:26:13 am
Well I just tried Fasecero's way, and Aurel's looks correct too.

But I'm obviously making a basic mistake here...

In a console screen I can print the buffer, and the line text if good, but on passing it to a sub routine it does nothing as it's not recognised.

Here are the parameters that the sub routine gets:

SUB ColourLineZ(int LineNoIn,string LineToWords,int Offset)

LineToWords is what the buffer should be.

Help please!

Andy.
Title: Re: EM_GETLINE message
Post by: ckoehn on April 01, 2020, 08:18:47 am
Are you remembering that:

IWBASIC defaults to passing by value for all numeric types and passing by reference for strings, UDT's, etc.

When calling a sub the string LineToWords is passed by reference which is the same as a pointer.

So with in the sub you don't use &LineToWords, just use LineToWords.

I think I'm right, if not someone please correct me.

Later,
Clint
Title: Re: EM_GETLINE message
Post by: aurelCB on April 01, 2020, 12:29:06 pm
Yes ,i think that you have a right .
Andy you can also use type POINTER and cast it <string>tbuffer
Title: Re: EM_GETLINE message
Post by: Andy on July 02, 2020, 03:43:26 am
Well I've managed to load msftedit.dll and use

Code Select
uint rHandle = CreateWindowEx(0,MSFTEDIT_CLASS,"",0x50B010C4,110,100,EndButtons-100,480,w1.hwnd,1,GetModuleHandle(0),0)

to create my rich edit control, however, the EM_GETLINE message no longer works...

Code Select
ISTRING rbuffer[1000]
SENDMESSAGE(HandleIn,EM_GETLINE,a-1,&rbuffer)

HandleIn - handle to the rich edit control
a-1 - the line number I want to get text for
rbuffer - the buffer that stores the line text

If I go back to creating the rich edit control the normal IWB way, the EM_GETLINE code works?

Help please..
Thanks,
Andy.
Title: Re: EM_GETLINE message
Post by: Brian on July 02, 2020, 04:34:52 am
Why are you using HandleIn instead of rHandle? Or am I wrong!

Brian
Title: Re: EM_GETLINE message
Post by: Andy on July 02, 2020, 04:42:18 am
Brian,

Forgot to say the code is in a sub routine, rHandle is passed to it as "HandleIn", even so, if I use rHandle directly it still doesn't return any text.

I have also tried Fasecero's alternative way of setting the buffer with a size before hand - still nothing.

Andy.
Title: Re: EM_GETLINE message
Post by: fasecero on July 03, 2020, 03:26:47 am
The new richedit is probably unicode internally. Try EM_GETLINEW with some unicode buffer.
Title: Re: EM_GETLINE message
Post by: Andy on July 05, 2020, 03:17:19 am
Thanks for that, was wondering the same thing.

I tried what you suggested and to cut a long story short decided that going down this path is becoming very hard work as it is simply not working.

So I have begun trying with my own "undo" buffer for undo's / redo's, and so far it works for characters typed. I will obviously need to do more work on this but it was either a case of spend time solving the built in undo feature or write my own undo / redo code.

Thanks again,
Andy.
:)