CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    [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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    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?

  3. #3
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  4. #4
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Post 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.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: CEditView

    Quote Originally Posted by laitinen
    Maybe you can use HideCaret function: CWND::HideCaret()
    Good point! I didn't know about HideCaret/ShowCaret methods (cause I never needed them)!

  6. #6
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Post 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!

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Post Re: CEditView

    I need only to display text in the view, not to write in it too...

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CEditView

    Quote 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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  10. #10
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: CEditView

    Quote 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

  11. #11
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CEditView

    Quote 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;
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  12. #12
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Post 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!

  13. #13
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CEditView

    Quote 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);
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  14. #14
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Post 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...

  15. #15
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured