Re: Simple question: Events for controls (WTL)
<foahchon@hotmail.com> wrote in message
news:1159407493.747472.261950@e3g2000cwe.googlegroups.com
Hi, I'm trying to assign events to a simple edit control, and from
what I understand, the only way to do this is to create a custom
control class
What exactly do you mean by "assign events"? I'm afraid I'm not familiar
with the term. What are you trying to achieve?
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled)
{
aEdit editbox;
RECT rc2 = {0,0,50,50};
editbox.Create(m_hWnd,&rc2,_T("Test."),WS_VISIBLE | WS_CHILD);
bHandled = FALSE;
return 0;
}
An instance of CWindowImpl-derived class must outlive the associated
window (HWND handle). You've created an instance of aEdit on the stack,
it goes out of scope and is destroyed as soon as OnCreate returns.
Whenever I try to run this, I get a "Debug Assertion Failed" error,
which tells me to consult line 2807 of atlwin.h, which doesn't help
me. If I change it to an ordinary CEdit it works fine.
CEdit is not derived from CWindowImpl and does not provide a window proc
for the associated window. That's why it does not matter that a CEdit
instance gets destroyed - it does not hold anything important.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925