NO

Author Topic: How to populate Listbox  (Read 3702 times)

rp108

  • Guest
How to populate Listbox
« on: August 05, 2014, 04:52:46 PM »
I am trying to populate a Listbox, but the text does not get placed into the box.

I am using Pelles c 7.00.355 64bit
Win7 OS

I have used the Wizard to create a Dialog-based app.
I have used the drag-and-drop interface to place a Listbox icon in my app.

The ID of my Listbox is 4015

I have successfully used:

ShowWindow(GetDlgItem(hwndDlg,4015),SW_HIDE);
and
ShowWindow(GetDlgItem(hwndDlg,4015),SW_SHOW);

to hide and show the dialog, under user control, when app is running.


Here is the code I am using to populate the Listbox - that does not work.
I have included the declarations below.

int pos;
int ii;
HWND hwndList;
char buf22[300];

strcpy(buf22, "some listbox text");

hwndList = GetDlgItem(hwndDlg, 4015);

ii = 1;
pos = (int)SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM) buf22);
SendMessage(hwndList, LB_SETITEMDATA, pos, (LPARAM) ii);
// Set input focus to the list box.
SetFocus(hwndList);

Any help is much appreciated.

Thank-you.

JohnF

  • Guest
Re: How to populate Listbox
« Reply #1 on: August 05, 2014, 05:43:00 PM »
It would be better if you posted a small project.

John

czerny

  • Guest
Re: How to populate Listbox
« Reply #2 on: August 05, 2014, 07:04:52 PM »
Try this:

rp108

  • Guest
Re: How to populate Listbox
« Reply #3 on: August 05, 2014, 09:35:12 PM »
Thank-you all for replies.

I have czerny's code running.
I am studying it to see how it is different from mine.
It appears that you simply inserted my code into a small project.

Your code works.
Mine does not work.

I execute my code (to populate the list box) from a WM_COMMAND when the User presses a Button.

Your code runs at WM_INITDIALOG.

So far that is the only difference I see and I don't know why that is significant.

Back when I developed with MS Vis Studio (MFC), you had to call UpdateDialog() to either read from or write to a control. But I thought that was only specific to MFC.

Is there something equivalent in Pelles c ?

Thanks again.

P.S. yes in the future I will post a small project .... didn't think of that this time.

rp108

  • Guest
Re: How to populate Listbox
« Reply #4 on: August 05, 2014, 10:23:55 PM »
I have created my own small project and it works just like czerny's.

I have created a comparison on the properties of the 2 Listboxes to try to understand why one works and one does not work.

the comparison is a screenshot jpg.

Any ideas on why the Listbox won't accept input is much appreciated.

Thank-you.

laurro

  • Guest
Re: How to populate Listbox
« Reply #5 on: August 05, 2014, 11:39:08 PM »
Your List box is probably a List-view control ,"ListBox" vs "SysListView32".

Laur

rp108

  • Guest
Re: How to populate Listbox
« Reply #6 on: August 05, 2014, 11:42:30 PM »

Thank-you Laur   :)