virtual function MeasureItem problem(owner draw function problem)
-
I derived my class from CListBox called CMyListBox. then I write the virtual function MeasureItem to change the height of items. In my main dialog CMyDialog, construct a CMyListBox object. CMyListBox m_ctlBox; and in the CMyDialog::OnInitDialog
DDX_Control(pDX, BOXID, m_ctlBox); CMyDialog::OnInitDialog() { m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); }
but it has no affect. The height doesn't change at all. But it executes fine. Then I've tried comment the code m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); And in the resource editor, I change the property of the ListBox with OwnerDraw to OwnerDrawFixed, then I got compilation assertion error. What do I miss? And Why do I get the assertion error?But I don't want to create the CMyListBox on the fly at all, cause If I create it on the fly, I can't adjust its position and size. And in the book «Programming with MFC 2nd», I program as the book shows, it works fine. First, in the CMyListBox use the PreCreateWindowClass to add the style with LBS_OWNERDRAWFIXED OR LBS_OWNERDRAWVARIABLE. Second, in the virtual MeasureItem function to change the height. Third, But you should in the CMyDialog::OnInitDialog to create the CMyListBox on the fly, it should use CMyListBox.Create to create the ListBox, otherwise the CMyListBox::PreCreateWindowClass would not be called to initialize the style with LBS_OWNERDRAWFIXED. -
I derived my class from CListBox called CMyListBox. then I write the virtual function MeasureItem to change the height of items. In my main dialog CMyDialog, construct a CMyListBox object. CMyListBox m_ctlBox; and in the CMyDialog::OnInitDialog
DDX_Control(pDX, BOXID, m_ctlBox); CMyDialog::OnInitDialog() { m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); }
but it has no affect. The height doesn't change at all. But it executes fine. Then I've tried comment the code m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); And in the resource editor, I change the property of the ListBox with OwnerDraw to OwnerDrawFixed, then I got compilation assertion error. What do I miss? And Why do I get the assertion error?But I don't want to create the CMyListBox on the fly at all, cause If I create it on the fly, I can't adjust its position and size. And in the book «Programming with MFC 2nd», I program as the book shows, it works fine. First, in the CMyListBox use the PreCreateWindowClass to add the style with LBS_OWNERDRAWFIXED OR LBS_OWNERDRAWVARIABLE. Second, in the virtual MeasureItem function to change the height. Third, But you should in the CMyDialog::OnInitDialog to create the CMyListBox on the fly, it should use CMyListBox.Create to create the ListBox, otherwise the CMyListBox::PreCreateWindowClass would not be called to initialize the style with LBS_OWNERDRAWFIXED.The proper place to do all this is inside your override of the PreSubclassWindow() function. This function is called regardless of whether the control is created dynamically with a call to Create(), or on-the-fly with a dialog resource template and subclassed with the DDX_Control functions. See http://www.flounder.com/presubclasswindow.htm[^]