PDA

View Full Version : RichEdit AutoScroll?



catventure
17-01-2006, 15:56
Hi Eros,

I found these snippets doing a search about 'richedit scrolling' on Powerbasic forums:


-----------------------
When the RichText box is filled, I want it to
automatically scroll so that the last line entered into it is
always visible rather than the first line of text entered (in
other words, I want the box to auto-scroll to the bottom).

I have no doubt there's a faily easy way to do this but my head
hurts from beating it against the wall to find it. Any
assistance would be VERY greatly appreciated.

----------------------

The easy way is by using EM_REPLACESEL to set text. Works like paste - RichEdit
will scroll to end of inserted text. Can use EM_EXSETSEL to control position
and if something should be replaced. But if text only is added to end, no need
to do anything, since input pos then always will be at the end with this message.

And in case you didn't know: to avoid auto-selection of all when RichEdit gets
focus one can simply include %ES_SAVESEL style at creation.

---------------------------

Thanks much for pointing me in the right direction
***** %EM_SCROLLCARET solved the problem. *****

------------------------------

' replace selected text with result string
CONTROL SEND CBHNDL, %txt_richedit, %EM_REPLACESEL, 1, STRPTR( pString )

' scroll to the carrot cursor
CONTROL SEND CBHNDL, %txt_richedit, %EM_SCROLLCARET, 0, 0

------------------------------

Try EM_SETSEL to place the cursor at the end of the contents of the edit control, followed by a EM_SCROLLCARET to bring the cursor into view.
-------------------------------

Maybe this info will provide a solution, Eros??
%EM_REPLACESEL with %EM_SCROLLCARET
What do you think? I dunno how to write these in thinBASIC.

Regards,
catventure.

Petr Schreiber
17-01-2006, 16:50
Hi Catventure,

If you need the value of equates, here they are ( just paste into code ):


%EM_REPLACESEL = &HC2
%EM_SCROLLCARET = &HB7


I'm now on computer with no thinBASIC installed, so I can't help you more at this time


Psch

catventure
18-01-2006, 18:23
Thanks , Psch.

Don't know how useful they will be..

Today, I tried to do the scrolling using the eventmask (as in richedit example) to capture changes in richedit via window handler and tried to manipulate scrolling from there using %em_scrollcaret and others - but didn't work :cry:

Anyone else got any good ideas?
catventure.

Petr Schreiber
18-01-2006, 21:43
Hi Catventure,

I'v got solution !
Replace "ShowText" function in your T.A.B. project with this one:



function showtext() as long
dim a as string

control append text hwnd,%id_RICHEDIT2,sprint

control get text hwnd,%id_RICHEDIT2 to a
CONTROL SEND hwnd, %id_RICHEDIT2, %EM_SETSEL , len(a),len(a)
CONTROL SEND hwnd, %id_RICHEDIT2, %EM_SCROLLCARET, 0, 0
end function



It really works, at least on WinME. Hope on your box too.
Let me know !

Petr

catventure
18-01-2006, 22:10
Hi Psch,

Well done, Psch.
Yes that code *should* work. I have seen it as a poss solution on other forums so believe it will work.
But it does NOT on my Win98 :cry:

I've tried it with control post, control send and sendmessage. It will not scroll. I also tried other similar ways earlier today and yesterday.

What richedit dll is being used by you?

Mine is using riched32.dll (which is actually version 2 of microsoft richedit)
but I also have riched20.dll (which despite its number is actually version 3!)

If I could get it to use riched20.dll maybe your fantastic solution will work for me??

Maybe there's a way in Tb that will allow me to use this later riched library?

Many thanks,
catventure.

catventure
19-01-2006, 11:47
Hi,

Well it appears that riched32.dll is just a stub for loading riched20.dll - so it IS using that dll! Maybe its a Win98 problem as Eros thought? I did it using IBasic (and that must have used the same dll? )so maybe it will still be possible...

How I wish that microsoft had come up with a more standardised and compatible control.

catventure

Petr Schreiber
19-01-2006, 16:33
Hi Catventure,

Yes I have mayor version of RichEd20.DLL - version 3.
But I agree it must be possible to do it other way, for example
if it works in thinAIR on your box ( during search ), then there must be a way.

Maybe there is technique to send PageDown press to the richedit ?
I'v seen "SendKeys" function in thinBASIC help file, but I'm not sure how it works :(


Psch

catventure
19-01-2006, 21:30
Hi Psch,

I think we both have same dll.

Now I have tried below code and it sort of works except when TAB has finished outputting text I have to "click" (not scroll at all) on the vert scrollbar and the text appears and looks to have scrolled properly....! I am not 'moving' the scrollbar but merely clicking it and presto text appears! The question is how to make it do it without clicking scrollbar???
Can you please try and let me know?

'---rem define these at top of program
%SB_BOTTOM=7
%SB_PAGEUP=2




function showtext() as long

control append text hwnd,%ID_RICHEDIT2,sprint

control send hwnd,%ID_RICHEDIT2,%EM_linescroll,0,%SB_bottom

control send hwnd,%ID_RICHEDIT2,%EM_linescroll,0,%SB_pageup

end function



If you can help at all please reply. I need a break from it for time being.


Best wishes,
catventure.

ErosOlmi
19-01-2006, 23:00
Catventure,

I've tested again Petr suggestion under WIN98 and it should work. The only difference is that in my testing WIN98 machine I've IE 6.x version installed while you have an early version and this can make the difference.

Anyhow, on my WIN98 box this function seems to do the job:

function ShowText() as long
dim sBuffer as string

control append text hwnd, %id_RICHEDIT2, sprint

'---Scroll RichEdit at its bottom
'---Get the full richedit text buffer
control get text hwnd, %id_RICHEDIT2 to sBuffer

'---Select the last char of the buffer. wParam is starting point, lParam is ending point
CONTROL SEND hwnd, %id_RICHEDIT2, %EM_SETSEL , len(sBuffer ), len(sBuffer )

'---Tell edit control to scroll at the caret position
CONTROL SEND hwnd, %id_RICHEDIT2, %EM_SCROLLCARET, 0, 0

end function

Please try again and let me know.
Do you have the option to try TAB under a different machine with WIN98?
Also, if you do not have already installed, please install thinBasic preview version 1.0.9.0

Ciao
Eros

Petr Schreiber
19-01-2006, 23:05
Hi Eros,

just a little correction in your example:



CONTROL SEND hwnd, %id_RICHEDIT2, %EM_SETSEL , len(a), len(a)


... should be replaced with ...



CONTROL SEND hwnd, %id_RICHEDIT2, %EM_SETSEL , len(sBuffer), len(sBuffer)


It's just little detail. I hope I could perform some tests on brothers computer with Win98 FE ( first edition :) )

Bye,
Petr

ErosOlmi
19-01-2006, 23:08
That's right.

catventure
20-01-2006, 02:21
Hi,

I installed IE6 latest from microsoft downloads for win98.

Eros: Sorry to report that Psch example still doesn't work. Copied exactly as above.
(Also tooltips example prog still no joy)

I am now getting 1.0.9.0 to try...

====
OK. Got 1.0.9.0. Psch example still no work. I may have been too hasty about tooltips. They are appearing now more frequently in example. Different shape too. Smaller and more rectangular like in ThinAir iconbar... Sometimes have to click in textboxes first before they will show - but don't always work on mouseover unless I'm missing the 'hotspots' that activate them... :)

Regards,
catventure

Petr Schreiber
20-01-2006, 10:21
Hi Catventure,

that's very strange. I'v tested T.A.B now on brothers Win98 box. Although he has old Internet Explorer ( version 5.0 ) all works perfect! I don't know how much matters it's czech version of Win.

Hadn't you some conflict with kind of dark magician in the past :) ?


Psch

catventure
20-01-2006, 16:40
Hi,

SUCCESS! ***YES*** It works.

I reinstalled richedit version 3 (riched32.dll + riched20.dll) to latest version using a microsoft download. Works great now. Phew!!!!!!

Sorry. I did already have these versions but perhaps not properly installed?
I wish I had known. It would have saved me hours....
Anyway, as a plus I got to know the richedit control a lot better.

Currently using:
riched20.dll - version 5.30.23.12212
riched32.dll - version 5.0.1461.82

It occurred to me it best to do this after Psch report on brothers 98 box.
My jaw dropped in surprise when it worked! :)
Thanks Psch for that testing. And Eros of course You have both helped me to solve it in the end.

Psch code now works great.

To complete the adventure scroller (until colored text; rtf etc.. is possible) I just need now to stop the scroll when MORE than a pageful of text is to be shown during one turn of the game, so the player can read before pressing a key to display rest of text - otherwise portions of text will scroll out of sight before player has chance to read it... Another challenge!

catventure. (Phil)