-
April 12th, 2007, 07:22 AM
#1
[RESOLVED] CEditView
in a text editor, like in a CEdit, there is a little clipping bar that shows the position, where you type characters. Can anybody tell me what is its name, how can I control it, and how can I remove it from my CEditView?
-
April 12th, 2007, 07:53 AM
#2
Re: CEditView
It is the caret .
To control it: CEdit::GetSel/SetSel (CEdit::ReplaceSel).
I don't know how to remove it any other way than move the focus on the other window. Why do you want to remove caret from the edit control?
-
April 12th, 2007, 07:56 AM
#3
Re: CEditView
Maybe you can use HideCaret function: CWND::HideCaret()
Regards,
Laitinen
-
April 12th, 2007, 07:58 AM
#4
Re: CEditView
I want only to display text, and it looks bad having it permanently at the begining of the first line. I was thinking about caret, but any function I tried, didn't do anything... so I said it isn't it...
can you tell me how to work with it? Why every function I've tried with it didn't have any effect?
Last edited by Feoggou; April 12th, 2007 at 08:00 AM.
-
April 12th, 2007, 08:07 AM
#5
Re: CEditView
Originally Posted by laitinen
Good point! I didn't know about HideCaret/ShowCaret methods (cause I never needed them)!
-
April 12th, 2007, 08:12 AM
#6
Re: CEditView
I found it! I think...
every time the window gets a WM_SETFOCUS message, it creates the caret. I have created, hidden, showed in MyView::OnSetFocus() and now it works! I think I'm right!
-
April 13th, 2007, 12:45 AM
#7
Re: CEditView
Just a little curious. Why do you need to hide caret in an edit control?
AFAIK, it isn't put there for nothing...
-
April 13th, 2007, 02:12 AM
#8
Re: CEditView
I need only to display text in the view, not to write in it too...
-
April 13th, 2007, 02:16 AM
#9
Re: CEditView
Originally Posted by Feoggou
I need only to display text in the view, not to write in it too...
That case, just make it read-only.
Note that hiding the caret does not prevent user to write in.
-
April 13th, 2007, 02:16 AM
#10
Re: CEditView
Originally Posted by Feoggou
I need only to display text in the view, not to write in it too...
Then you should just set the readOnly property to true.
Regards,
Laitinen
-
April 13th, 2007, 02:33 AM
#11
Re: CEditView
Originally Posted by laitinen
Then you should just set the readOnly property to true.
Hmmm... I'm wondering who can find such a "property" for MFC's CEditView...
Well, to be more specific myself.
CEditView encapsulates an edit control and has a method "GetEditCtrl" that returns a reference to the corresponding CEditCtrl object.
So, to make an edit view read-only, you have to do something like in the next example (here in the WM_CREATE message handler).
Code:
int CMyEditView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEditView::OnCreate(lpCreateStruct) == -1)
return -1;
GetEditCtrl().SetReadOnly();
return 0;
}
-
April 13th, 2007, 02:39 AM
#12
Re: CEditView
I don't like that if I put it ReadOnly, the view turns gray.
But, what I have tried:
If I handle the WM_CHAR message, and delete the CEditView::OnChar(nChar, nRepCnt, nFlags) function, I cannot write in view. And, a better ideea than this, I can handle the WM_SETFOCUS message, so every time the message is sent, the focus should be sent to something else, so I cannot write in view.
Mabey turning the view as ReadOnly is a good ideea, but I don't like it to be gray, and I don't know how to change its color. I think it can be changed...
Anyway, thanks to all!
-
April 13th, 2007, 02:45 AM
#13
Re: CEditView
Originally Posted by Feoggou
I don't like that if I put it ReadOnly, the view turns gray.
But, what I have tried:
[...]
Please, please, stop running around tail!
I know, the default background color for a read-only edit control is gray, but it's no any sweat to change it according to what your muscles want.
Just handle WM_CTLCOLOR message and return the desired (color) brush handle (in the case of CEditView handle "=WM_CTLCOLOR" reflected message).
Here is an example turning the background back to white:
Code:
HBRUSH CMyEditView::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
// TODO: Return a non-NULL brush if the parent's handler should not be called
// return NULL;
return (HBRUSH)::GetStockObject(WHITE_BRUSH);
}
-
April 13th, 2007, 03:02 AM
#14
Re: CEditView
Yes, it worked!
but, I've got one more question... I don't understand this: the CTLCOLOR message looks like =WM_CTLCOLOR... and so, what's the difference between a message with "=" and one without?
like "WM_SETFOCUS" and "=WM_SETFOCUS". when I've tried to handle the "=WM_SETFOCUS" message it didn't do anything, but "WM_SETFOCUS" worked...
-
April 13th, 2007, 03:06 AM
#15
Re: CEditView
I was 99.999998% sure that's the next question...
Well, I hope is pretty clear what's Message Reflection for Windows Controls in MSDN.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|