|
Hi~ I have got your control, which didn't redraw a text when it needs do that,
although I used your class in ActiveX Control.
So I added a line which implement "Default()" method in a OnPaint message handler...
After do that, it works very well..^^
Thank you for your Good Control!!^^God bless you~
CHO, DAE-WAN...
ChungNam National University. South Korea~
|
|
|
|
|
edit boxes are created in the main window.(not in the dialogs). we would like to change the background of the edit box and the text color of this edit box when we send data to it. how to do it
|
|
|
|
|
See WM_CTLCOLOREDIT & WM_CTLCOLORSTATIC.
|
|
|
|
|
The borders of the control are slightly different, but your code seems to work without handling WM_PAINT messages.
What do you think about this ?
Friendly yours, Chris
|
|
|
|
|
See MSDN Q132080 for details, or just search for WM_CTLCOLOREDIT in the MSDN
|
|
|
|
|
Even if it IS a copy and paste, the author is sharing info with the community. Are you?
just my two cents.
|
|
|
|
|
Hi,
I'm trying to change the selection color of the edit box within the control programmatically. Can anybody help me ?
Thank you very much
|
|
|
|
|
Hello
Can I change the Text Color of individual Words in the Multiline CEdit text?
And how can I catch the mouse Click event and return the clicked word in the text (without selection)
Can you help me please?
|
|
|
|
|
Just thought I'd point out a couple of issues with this code:
Here is my updated version of the painting code:
CString text;
GetWindowText(text);
m_Brush.DeleteObject();
m_Brush.CreateSolidBrush(m_Col);
CDC* pDC = GetDC();
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor(m_Col);
pDC->SelectObject(&m_Brush);
CRect rc;
GetClientRect(&rc);
pDC->Rectangle(0, 0, rc.Width(), rc.Height());
pDC->SetTextColor(RGB(0, 0, 0,));
pDC->ExtTextOut(2, 2, ETO_CLIPPED, &rc, text.GetBuffer(text.GetLength()), NULL);
text.ReleaseBuffer();
After all that, I still don't have this working the way I want it, I still need to reset the font, which is going bold due to the call to TextOut ( default font is bold ), etc. It's a useful idea though, it just needs some more work.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Christian Graus wrote:
//( why make it a member variable if it's only used in one place ? )
So that you do not abuse dynamically allocated memory (at least, not any more than needed). It is the same reason you should not do:
<br />
for( DWORD dwValue = 0; dwValue < 1024; dwValue++ )<br />
{<br />
CString sString;<br />
<br />
sString.Format( _T( "This is the value: %04d" ), dwValue );<br />
}<br />
Instead, you would do this (which is better, but is still abusing the CString...):
<br />
CString sString;<br />
<br />
for( DWORD dwValue = 0; dwValue < 1024; dwValue++ )<br />
{<br />
sString.Format( _T( "This is the value: %04d" ), dwValue );<br />
}<br />
These are all too common (mis)uses of CStrings (and hence, dynamically allocated memory). While it is not so bad for small-time applications, it can have a decent effect on real, large-scale projects.
As an aside, I still do not understand the need to manually draw the text contained within the control... Can someone explain the need to me?
Peace!
-=- James.
|
|
|
|
|
James R. Twine wrote:
Christian Graus wrote:
//( why make it a member variable if it's only used in one place ? )
So that you do not abuse dynamically allocated memory (at least, not any more than needed). It is the same reason you should not do:
So you're saying it makes more sense to keep this string in memory than it does to allocate it during a paint call ? Your example is obviously correct, I'm not convinced in this case that it makes a whole bunch of difference.
James R. Twine wrote:
As an aside, I still do not understand the need to manually draw the text contained within the control... Can someone explain the need to me?
If you look at his code, he's filling the edit control with a rectangle, so the text has been wiped and needs to be replaced. I forget replying to this, so I could be off target here, but based on my brief glance now, and total lack of memory regarding this article, I suspect he needs to impliment WM_CTLCOLOR instead.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian Graus wrote:
So you're saying it makes more sense to keep this string in memory than it does to allocate it during a paint call ?
Yep. You waste more time constructing, allocating, deallocating, and destructing the object each time you paint (which happens a lot more often than most people think).
I'm not convinced in this case that it makes a whole bunch of difference
In this case, with a single edit control, in a piddly little demo app, no. But in the Real World... Things like that are bad habits to get into.
I suspect he needs to impliment WM_CTLCOLOR instead
Yep. -And handle the background brush, eliminating the need to manually draw the text at all. Which, eliminates the CString in this case!
Peace!
-=- James.
|
|
|
|
|
James R. Twine wrote:
Yep. You waste more time constructing, allocating, deallocating, and destructing the object each time you paint (which happens a lot more often than most people think).
I realise WM_PAINT gets called a lot, and I can see that your case is arguable. I'm all for eliminating bad habits, I guess working with images I am more used to trying not to carrying things in memory if I can avoid it.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
|
Hi,
Good stuff, but it should have made class to contain the following stuff.
1. On the screen if some edit boxes are required have some input, then the class should able to have some default color (Yellow) until user enters some text.
2. It should also support the error validation. Say if the entered text is wrong, then the background color of that edit box should change to Red. So that it brings the attention to the user.
Good work.
Kant
|
|
|
|
|