Dynamic Create ownerdraw ListBox in Mfc

Rocky Shr 41 Reputation points
2020-09-21T13:09:10.107+00:00

I have created my own list box with the base class of CListBox. when I use it in the Dialog box it works fine.
but when I try to create dynamic at runtime it gives an error.

here is my code for it

m_LstList= new x_ListBox;  
		m_LstList->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |  
			LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS, rect, m_hWnd, IDC_X_LIST);  

am I doing anything wrong?
or there is any extra setting I have to make inside x_ListBox class

	class x_ListBox : public CListBox  
	{  
public:  
		x_ListBox();  
		virtual ~x_ListBox();  
		LIST_BOX_TYPE m_ListBoxType;  

// my functions for custom draw

	protected:  
		afx_msg void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);  
		DECLARE_MESSAGE_MAP()  
  
  
};  

26175-image.png

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,753 questions
0 comments No comments
{count} votes

Accepted answer
  1. SM 416 Reputation points
    2020-09-21T13:18:25.077+00:00

    You need to override OnMeasureItem()

    -SM

    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Rocky Shr 41 Reputation points
    2020-09-21T15:10:22.993+00:00

    hi dear,
    is it possible to refer any sample code for that? that would be great if I can see any reference.


  2. Rocky Shr 41 Reputation points
    2020-09-21T15:20:55.95+00:00

    Thanks a lot.

    BTW. that is Manage C++. is that same as native? I've never tried it.


  3. Rocky Shr 41 Reputation points
    2020-09-21T15:37:25.05+00:00

    I am really thankful for your support and the time you spend on my problem. I will try to understand and try to follow it.
    thank you very much.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.