Adding text to my list box

Hi all,

I am working on a simple application using windows.h, my first. I have a structure with some data on various games, read from a file. With that data, I would like to create some sort of table each row is a game, and each column has atributes about it such as title, year, cost, developer, etc. (6 columns in total).

I was able to create this list box with a call to CreateWindow(), but now I have no idea how to go about adding text to it. I tried putting the text in the 2nd parameter, as usual, but it still just comes out as blank.

Here is the code where the box is created:

   listbox = CreateWindow ("LISTBOX",
                                 "Hello World",
                                 WS_VISIBLE | WS_CHILD | WS_BORDER | LBS_MULTICOLUMN,
                                 hwnd, (HMENU) 20, NULL, NULL);

I would very much appreciate it if someone could tell me how to put data into this list box. I dont need it to have any associated option, just the ability to refresh the display.

Here is a link to the full program (in the form of a .cpp file)... Sorry it did not fit in the message. The listbox is created on like 216.

Thanks very much,
Last edited on
How to Create a Simple List Box (Windows)

(the first hit when I Googled for "Add text to a list box c++")
Thank you, I looked at that one... I found it quite confusing because I couldnt figure out where they actually created the list box, and as you know i am very bad at using the win32 api :).

I got it working, my mistake was forgetting to typecast.

If I could ask one more quick question, that would be great:

You know the option to create a multi-column list box right? (LBS_MULTICOLUMN)... If I were to do that, how would windows know how many columns I want, and where to insert each string?

Thanks very much for your help,
I don't think LBS_MULTICOLUMN is what you're looking for. That's a list box with a single row which scrolls horizontally (and not vertically).

What you prob. need is a list-view control with LVS_REPORT style

List-View Control Overviews (Windows)

How to Add List-View Columns (Windows)

How to Add List-View Items and Subitems (Windows)

Thanks very much, I will look into implementing that
Topic archived. No new replies allowed.