Re: Channel 9 video: Visual C++ 10 is the new 6
On Sun, 23 Nov 2008 23:00:55 +0100, "Giovanni Dicanio"
<giovanniDOTdicanio@REMOVEMEgmail.com> wrote:
MyListBox c_lb;
...
CListBox& lb = c_lb;
lb.InsertString(...);
I think that the problem here is that CListBox::InsertString() is not
virtual, so lb.InsertString() actually calls CListBox::InsertString()
instead of the derived class MyListBox::InsertString() implementation.
Right.
I would solve that overriding CWnd::WindowProc that is *virtual* in
MyListBox class, and process LB_INSERTSTRING in this override of WindowProc,
something like this following:
<code>
LRESULT MyListBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case LB_INSERTSTRING:
TRACE("Processing MyListBox::LB_INSERTSTRING message; Index = %d,
String = %s\n", wParam, (LPCTSTR)lParam);
break;
}
return CListBox::WindowProc(message, wParam, lParam);
}
</code>
Is this what you had in mind?
Or is there a better solution?
(Or am I wrong?)
Normally you would use ClassWizard and the message map to implement
LB_INSERTSTRING and other messages, and the only way the message map gets
used is by calling SendMessage and friends. So the answer I had in mind was
to use SendMessage instead of calling the member function directly. That
way, the virtual function GetMessageMap is called, and the message map
search begins in the most derived object that has a message map.
--
Doug Harrison
Visual C++ MVP