News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Rich Edit Control Insertion Point

Started by z941998, January 25, 2012, 09:58:02 PM

Previous topic - Next topic

z941998

How do I access the insertion point for a Rich Edit Control?

I can format text with selection method and now want to try automation with using a table of various items and the insertion point to control formating on the fly (Like highlighting a coloumn of data and not the whole para).

jj2007

What do you mean with insertion point? The position where the x appears when you type x?
Re columns in a table, could you show an example, e.g. make a copy of the table e.g. in MS Word and format the copy, so that we can see the result?

z941998

I understand the insertion point is where the cursor is at while inputing and editing text, so your example of x is the same.

Example of column data

01  05  08   Test
02  05  09   Text
03  05  10   Testing


Selecting only the 05's and coloring the red.


hutch--

The sense that you use the term insertion point is satisfied by the CHARRANGE structure and the messages that pass it. If you have some technique to set the text colour you can set the characters in the column to whatever colour you like but a rich edit control has no method available to perform vertical selection.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: z941998 on January 26, 2012, 12:46:34 AM
Example of column data

01  05  08   Test
02  05  09   Text
03  05  10   Testing

Selecting only the 05's and coloring the red.

If your table is tab-delimited, there is a chance to do it:
- select the top 05
- calc the number of tabs (1)
- go line by line and colour in red what is between tab1 and tab2
- stop when you find a line without tabs

Not elegant but feasible.

z941998

I am developing this technique for an app as Hutch has pointed out there is no method to do this.

My thought was if I can stream data to a rich edit and then insert some data (table) I need a way to determine where I am at.  I have used the CHARRANGE which does the job, but I get several flickers of the screen while I am updataing the colors of the appropriate cols.

I thought I could write to the screen once and have the attributes (color or whatever) apply and have no flickers of the screen and be done with it.  When I read the SDK it indicates using the insertion point but does not give a default versus selecting a range and then formating.

I will give this some more thought and get back to you, Steve


jj2007

To get the insertion point, use
LOCAL txrg:TEXTRANGE
  invoke SendMessage, hRE, EM_EXGETSEL, 0, addr txrg


For the flicker, I can give you these macros:

Refresh_ON   EQU invoke UpdateRE, -1
Refresh_OFF   EQU invoke UpdateRE, 0
....
UpdateRE proc flag:DWORD
  pushad
  mov ebx, DefMask
  mov esi, flag      ; -1=Refresh_ON, 0=Refresh_OFF
  and ebx, esi
  invoke SendMessage, hRE, EM_SETEVENTMASK, 0, ebx
  invoke SendMessage, hRE, WM_SETREDRAW, esi, 0
  .if esi
   invoke InvalidateRect, hRE, 0, 0   ; redraw the RichEdit window
  .endif
  popad
  ret
UpdateRE endp

z941998

Thanks JJ - I forgot about refreshining - I give it a try

jj2007

Here is a little table for testing. In RichMasm (the MasmBasic editor), you can insert a table by pressing Control G and inserting e.g. tbl=5*3*80 into the Goto edit field: table=rows*cols*percent of width. Handy although I rarely use it. Note if the cells don't word wrap, you are using an older version of Riched.dll.

z941998

I kinda of been thinking along that approach.

Your previous equates worked like a champ.

I have attached a small example of what are some of my needs, although any type of algo can be applied, such as coloring cols versus variables.


jj2007

Looks promising. Typically one would call first
  Refresh_OFF
  invoke SendMessage, hRichEd, EM_LINEINDEX, -1, 0   ; get char of current line
  invoke SendMessage, hRichEd, EM_EXLINEFROMCHAR, 0, eax  ; get line of current char
  mov ebx, eax
  mov txrg.chrg.cpMin, eax
  inc ebx
  invoke SendMessage, hRichEd, EM_LINEINDEX, ebx, 0   ; get char of next line
  dec eax
  mov txrg.chrg.cpMax, eax

to get the start and end of the line, and then use
  invoke SendMessage, hRE, EM_GETTEXTRANGE, 0, addr txrg
to get the line as plain text. Then parse for tabs, and colour text between tabs #col and #col+1

Good luck :thumbu