Newyana2
2023-06-13 13:10:17 UTC
"R.Wieser" <***@is.invalid> wrote
| As you have mentioned to have done quite a bit with the RichEdit control,
| maybe you can help me understand a problem I had a while ago.
|
| I loaded an RTF file (containing multiple font sizes) into a RichEd20
| control, Than Itried to save the cursor position using EM_GETSCROLLPOS and
| later restore the position using EM_SETSCROLLPOS.
|
| The problem ? Even when I executed those two commands directly after the
| other* the cursor jumped up a number of lines.
|
I sandwich operations between LockWindowUpdate
on the parent window. I also sometimes add EnableWindow
on the RichEdit itself. The former blocks painting. The
latter blocks input from mouse and keyboard.
DoEvents
LockWindowUpdate ParentWindow.hWnd
EnableWindow hRE.hWnd, False
' [Here I might do something like read out the
RE content and run the string through a tokenizing
routine to update formatting, colors, or whatever,
then put back the new RTF text.]
EnableWindow hRE.hWnd, True
LockWindowUpdate 0
At some point MS decided LockWindowUpdate should not be
used and recommended a WM_SETREDRAW message instead.
If I remember correctly, LWU wraps that message along with
other operations. I never understood the hubbub. Raymond
Chen goes on about how all hell will break loose if you start
running LWU on multiple windows because there's no window
handle for unlocking. But I don't see a problem with that. I'm
not doing it with multiple windows and I only do it for a fraction
of a second. It may be possible for another program to make
the same call during that fraction of a second while someone is
using my editor, but that's farfetched. At any rate, you can try
WM_SETREDRAW. Both block painting but keep track of changes
for painting after unlock. EnableWindow, by contrast, is used to
block input to the window entirely while a locking operation is
going on.
I find that if I can do all operations in less than 1/4 second
then the window display is smooth and the content just updates
in appearance. I don't if that covers the problem you're having.
I Guess I typically record SelStart before any operation and
then return it to that position. EM_GETSEL and EM_SETSEL.
I don't get how you're doing any of this with script, but I'll
leave you to it. :) However, getting, setting SelStart requires
a long pointer to a CHARRANGE STRUCT. The STRUCT is two
longs, which specify the starting point and ending point of
a specified set of characters. You dson't have to care about that
if you just return the CHARRANGE from GET to the SET operation,
but you will need to handle a CHARRANGE.
| P.s.
| I posted the question here as you frequent this newsgroup. But I've set
| the follow-up to "comp.os.ms-windows.programmer.win32". If thats not a
| newsgroup your newsgroup provider carries than please remove the
| redirection.
|
I'll find out, I guess. I'm setting it for both, since
it's possible someone here would be curious. I used
to visit maybe 6-7 programming groups, including
Win32 API. I didn't know there were any still left.
The only one I still go to is vb.general.discussion,
which still gets regular traffic.
| As you have mentioned to have done quite a bit with the RichEdit control,
| maybe you can help me understand a problem I had a while ago.
|
| I loaded an RTF file (containing multiple font sizes) into a RichEd20
| control, Than Itried to save the cursor position using EM_GETSCROLLPOS and
| later restore the position using EM_SETSCROLLPOS.
|
| The problem ? Even when I executed those two commands directly after the
| other* the cursor jumped up a number of lines.
|
I sandwich operations between LockWindowUpdate
on the parent window. I also sometimes add EnableWindow
on the RichEdit itself. The former blocks painting. The
latter blocks input from mouse and keyboard.
DoEvents
LockWindowUpdate ParentWindow.hWnd
EnableWindow hRE.hWnd, False
' [Here I might do something like read out the
RE content and run the string through a tokenizing
routine to update formatting, colors, or whatever,
then put back the new RTF text.]
EnableWindow hRE.hWnd, True
LockWindowUpdate 0
At some point MS decided LockWindowUpdate should not be
used and recommended a WM_SETREDRAW message instead.
If I remember correctly, LWU wraps that message along with
other operations. I never understood the hubbub. Raymond
Chen goes on about how all hell will break loose if you start
running LWU on multiple windows because there's no window
handle for unlocking. But I don't see a problem with that. I'm
not doing it with multiple windows and I only do it for a fraction
of a second. It may be possible for another program to make
the same call during that fraction of a second while someone is
using my editor, but that's farfetched. At any rate, you can try
WM_SETREDRAW. Both block painting but keep track of changes
for painting after unlock. EnableWindow, by contrast, is used to
block input to the window entirely while a locking operation is
going on.
I find that if I can do all operations in less than 1/4 second
then the window display is smooth and the content just updates
in appearance. I don't if that covers the problem you're having.
I Guess I typically record SelStart before any operation and
then return it to that position. EM_GETSEL and EM_SETSEL.
I don't get how you're doing any of this with script, but I'll
leave you to it. :) However, getting, setting SelStart requires
a long pointer to a CHARRANGE STRUCT. The STRUCT is two
longs, which specify the starting point and ending point of
a specified set of characters. You dson't have to care about that
if you just return the CHARRANGE from GET to the SET operation,
but you will need to handle a CHARRANGE.
| P.s.
| I posted the question here as you frequent this newsgroup. But I've set
| the follow-up to "comp.os.ms-windows.programmer.win32". If thats not a
| newsgroup your newsgroup provider carries than please remove the
| redirection.
|
I'll find out, I guess. I'm setting it for both, since
it's possible someone here would be curious. I used
to visit maybe 6-7 programming groups, including
Win32 API. I didn't know there were any still left.
The only one I still go to is vb.general.discussion,
which still gets regular traffic.