Re: WM_SETTEXT with Subclassed CEdit: Is this safe?
From: River Ross (river.ross_at_sbcglobal.net)
Date: 02/24/05
- Next message: Phillip N Rounds: "Need Help Fixing GDI Leaks"
- Previous message: River Ross: "Re: CHtmlView painting problem"
- In reply to: Dan McCarty: "WM_SETTEXT with Subclassed CEdit: Is this safe?"
- Next in thread: Joseph M. Newcomer: "Re: WM_SETTEXT with Subclassed CEdit: Is this safe?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Feb 2005 22:56:30 GMT
No I don't think that is safe... you are copying over the pointer that
outside code called and you have no idea what that pointer is, readonly,
enough memory,etc.
what if some other programmer does this:
yourcontrol.SendMessage(WM_SETTEXT,0,"crashme");
Plus as a design this doesn't really make sense the message is telling your
control what to display, not asking your control to copy over a buffer.
Maybe something like this is suitable:
CMonetEdit::SetValue(double dMoney)
{
m_dMyNumber=dMoney;
CString strTemp;
strTemp.Format("$%f",dMyNumber);
if (GetSafeHwnd())
SetWindowText(strTemp);
}
Or try a design that binds it to an outside data value etc.
BTW Monet is a painter. :)
"Dan McCarty" <dmccarty@gmail.com> wrote in message
news:1109279301.111082.45760@z14g2000cwz.googlegroups.com...
>I created a custom edit control (CMonetEdit) that I plan on using
> throughout an entire application. Among other things, the CMonetEdit
> stores units for each field. To display the field plus its units, I
> handle WM_SETTEXT:
>
> LRESULT CMonetEdit::OnSetText(WPARAM w, LPARAM lpsz)
> {
> // FormatField() knows about the field's data through a
> // custom DDX routine
> CString text = FormatField();
> // For example, lpsz might've been 500; FormatField()
> // would return "5.00 in" instead
> wcscpy((wchar_t *)lpsz, text);
>
> return Default();
> }
>
> I've made a critical assumption: that the size of lpsz is buffered to
> some size larger than just the length of the current field text,
> similar to a CString. Is this a safe assumption to make?
>
> Thanks,
> Dan.
>
- Next message: Phillip N Rounds: "Need Help Fixing GDI Leaks"
- Previous message: River Ross: "Re: CHtmlView painting problem"
- In reply to: Dan McCarty: "WM_SETTEXT with Subclassed CEdit: Is this safe?"
- Next in thread: Joseph M. Newcomer: "Re: WM_SETTEXT with Subclassed CEdit: Is this safe?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|