CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Edit issue

  1. #1
    Join Date
    May 2002
    Location
    Romania
    Posts
    929

    Edit issue

    I want to prohibit writing into an editbox.
    I'd use read-only propriety, but it adds disable aspect to my editbox and I want to avoid this.

    Thanks,
    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  2. #2
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    I guess I should manage a window message by returning it before execute some code from MFC.

    But which one ?!?

    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  3. #3
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    I think I can make it read only and after change backgroud appearance from gray to white.

    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  4. #4
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    I did so and it worked, but when I put some text into edit with SetWindowText, it appears disable (with a gray background).

    Does anyone know how to avoid this ?

    Thanks,
    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  5. #5
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    You could derive a control from CEdit and implement PreTranslateMessage() like this:
    Code:
    BOOL CLockedEdit::PreTranslateMessage(MSG* pMsg) 
    {
      BOOL retval = TRUE;
      if(pMsg->message != WM_KEYDOWN)
      {
        retval = CEdit::PreTranslateMessage(pMsg);
      }	
      return retval;
    }

  6. #6
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    I suppose I cannot do it without deriving a control from CEdit, can I ?

    The fact is I have a big number of CEdit-s on my dialog and for all of them I would be forced to define a CMyEdit variable, wouldn't I ?

    Thank you very much for your suggestion, gstercken. I cannot imagine why it didn't came to me

    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  7. #7
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by Snakekaa
    I suppose I cannot do it without deriving a control from CEdit, can I ?

    The fact is I have a big number of CEdit-s on my dialog and for all of them I would be forced to define a CMyEdit variable, wouldn't I ?
    Well, you could of course have some code in your dialog which iterates the controls and subclasses all edit controls programmatically. But I think it will be easier to live with a DDX control member for every edit control.

    But just another thought: If an edit control is read only, I think it is preferrable to display it the way Windows provides (that is, grayed). IMHO, an edit control which appears as if it were editable but is read only is not what a Windows user expects. That's why there is no easy way to achieve this - it's by design.
    Last edited by gstercken; September 3rd, 2003 at 10:28 AM.

  8. #8
    Join Date
    May 2001
    Location
    Madrid-Spain
    Posts
    1,123
    Originally posted by Snakekaa
    I did so and it worked, but when I put some text into edit with SetWindowText, it appears disable (with a gray background).

    Does anyone know how to avoid this ?

    Thanks,
    Snakekaa
    How do you change the background? Have you used WM_CTLCOLOR message? I do it with WM_CTLCOLOR and it works for me.
    I am Miss Maiden... Miss Iron Maiden :-D

  9. #9
    Join Date
    May 2002
    Location
    Romania
    Posts
    929
    I also used that, WM_CTLCOLOR. Perhaps I didn't make myself clear : not the backgroud of editbox remained gray, but the backgroud of the text I put in. But this is no longer a problem, since I've adopted gstercken's solution.

    Thank you, irona20.

    gstercken, thanks for your suggestions. Regarding your advice, I agree, in most of the case it's true what you were saying.

    But (there is always a "but"), look in Office Word, in Tools menu, Customize ... In Customize dialog, press Keyboard... button. In Customize Keyboard ... dialog see the behaviour of editbox located under "Press new shortcut key:" static.

    Such behaviour I was looking for and, thanks to you, I've found it.

    Snakekaa
    Move like a snake, think like a snake, be a snake !!!

  10. #10
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by Snakekaa
    But (there is always a "but"), look in Office Word, in Tools menu, Customize ... In Customize dialog, press Keyboard... button. In Customize Keyboard ... dialog see the behaviour of editbox located under "Press new shortcut key:" static.

    Such behaviour I was looking for and, thanks to you, I've found it.
    But you know about the CHotKeyCtrl (which can be added using the dialog resource editor), don't you?

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