The following code does not work.
Attempting to highlight a line of text by making the background light blue
and the text white. Same as what Hutch does in the Qeditor.
Line of text already exists that I want to highlight.
Have searched for info on this to no avail.
LOCAL hWnd:HWND, pt:POINT, iMsg:UINT
.ELSEIF iMsg==WM_LBUTTONDOWN
invoke GetDC,hWnd
mov hdc, eax
invoke GetCursorPos, addr pt
invoke ScreenToClient, hWnd, addr pt
invoke SetPixel, hdc, pt.x+1, pt.y+1, 00ffff00h
invoke SetBkMode, hdc, OPAQUE
invoke SetBkColor, hdc, 00ffff00h ; light blue
invoke InvalidateRect, hWnd, NULL, TRUE
invoke UpdateWindow, hWnd
invoke ReleaseDC, hWnd, hdc
you may want to provide a method of highlighting a line in the WM_PANT handler
set a line number to highlight - then, when you paint, perform the highlighting
my understanding is, once text is drawn, it stays the color it is
to highlight it, it may need to be re-drawn with the appropriate color(s)
you can use the system colors COLOR_HIGHLIGHT and COLOR_HIGHLIGHTTEXT
that way, the colors that have been selected by the user (theme) are used
Jack,
In a rich edit control, the control itself does it. These are the API messages sent to set a line as hilighted.
mov li, FUNC(SendMessage,hEdit,EM_LINEINDEX,cnt,0)
m2m cr.cpMin, li
m2m cr.cpMax, li
invoke SendMessage,hEdit,EM_EXSETSEL,0,ADDR cr
invoke SendMessage,hEdit,EM_EXGETSEL,0,ADDR cr
mov ll, FUNC(SendMessage,hEdit,EM_LINELENGTH,cr.cpMin,0)
add cr.cpMax, eax
invoke SendMessage,hEdit,EM_EXSETSEL,0,ADDR cr
Thanks Hutch for the example.
Since this is my 1st venture into rich edit controls I think I need something like
Rich edit for dummies.
I can't follow your ex.
If you have the time:
What is "FUNC"?
I assume L1 is a dbl word.
Is "cr" a struct and where can I find it?
Do I need to include something to run Rich Edit in my program?
My only source is "C Petzolds Programming windows 95".
MSDN is worth searching for the various structures or messages to use:
EM_EXSETSEL message: http://msdn.microsoft.com/en-us/library/windows/desktop/bb788001%28v=vs.85%29.aspx
CHARRANGE structure: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787885%28v=vs.85%29.aspx
So in hutches example, he declares a variable of type CHARRANGE, which is itself a structure as defined in the above link
If your declaring it in your .data section your would probably do so like this:.data
cr CHARRANGE <>
However if your using it in a procedure and want to only use this as a temporary variable you can make it a local variable and declare it like so:
LOCAL cr:CHARRANGE
FUNC is a macro - shorthand if you like - that calls a function or procedure and returns the value in eax, so in the example used:
mov li, FUNC(SendMessage,hEdit,EM_LINEINDEX,cnt,0)
is the same as the following (perhaps handier to do in one line once you know how - personal preference tho if you use macros):
Invoke SendMessage, hEdit, EM_LINEINDEX, cnt, 0
mov li, eax ; value of sendmessage is returned in eax, and we store it in a local or global var called li - short for line index
the variable li is a dword (you are right in assuming this). It is easier to manipulate and store the result from eax to a variable of the same size as the register we are using.
m2m is a macro to move the line index value into your cr variable min and max part (both of which are dword/long values)
Hope that helps
Thank you Fearless for a very good explanation. It's much appreciated.
Yes I will pursue the info on the Microsoft site.
Two more items in Hutch's code:
"cnt" and "LL"
What's in cnt and how is it defined. Thought that param should be null in a SendMessage.
LL never seems to be used or is it a typo?
Am I right in assuming I have to create a child window to get this code to work?