Andy
Andy

Reputation: 31

Using ListControl in a Dialog window

Can ListControl be used in a dialog in a Non-MFC project? I am using visual c++ 2010.

The examples I have seen so far uses MFC, so it seems to me that ListControl is part of MFC. The code I am working on is not MFC based, however, Visual Studio still allows adding a ListControl to the dialog in the resource view, and generates rc code for the List Control. So my guess is that I should be able to use it. However, I could not use the standard method found online to add variable to the ListControl and use it.

How can I use the ListControl in this case? e.g. adding a column or write something to a cell? Some code example will certainly help.

Upvotes: 3

Views: 1544

Answers (1)

Cody Gray
Cody Gray

Reputation: 244991

The CListCtrl class is an MFC class. It can only be used from within an MFC project.

However, CListCtrl is simply a wrapper around the ListView common control, and a ListView control can be used in any Windows application—no MFC required.

The Resource Editor included with Visual C++ (confusingly) refers to a ListView control as a "List Control". You can insert one on your dialog, and all it will do is insert a ListView control.

If you're using MFC, you can choose to create a member variable corresponding to that control. The type of that member variable will be CListCtrl, because it is encapsulating access to a ListView control on your dialog.

If you are not using MFC, you can still use the ListView control, you'll just have to use the standard SDK mechanisms for accessing and manipulating it. For example, to insert an item into the ListView control on your dialog, you would obtain the control's window handle (GetDlgCtrlID) and send it a LVM_INSERTITEM message. The SDK documentation contains sample code listings, but they are a rather poor way to learn. The best resource for good old Windows SDK programming is still Charles Petzold's Programming Windows.

Upvotes: 3

Related Questions