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
Printable View
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
I guess I should manage a window message by returning it before execute some code from MFC.
But which one ?!?
Snakekaa
I think I can make it read only and after change backgroud appearance from gray to white.
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
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;
}
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
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.Quote:
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 ?
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.
How do you change the background? Have you used WM_CTLCOLOR message? I do it with WM_CTLCOLOR and it works for me.Quote:
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
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
But you know about the CHotKeyCtrl (which can be added using the dialog resource editor), don't you? :DQuote:
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.