CListBox!?
-
Hi All, This is to request a HELP on the CListBox stuff! The ususal way to stuff the list box control is to use the CListBox::AddString(...) in the WM_INITDIALOG of any dilaog window! But I require this list box to initialize the contents of itself, INDEPENDENTLY! If I derive a class from the CLisBox, how/where is the place to self init the derived class? :) Any help/hint is highly appreciated! :) :) Cheers Masoud
-
Hi All, This is to request a HELP on the CListBox stuff! The ususal way to stuff the list box control is to use the CListBox::AddString(...) in the WM_INITDIALOG of any dilaog window! But I require this list box to initialize the contents of itself, INDEPENDENTLY! If I derive a class from the CLisBox, how/where is the place to self init the derived class? :) Any help/hint is highly appreciated! :) :) Cheers Masoud
You need to do it two places. First, you override WM_CREATE, and do it there. That takes care of dynamic creation. The one most people don't notice is that you have to override the Attach() function as well. When you use classwizard to associate a class with a dialog control, the control is created by Windows, and then the class is attached to it in the DDX. Thus, Create() is never called but Attach() is.
-
You need to do it two places. First, you override WM_CREATE, and do it there. That takes care of dynamic creation. The one most people don't notice is that you have to override the Attach() function as well. When you use classwizard to associate a class with a dialog control, the control is created by Windows, and then the class is attached to it in the DDX. Thus, Create() is never called but Attach() is.
Dear Erik! Hi and thanks for your reply. Just a while ago I did the override of
WM_CREATE
and tried theAddString("Test!")
, but does not catch it here! Also am confused about theAttach(...)
, is this theBOOL CWnd::Attach(HWND hWndNew);
function? If yes then where is thehWndNew
going to be set and how? Also about your point on the DDX, when I derive from the CListBox, I also attach the derived class to a member namedm_List
whcih is the control's object. For both am using the calsswizard to do. And then in theOnInitDialog()
am doing these:// Add some string
m_List.AddString("Test1");
m_List.AddString("Test2");
m_List.AddString("Test3");
m_List.AddString("Test4");// Select default the first item
m_List.SetCurSel(0);I am confused and lost! Help with some code lines would really solve this! :) However, this thing am doing is gonna be posted here (CP) to benefit everyone else as well! :) :) Thanks in advance already! Cheers Masoud
-
Dear Erik! Hi and thanks for your reply. Just a while ago I did the override of
WM_CREATE
and tried theAddString("Test!")
, but does not catch it here! Also am confused about theAttach(...)
, is this theBOOL CWnd::Attach(HWND hWndNew);
function? If yes then where is thehWndNew
going to be set and how? Also about your point on the DDX, when I derive from the CListBox, I also attach the derived class to a member namedm_List
whcih is the control's object. For both am using the calsswizard to do. And then in theOnInitDialog()
am doing these:// Add some string
m_List.AddString("Test1");
m_List.AddString("Test2");
m_List.AddString("Test3");
m_List.AddString("Test4");// Select default the first item
m_List.SetCurSel(0);I am confused and lost! Help with some code lines would really solve this! :) However, this thing am doing is gonna be posted here (CP) to benefit everyone else as well! :) :) Thanks in advance already! Cheers Masoud
A control is created two ways. The first way, dynamicly, is when you call control.Create(); This allows you to create controls on the fly whenever you want. The second way, is when you put a control on a dialog. In this way, the Create() method of class is never called because Windows creates the control, not your code. Your code merely attaches to it AFTER it's been created, thus you never get a WM_CREATE message, since your class isn't attached to the actual control until after the window has sent that message. This is all handled for you by the DDX handler for your control when you associate a class with the control in ClassWizard. However, I lead you slightly astray. It's not Attach() that you override, but PreSubclassWindow(). PreSubclassWindow() is called by Attach(). Simply call the base class first, then do whatever you need to do to the control.
-
A control is created two ways. The first way, dynamicly, is when you call control.Create(); This allows you to create controls on the fly whenever you want. The second way, is when you put a control on a dialog. In this way, the Create() method of class is never called because Windows creates the control, not your code. Your code merely attaches to it AFTER it's been created, thus you never get a WM_CREATE message, since your class isn't attached to the actual control until after the window has sent that message. This is all handled for you by the DDX handler for your control when you associate a class with the control in ClassWizard. However, I lead you slightly astray. It's not Attach() that you override, but PreSubclassWindow(). PreSubclassWindow() is called by Attach(). Simply call the base class first, then do whatever you need to do to the control.
Erik!,Thankyou! :) :) It was indeed the
PreSubClass()
guy! This just FIXED the problem! By 2 days max I'll have the documentations ready to post here on the CP. Have fun and thanx again. Cheers Masoud